flutter_freedome_authentication 1.1.0
flutter_freedome_authentication: ^1.1.0 copied to clipboard
FreeDome authentication library for Flutter applications
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_freedome_authentication/flutter_freedome_authentication.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'FreeDome Authentication Demo',
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
AppLocalizations.delegate,
],
supportedLocales: FreeDomeLocalizationService.supportedLocales,
locale: const Locale('en', ''),
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final _authService = FreeDomeAuthService(baseUrl: 'https://api.freedome.com');
final _registrationService = FreeDomeRegistrationService(baseUrl: 'https://api.freedome.com');
final _passwordService = FreeDomePasswordService(baseUrl: 'https://api.freedome.com');
String _currentLanguage = 'en';
String _status = 'Ready';
@override
Widget build(BuildContext context) {
final localizations = AppLocalizations.of(context)!;
return Scaffold(
appBar: AppBar(
title: Text(localizations.appTitle),
actions: [
PopupMenuButton<String>(
onSelected: (language) {
setState(() {
_currentLanguage = language;
});
},
itemBuilder: (context) => FreeDomeLocalizationService
.getSupportedLanguages()
.map((lang) => PopupMenuItem<String>(
value: lang['code']!,
child: Text('${lang['nativeName']} (${lang['name']})'),
))
.toList(),
child: const Icon(Icons.language),
),
],
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
localizations.appTitle,
style: Theme.of(context).textTheme.headlineSmall,
),
const SizedBox(height: 8),
Text('Status: $_status'),
const SizedBox(height: 8),
Text('Language: ${FreeDomeLocalizationService.getLanguageName(_currentLanguage)}'),
],
),
),
),
const SizedBox(height: 16),
Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
localizations.login,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 8),
TextField(
decoration: InputDecoration(
labelText: localizations.username,
border: const OutlineInputBorder(),
),
),
const SizedBox(height: 8),
TextField(
decoration: InputDecoration(
labelText: localizations.password,
border: const OutlineInputBorder(),
),
obscureText: true,
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () async {
setState(() {
_status = localizations.authenticating;
});
// Simulate authentication
await Future.delayed(const Duration(seconds: 2));
setState(() {
_status = localizations.loginSuccess;
});
},
child: Text(localizations.login),
),
],
),
),
),
const SizedBox(height: 16),
Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
localizations.register,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 8),
TextField(
decoration: InputDecoration(
labelText: localizations.firstName,
border: const OutlineInputBorder(),
),
),
const SizedBox(height: 8),
TextField(
decoration: InputDecoration(
labelText: localizations.lastName,
border: const OutlineInputBorder(),
),
),
const SizedBox(height: 8),
TextField(
decoration: InputDecoration(
labelText: localizations.email,
border: const OutlineInputBorder(),
),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () async {
setState(() {
_status = localizations.registering;
});
// Simulate registration
await Future.delayed(const Duration(seconds: 2));
setState(() {
_status = localizations.registrationSuccess;
});
},
child: Text(localizations.register),
),
],
),
),
),
const SizedBox(height: 16),
Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
localizations.password,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 8),
TextField(
decoration: InputDecoration(
labelText: localizations.password,
border: const OutlineInputBorder(),
),
obscureText: true,
),
const SizedBox(height: 8),
TextField(
decoration: InputDecoration(
labelText: localizations.confirmPassword,
border: const OutlineInputBorder(),
),
obscureText: true,
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () async {
setState(() {
_status = localizations.changingPassword;
});
// Simulate password change
await Future.delayed(const Duration(seconds: 2));
setState(() {
_status = localizations.passwordChanged;
});
},
child: Text(localizations.password),
),
],
),
),
),
],
),
),
);
}
}