160 lines
4.7 KiB
Dart
160 lines
4.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:learn_project/screens/home.dart';
|
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
|
import 'package:learn_project/screens/account_page.dart';
|
|
import 'package:learn_project/screens/login_page.dart';
|
|
import 'package:learn_project/screens/splash_page.dart';
|
|
import 'utils/constants.dart';
|
|
|
|
Future<void> main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await Supabase.initialize(
|
|
url: 'http://192.168.179.86:8000/',//'https://vvtefqdqahcpzgolvupv.supabase.co',//'https://vvtefqdqahcpzgolvupv.supabase.co',//
|
|
anonKey: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InZ2dGVmcWRxYWhjcHpnb2x2dXB2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTYwMjE2NTIsImV4cCI6MjAzMTU5NzY1Mn0.1bp5V61Oguo5zLUhCFJmCabUY1sujeISr_CR2XUKvh4',//'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InZ2dGVmcWRxYWhjcHpnb2x2dXB2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTYwMjE3ODksImV4cCI6MjAzMTU5Nzc4OX0.6g5EtS9HrgxC6cpCYgOT0HLpA4lEnASQbKs9mfnUM7k',//Constants.supabaseAnnonKey,//
|
|
);
|
|
runApp( MyApp());
|
|
}
|
|
|
|
/// Supabase client
|
|
final supabase = Supabase.instance.client;
|
|
/// Error message to display the user when unexpected error occurs.
|
|
const unexpectedErrorMessage = 'Unexpected error occurred.';
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const MaterialApp(
|
|
title: 'Events',
|
|
home: HomePage(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class HomePage extends StatefulWidget {
|
|
const HomePage({super.key});
|
|
|
|
@override
|
|
State<HomePage> createState() => _HomePageState();
|
|
}
|
|
|
|
class _HomePageState extends State<HomePage> {
|
|
final _future = Supabase.instance.client
|
|
.from('events')
|
|
.select();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: FutureBuilder(
|
|
future: _future,
|
|
builder: (context, snapshot) {
|
|
if (!snapshot.hasData) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
final events = snapshot.data!;
|
|
return ListView.builder(
|
|
itemCount: events.length,
|
|
itemBuilder: ((context, index) {
|
|
final event = events[index];
|
|
return ListTile(
|
|
title: Text(event['name']),
|
|
subtitle: Text(event['description']),
|
|
);
|
|
}),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/* class MyApp extends StatelessWidget { */
|
|
//MyApp({super.key});
|
|
|
|
/* @override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
//title: 'Recipes',
|
|
theme: ThemeData(
|
|
colorScheme: ColorScheme.fromSwatch().copyWith(
|
|
primary: Colors.white,
|
|
secondary: const Color(0xff8DB646), // Your accent color
|
|
),
|
|
),
|
|
home: const HomePage(),
|
|
);
|
|
} */
|
|
|
|
|
|
|
|
/* @override
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
title: 'Supabase Flutter',
|
|
theme: ThemeData.dark().copyWith(
|
|
primaryColor: Colors.green,
|
|
textButtonTheme: TextButtonThemeData(
|
|
style: TextButton.styleFrom(
|
|
foregroundColor: Colors.green,
|
|
),
|
|
),
|
|
elevatedButtonTheme: ElevatedButtonThemeData(
|
|
style: ElevatedButton.styleFrom(
|
|
foregroundColor: Colors.white,
|
|
backgroundColor: Colors.green,
|
|
),
|
|
),
|
|
),
|
|
initialRoute: '/',
|
|
routes: <String, WidgetBuilder>{
|
|
'/': (_) => const SplashPage(),
|
|
'/login': (_) => const LoginPage(),
|
|
'/account': (_) => const AccountPage(),
|
|
},
|
|
);
|
|
} */
|
|
/* Future<void> readData() async {
|
|
final response = await Supabase.instance.client.from('events').select();
|
|
if (response.error == null) {
|
|
final data = response.data;
|
|
print('Fetched data: $data');
|
|
} else {
|
|
print('Error reading data: ${response.error!.message}');
|
|
}}
|
|
|
|
final _future = Supabase.instance.client
|
|
.from('events')
|
|
.select();
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('Home Page'),
|
|
),
|
|
body: FutureBuilder(
|
|
future: _future,
|
|
builder: (context, snapshot) {
|
|
|
|
}
|
|
final countries = snapshot.data!;
|
|
return ListView.builder(
|
|
itemCount: countries.length,
|
|
itemBuilder: ((context, index) {
|
|
final country = countries[index];
|
|
return ListTile(
|
|
title: Text(country['name']),
|
|
);
|
|
}),
|
|
);})));
|
|
}
|
|
}
|
|
|
|
class _execute {
|
|
}*/ |