Files
venir.dev 171d80bd60 Cleanup
2022-10-07 16:21:31 +02:00

89 lines
2.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'auth.dart';
import 'router.dart';
void main() {
runApp(const ProviderScope(child: ValueNotifierApp()));
}
class ValueNotifierApp extends ConsumerWidget {
const ValueNotifierApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
// Comment out the implementation you're not using
final router = ref.watch(routerProvider);
return MaterialApp.router(
routeInformationParser: router.routeInformationParser,
routerDelegate: router.routerDelegate,
routeInformationProvider: router.routeInformationProvider,
title: 'flutter_riverpod + go_router Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
);
}
}
class HomePage extends ConsumerWidget {
const HomePage({Key? key}) : super(key: key);
static String get routeName => 'home';
static String get routeLocation => '/';
@override
Widget build(BuildContext context, WidgetRef ref) {
return Scaffold(
appBar: AppBar(title: const Text("Your phenomenal app")),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text("Home Page"),
ElevatedButton(
onPressed: () {
ref.read(authProvider.notifier).logout();
},
child: const Text("Logout"),
),
],
),
),
);
}
}
class LoginPage extends ConsumerWidget {
const LoginPage({Key? key}) : super(key: key);
static String get routeName => 'login';
static String get routeLocation => '/$routeName';
@override
Widget build(BuildContext context, WidgetRef ref) {
return Scaffold(
appBar: null,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text("Login Page"),
ElevatedButton(
onPressed: () async {
ref.read(authProvider.notifier).login(
"myEmail",
"myPassword",
);
},
child: const Text("Login"),
),
],
),
),
);
}
}