nonso 0.0.23
nonso: ^0.0.23 copied to clipboard
A package that handles email and password authentication in a Flutter app. It is based on Firebase Authentication.
import 'package:example/firebase_options.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:nonso/nonso.dart' as nonso;
import 'package:nonso/nonso.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
runApp(MyApp(FirebaseAuth.instance));
}
class MyApp extends StatelessWidget {
final FirebaseAuth firebaseAuthInstance;
const MyApp(this.firebaseAuthInstance, {super.key});
@override
Widget build(BuildContext context) {
return BlocProvider<nonso.AuthBloc>(
create: (context) => nonso.AuthBloc(firebaseAuthInstance),
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
localizationsDelegates: [nonso.AppLocalizations.delegate],
supportedLocales: nonso.AppLocalizations.supportedLocales,
home: nonso.AuthScreen(
// This is your home screen
const MyHomePage(title: 'Flutter Demo Home Page'),
),
),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
final User currentSignedInUser = context.read<AuthBloc>().state.user!;
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('You have pushed the button this many times:'),
Text('User UID: ${currentSignedInUser.uid}'),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}