refactor: implement Flutter best practices and proper architecture
- Create proper service layer with AuthService and FirebaseAuthService - Implement UserModel for proper data representation - Enhance AuthState with proper loading states and error handling - Convert stateless widgets to stateful where appropriate - Add proper form validation and user feedback mechanisms - Implement comprehensive error handling and loading indicators - Fix redirect logic in router for proper authentication flow - Create theme system with light and dark themes - Add shared components like LoadingIndicator - Improve code organization following recommended architecture - Add proper disposal of controllers and focus nodes - Implement proper null safety handling Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,10 @@ class HomeScreen extends StatelessWidget {
|
||||
appBar: AppBar(title: const Text('Home')),
|
||||
body: Consumer<AuthState>(
|
||||
builder: (context, authState, child) {
|
||||
if (authState.isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return authState.isLoggedIn
|
||||
? const _LoggedInView()
|
||||
: const _LoggedOutView();
|
||||
@@ -40,22 +44,39 @@ class _LoggedInView extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView.builder(
|
||||
itemCount: 20, // Example items
|
||||
itemBuilder: (context, index) {
|
||||
return Card(
|
||||
margin: const EdgeInsets.all(8.0),
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.star),
|
||||
title: Text('Item ${index + 1}'),
|
||||
subtitle: const Text('This is an example item.'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
body: authState.currentUser != null
|
||||
? ListView(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
children: [
|
||||
Card(
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.person),
|
||||
title: Text(authState.currentUser!.displayName ?? 'User'),
|
||||
subtitle: Text(authState.currentUser!.phoneNumber ?? 'No phone number'),
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: 20, // Example items
|
||||
itemBuilder: (context, index) {
|
||||
return Card(
|
||||
margin: const EdgeInsets.symmetric(vertical: 4.0),
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.star),
|
||||
title: Text('Item ${index + 1}'),
|
||||
subtitle: const Text('This is an example item.'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
: const Center(child: Text('Loading user data...')),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
authState.logout(); // Call logout method
|
||||
onPressed: () async {
|
||||
await authState.logout(); // Call logout method
|
||||
},
|
||||
label: const Text('Logout'),
|
||||
icon: const Icon(Icons.logout),
|
||||
@@ -86,7 +107,7 @@ class _LoggedOutView extends StatelessWidget {
|
||||
const SizedBox(height: 30),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
context.go('/phone');
|
||||
context.go('/login');
|
||||
},
|
||||
child: const Text('Login'),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user