92 lines
3.1 KiB
Dart
92 lines
3.1 KiB
Dart
// Copyright (C) 2024 WYATT GROUP
|
|
// Please see the AUTHORS file for details.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:wyatt_authentication/wyatt_authentication.dart';
|
|
import 'package:wyatt_authentication_example/account_model.dart';
|
|
|
|
class App extends StatelessWidget {
|
|
const App({super.key});
|
|
|
|
static const String title = 'Wyatt Authentication Example';
|
|
|
|
@override
|
|
Widget build(BuildContext context) => MaterialApp(
|
|
title: title,
|
|
theme: ThemeData(
|
|
primarySwatch: Colors.blue,
|
|
),
|
|
home: Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text(title),
|
|
),
|
|
body: Column(
|
|
children: [
|
|
ValueListenableBuilder(
|
|
valueListenable: Auth.instance.accountNotifier,
|
|
builder: (context, value, child) {
|
|
if (value == null) {
|
|
return const Text('Not authenticated');
|
|
}
|
|
return Text('Authenticated as ${value as AccountModel}');
|
|
},
|
|
),
|
|
StreamBuilder(
|
|
stream: Auth.instance.status,
|
|
builder: (context, snapshot) {
|
|
if (snapshot.data == AuthenticationStatus.unknown) {
|
|
return const Text('Unknown');
|
|
}
|
|
if (snapshot.data == AuthenticationStatus.authenticated) {
|
|
return const Text('Authenticated');
|
|
}
|
|
return const Text('Unauthenticated');
|
|
},
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () async {
|
|
await Auth.instance.signUp(
|
|
EmailPasswordAuthProvider(
|
|
email: 'test@test.fr',
|
|
password: 'toto1234',
|
|
),
|
|
);
|
|
},
|
|
child: const Text('Sign Up'),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () async {
|
|
await Auth.instance.signIn(
|
|
EmailPasswordAuthProvider(
|
|
email: 'test@test.fr',
|
|
password: 'toto1234',
|
|
),
|
|
);
|
|
},
|
|
child: const Text('Sign In'),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () async {
|
|
await Auth.instance.signOut();
|
|
},
|
|
child: const Text('Sign Out'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|