Learn to connect Supabase to Flutter with our step-by-step guide. Set up your account, add dependencies, initialize, and fetch data with a demo UI.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Set up Supabase Account and Project
Step 2: Initialize a Flutter Project
Open your terminal and run the following commands to create a new Flutter project:
flutter create my_supabase_app
cd my_supabase_app
Step 3: Add Supabase Dependencies
pubspec.yaml
file in the root of your Flutter project.supabase_flutter
dependency under the dependencies section:dependencies:
flutter:
sdk: flutter
supabase_flutter: latest_version
flutter pub get
Step 4: Initialize Supabase in Flutter
lib/main.dart
file.import 'package:supabase_flutter/supabase_flutter.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Supabase.initialize(
url: 'YOUR_SUPABASE_URL',
anonKey: 'YOUR_SUPABASE_ANON_KEY',
);
runApp(MyApp());
}
Step 5: Create a Simple UI for Testing
lib/main.dart
file, create a simple UI to interact with Supabase:class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Supabase Flutter Demo',
home: Scaffold(
appBar: AppBar(title: Text('Supabase Flutter Demo')),
body: MyHomePage(),
),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final client = Supabase.instance.client;
Future<void> _fetchData() async {
final response = await client.from('your_table_name').select().execute();
print(response.data);
}
@override
Widget build(BuildContext context) {
return Center(
child: ElevatedButton(
onPressed: _fetchData,
child: Text('Fetch Data'),
),
);
}
}
Step 6: Run Your Flutter App
flutter run
Step 7: Customize and Extend
Now that you have a basic setup running, you can customize and extend your Flutter app to perform various operations on your Supabase database, such as inserting, updating, or deleting data.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.