fluo 4.0.3
fluo: ^4.0.3 copied to clipboard
Build beautiful onboarding flows with minimal code. Optional authentication included.
import 'package:example/config.dart';
import 'package:fluo/fluo.dart';
import 'package:fluo/l10n/fluo_localizations.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const ExampleApp());
}
class ExampleApp extends StatefulWidget {
const ExampleApp({super.key});
@override
State<ExampleApp> createState() => _ExampleAppState();
}
class _ExampleAppState extends State<ExampleApp> {
bool _isLoading = true;
@override
void initState() {
super.initState();
_initFluo();
}
Future<void> _initFluo() async {
await Fluo.initWithApiKey(Config.apiKey);
await Fluo.instance.loadAppConfig();
await Fluo.instance.refreshSession();
setState(() => _isLoading = false);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
scaffoldBackgroundColor: Colors.white,
colorScheme: const ColorScheme.light(
surface: Colors.white,
primary: Colors.black,
),
),
debugShowCheckedModeBanner: false,
localizationsDelegates: FluoLocalizations.localizationsDelegates,
supportedLocales: FluoLocalizations.supportedLocales,
home: _isLoading
? const Scaffold(
backgroundColor: Colors.white,
body: Center(child: CircularProgressIndicator()),
)
: Fluo.instance.hasSession()
? ConnectedScreen(
onSignOut: () async {
await Fluo.instance.clearSession();
setState(() {});
},
)
: SignInScreen(
onUserReady: () => setState(() {}),
),
);
}
}
class SignInScreen extends StatelessWidget {
const SignInScreen({
super.key,
required this.onUserReady,
});
final VoidCallback onUserReady;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Text(
'Fluo Test',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
const SizedBox(height: 48),
FilledButton.icon(
onPressed: () {
Fluo.instance.signInWithEmail(
context: context,
onExit: () {},
onUserReady: onUserReady,
);
},
icon: const Icon(Icons.email),
label: const Text('Sign in with Email'),
),
const SizedBox(height: 16),
FilledButton.icon(
onPressed: () async {
await Fluo.instance.signInWithMobile(
context: context,
onExit: () {},
onUserReady: onUserReady,
);
},
icon: const Icon(Icons.phone),
label: const Text('Sign in with Mobile'),
),
const SizedBox(height: 16),
FilledButton.icon(
onPressed: () async {
await Fluo.instance.signInWithGoogle(
context: context,
onBeforeSessionCreation: () {},
onUserReady: onUserReady,
);
},
icon: const Icon(Icons.g_mobiledata),
label: const Text('Sign in with Google'),
),
const SizedBox(height: 16),
FilledButton.icon(
onPressed: () async {
await Fluo.instance.signInWithApple(
context: context,
onBeforeSessionCreation: () {},
onUserReady: onUserReady,
);
},
icon: const Icon(Icons.apple),
label: const Text('Sign in with Apple'),
),
],
),
),
),
);
}
}
class ConnectedScreen extends StatelessWidget {
const ConnectedScreen({
super.key,
required this.onSignOut,
});
final VoidCallback onSignOut;
@override
Widget build(BuildContext context) {
final user = Fluo.instance.session?.user;
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Connected!',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
const SizedBox(height: 16),
if (user != null) ...[
Text('Email: ${user.email ?? 'N/A'}'),
Text('Mobile: ${user.mobileE164 ?? 'N/A'}'),
Text('Name: ${user.firstName ?? ''} ${user.lastName ?? ''}'),
const SizedBox(height: 24),
],
FilledButton(
onPressed: onSignOut,
child: const Text('Sign out'),
),
],
),
),
);
}
}