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:
soragui
2026-02-26 06:35:57 +08:00
parent f0bee91599
commit c903430f75
14 changed files with 1413 additions and 42 deletions

View File

@@ -7,17 +7,66 @@ class ProfileScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
final authState = Provider.of<AuthState>(context, listen: false);
final authState = Provider.of<AuthState>(context);
return Scaffold(
appBar: AppBar(title: const Text('Profile')),
body: Center(
child: ElevatedButton(
onPressed: () {
authState.toggleLogin();
},
child: const Text('Logout'),
),
body: authState.currentUser != null
? Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(
radius: 50,
child: Text(
authState.currentUser!.displayName != null
? authState.currentUser!.displayName![0].toUpperCase()
: '?',
style: const TextStyle(fontSize: 30),
),
),
const SizedBox(height: 16),
_buildProfileItem('Name', authState.currentUser!.displayName ?? 'Not set'),
_buildProfileItem('Phone', authState.currentUser!.phoneNumber ?? 'Not set'),
_buildProfileItem('Email', authState.currentUser!.email ?? 'Not set'),
const Spacer(),
Center(
child: authState.isLoading
? const CircularProgressIndicator()
: ElevatedButton.icon(
onPressed: () async {
await authState.logout();
},
icon: const Icon(Icons.logout),
label: const Text('Logout'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
),
),
),
],
),
)
: const Center(child: Text('Loading...')),
);
}
Widget _buildProfileItem(String label, String value) {
return Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
const SizedBox(height: 4),
Text(value.isEmpty ? 'Not set' : value),
const Divider(),
],
),
);
}