Search code examples
flutterdartsupabase

fetching data from supabase tables in flutter


I have a test project a Supabase website with these 2 tables :

enter image description here

and this is my main file :

import 'package:flutter/material.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Supabase.initialize(
    url: 'https://fszmicgacuftwaxzrydi.supabase.co',
    anonKey:
        'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZzem1pY2dhY3VmdHdheHpyeWRpIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTQ4MDY0MzIsImV4cCI6MjAzMDM4MjQzMn0.BhjbhjnuuIcFDZwtUF7FWehbna7KSrChm_s7UAJpRLdukvtko',
  );

  runApp(MyApp());
}

final supabase = Supabase.instance.client;

class MyApp extends StatelessWidget {
  MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Supabase Places Test')),
        body: Center(
          child: ElevatedButton(
            onPressed: () async {
              final data = await supabase.from('places').select();

              print(data);
            },
            child: const Text('Fetch Data'),
          ),
        ),
      ),
    );
  }
}

key and url are correct , but i cant get the data , is there any problem here?


Solution

  • I had to disabled the RLS security of the table