-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Refactor project structure and integrate Clean Architecture
1. lib/app/: - Reviewed and optimized global configurations and routes. - Updated `app.dart` with improved root widget setup. 2. config/: - Added and refined application theme and settings. - Simplified configurations for better scalability. 3. navigation/: - Integrated `go_router` for route management. - Created `app_router.dart` and `routes.dart` for centralized navigation. 4. lib/core/: - Restructured common providers, helper classes, and constants. - Enhanced modularity and readability. 5. lib/features/: - Improved feature-based module structure by separating into: - **presentation/**: Widgets, Pages, and UI components. - **application/**: State Notifiers, Providers, and business logic. - **domain/**: Entities, Use Cases, and core business rules. - **infrastructure/**: Repository implementations, data sources, and external integrations. - Added new Entity and Use Case definitions in the domain layer. - Enhanced state management with StateNotifier in the application layer. 6. lib/main.dart: - Refactored entry point for better alignment with Clean Architecture. - Optimized Firebase initialization as a separate function. Additionally: - Fully integrated Clean Architecture principles. - Removed unnecessary files and legacy code. - Improved Riverpod integration and configured ProviderScope. These changes aim to enhance project maintainability and simplify the addition of new features.
- Loading branch information
1 parent
c66b1f0
commit ea8b331
Showing
11 changed files
with
127 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'config/app_config.dart'; | ||
import 'navigation/app_router.dart'; | ||
|
||
class StructureApp extends StatelessWidget { | ||
const StructureApp({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp.router( | ||
title: AppConfig.appName, | ||
theme: AppConfig.themeData, | ||
routerConfig: appRouter, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class AppConfig { | ||
static const String appName = 'Structure App'; | ||
|
||
static ThemeData themeData = ThemeData( | ||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), | ||
useMaterial3: true, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
|
||
import 'routes.dart'; | ||
final GoRouter appRouter = GoRouter( | ||
initialLocation: '/', | ||
routes: appRoutes, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
|
||
import '../../features/counter/presentation/pages/counter_page.dart'; | ||
|
||
List<GoRoute> appRoutes = [ | ||
GoRoute( | ||
path: '/', | ||
name: 'counter', | ||
builder: (BuildContext context, GoRouterState state) => const CounterPage(), | ||
), | ||
// The other routes will come here. | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'package:firebase_core/firebase_core.dart'; | ||
|
||
Future<void> initializeFirebase() async { | ||
await Firebase.initializeApp(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import '../domain/entities/counter.dart'; | ||
|
||
class CounterNotifier extends StateNotifier<Counter> { | ||
CounterNotifier() : super(Counter(value: 0, incrementValue: 0)); | ||
|
||
void increment() { | ||
state = state.copyWith( | ||
value: state.value + 1, | ||
incrementValue: 1, | ||
); | ||
print(state.value); | ||
} | ||
} | ||
|
||
final counterProvider = StateNotifierProvider<CounterNotifier, Counter>( | ||
(ref) => CounterNotifier(), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Counter { | ||
final int value; | ||
final int incrementValue; | ||
|
||
Counter({required this.value, required this.incrementValue}); | ||
|
||
Counter copyWith({int? value, int? incrementValue}) { | ||
return Counter( | ||
value: value ?? this.value, | ||
incrementValue: incrementValue ?? this.incrementValue, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
import '../../application/counter_notifier.dart'; | ||
|
||
class CounterPage extends ConsumerWidget { | ||
const CounterPage({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final counter = ref.watch(counterProvider); | ||
|
||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Structure App counter'), | ||
), | ||
body: Center( | ||
child: Text( | ||
'Counter: ${counter.value}', | ||
style: Theme.of(context).textTheme.headlineMedium, | ||
), | ||
), | ||
floatingActionButton: FloatingActionButton( | ||
onPressed: () => ref.read(counterProvider.notifier).increment(), | ||
tooltip: 'Increment', | ||
child: const Icon(Icons.add), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters