How to Use Google API in Flutter: Step-by-Step Guide for Beginners
FlutterPulseThis article was translated specially for the channel FlutterPulseYou'll find lots of interesting things related to Flutter on this channel. Don't hesitate to subscribe!π

A Complete Step-by-Step Guide to Integrate Google APIs Like Maps, Drive, and Sign-In in Your Flutter App.
If you are a member, please continue,otherwise, read the full story here.
Introduction
If you're building a Flutter app that needs access to Google services β like Maps, YouTube, Drive, or Google Sign-In β you'll need to integrate Google APIs. These APIs unlock powerful capabilities such as location tracking, authentication, file storage, and analytics.
In this article, we'll walk through how to use Google APIs in Flutter, step-by-step, with examples and best practices to help you get started quickly.
What Are Google APIs?
Google APIs are interfaces that allow developers to connect their apps with Google's powerful services.
Examples include:
- Google Maps API β Embed maps, markers, and geolocation.
- Google Places API β Autocomplete and nearby location searches.
- Google Sign-In API β Authenticate users with their Google accounts.
- Google Drive API β Upload, view, and manage files.
- Google Cloud API β Use cloud storage, vision, translation, etc.
Step 1: Create a Project in Google Cloud Console
Before using any Google API, you must create a project and get an API key.
Steps:
- Go to Google Cloud Console.
- Click "New Project" β give it a name (e.g., FlutterGoogleAPI).
- Select your billing account (if needed).
- Once created, navigate to:
APIs & Services β Library. - Search and enable the API you want (e.g., Maps SDK for Android or Places API).
- Go to Credentials β Create Credentials β API Key.
- Copy your API key (you'll use it in your Flutter app).
Tip: Restrict your API key by app package name and SHA-1 fingerprint to keep it secure.
Step 2: Add Required Dependencies in Flutter
Open your Flutter project's pubspec.yaml and add dependencies.
For example, if you're using Google Maps:
dependencies:
flutter:
sdk: flutter
google_maps_flutter: ^2.2.8
http: ^1.2.0
Then run:
flutter pub get
Step 3: Add API Key to Android & iOS
For Android:
Open the file:
android/app/src/main/AndroidManifest.xml
Add your API key inside the <application> tag:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY"/>
For iOS:
Open:
ios/Runner/AppDelegate.swift
Add:
GMSServices.provideAPIKey("YOUR_API_KEY")Step 4: Using Google API in Flutter (Example with Google Maps)
Here's a simple example showing how to display a map with a marker:
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
class GoogleMapScreen extends StatefulWidget {
const GoogleMapScreen({super.key});
@override
State<GoogleMapScreen> createState() => _GoogleMapScreenState();
}
class _GoogleMapScreenState extends State<GoogleMapScreen> {
late GoogleMapController mapController;
final LatLng _center = const LatLng(37.7749, -122.4194); // San Francisco
void _onMapCreated(GoogleMapController controller) {
mapController = controller;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Google Maps in Flutter')),
body: GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 12.0,
),
markers: {
Marker(
markerId: const MarkerId('myMarker'),
position: _center,
infoWindow: const InfoWindow(title: 'San Francisco'),
),
},
),
);
}
}
Step 5: Calling Google REST APIs in Flutter
You can also use HTTP requests to interact with other Google APIs like Drive, YouTube, or Translate.
Example β Google Translate API:
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<void> translateText(String text) async {
const apiKey = 'YOUR_API_KEY';
final url = Uri.parse(
'https://translation.googleapis.com/language/translate/v2?key=$apiKey');
final response = await http.post(
url,
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'q': text,
'target': 'es', // Spanish
}),
);
if (response.statusCode == 200) {
final result = jsonDecode(response.body);
print("Translated Text: ${result['data']['translations'][0]['translatedText']}");
} else {
print("Error: ${response.body}");
}
}
Step 6: Best Practices
Secure Your API Key
- Use environment variables or Firebase Remote Config.
- Restrict keys in Google Cloud Console.
Use Packages
Many Google APIs already have Flutter packages (e.g., google_sign_in, google_mlkit, firebase_core).
Handle Permissions
Add location or internet permissions in Android/iOS manifests when needed.
Test on Real Devices
Google APIs often require physical device testing for accurate results.
Step 7: Bonus β Google Sign-In Example
You can easily add Google authentication using:
dependencies:
google_sign_in: ^6.2.0
And then:
final GoogleSignIn _googleSignIn = GoogleSignIn();
Future<void> handleSignIn() async {
try {
await _googleSignIn.signIn();
print("Signed in as: ${_googleSignIn.currentUser?.displayName}");
} catch (error) {
print(error);
}
}
Conclusion
Integrating Google APIs in Flutter opens the door to powerful, data-driven, and intelligent mobile apps.
Whether it's showing maps, authenticating users, or using AI-powered APIs, Google's ecosystem helps you deliver seamless experiences.
By following this step-by-step guide, you now know how to:
- Create a Google Cloud project
- Obtain and secure an API key
- Integrate Google APIs in Flutter
- Call REST APIs and use packages effectively
So go ahead β experiment with different Google APIs and level up your Flutter projects!