Skip to content

Commit 7bb0e98

Browse files
committed
feat: migrate to go_router and adaptive scaffold
- Removed counter module - Added go_router navigation - Implemented adaptive scaffold layout - Added theme cubit for light/dark mode
1 parent 5605644 commit 7bb0e98

File tree

11 files changed

+247
-79
lines changed

11 files changed

+247
-79
lines changed

lib/app/view/app.dart

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import 'package:flutter/material.dart';
2-
import 'package:ht_main/counter/counter.dart';
3-
import 'package:ht_main/l10n/l10n.dart';
2+
import 'package:flutter_bloc/flutter_bloc.dart';
3+
import 'package:ht_main/router/router.dart';
4+
import 'package:ht_main/theme/cubit/theme_cubit.dart';
45

56
class App extends StatelessWidget {
67
const App({super.key});
78

89
@override
910
Widget build(BuildContext context) {
10-
return MaterialApp(
11-
theme: ThemeData(
12-
appBarTheme: AppBarTheme(
13-
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
14-
),
15-
useMaterial3: true,
11+
return BlocProvider(
12+
create: (_) => ThemeCubit(),
13+
child: BlocBuilder<ThemeCubit, ThemeState>(
14+
builder: (context, state) {
15+
return MaterialApp.router(
16+
theme: state.themeData,
17+
routerConfig: appRouter,
18+
);
19+
},
1620
),
17-
localizationsDelegates: AppLocalizations.localizationsDelegates,
18-
supportedLocales: AppLocalizations.supportedLocales,
19-
home: const CounterPage(),
2021
);
2122
}
2223
}

lib/app/view/app_scaffold.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart';
3+
4+
class AppScaffold extends StatelessWidget {
5+
const AppScaffold({super.key});
6+
7+
@override
8+
Widget build(BuildContext context) {
9+
return AdaptiveScaffold(
10+
// NAVIGATION
11+
useDrawer: false,
12+
destinations: const [
13+
NavigationDestination(
14+
icon: Icon(Icons.view_headline),
15+
label: 'Headlines',
16+
),
17+
NavigationDestination(
18+
icon: Icon(Icons.search),
19+
label: 'Search',
20+
),
21+
],
22+
// MAIN BODY
23+
smallBody: (context) => const Placeholder(),
24+
body: (context) => const Placeholder(),
25+
largeBody: (context) => const Placeholder(),
26+
27+
// SECONDARY BODY
28+
smallSecondaryBody: AdaptiveScaffold.emptyBuilder,
29+
secondaryBody: AdaptiveScaffold.emptyBuilder,
30+
largeSecondaryBody: AdaptiveScaffold.emptyBuilder,
31+
32+
);
33+
}
34+
}

lib/counter/counter.dart

Lines changed: 0 additions & 2 deletions
This file was deleted.

lib/counter/cubit/counter_cubit.dart

Lines changed: 0 additions & 8 deletions
This file was deleted.

lib/counter/view/counter_page.dart

Lines changed: 0 additions & 55 deletions
This file was deleted.

lib/router/router.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:go_router/go_router.dart';
3+
import 'package:ht_main/app/view/app_scaffold.dart';
4+
5+
final appRouter = GoRouter(
6+
routes: [
7+
GoRoute(
8+
path: '/',
9+
builder: (BuildContext context, GoRouterState state) {
10+
return const AppScaffold();
11+
},
12+
),
13+
],
14+
);

lib/theme/cubit/theme_cubit.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'package:bloc/bloc.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:ht_main/theme/theme.dart';
4+
5+
part 'theme_state.dart';
6+
7+
class ThemeCubit extends Cubit<ThemeState> {
8+
ThemeCubit() : super(LightThemeState());
9+
10+
void toggleTheme() {
11+
emit(state is LightThemeState ? DarkThemeState() : LightThemeState());
12+
}
13+
}

lib/theme/cubit/theme_state.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
part of 'theme_cubit.dart';
2+
3+
abstract class ThemeState {
4+
final ThemeData themeData;
5+
6+
const ThemeState({required this.themeData});
7+
}
8+
9+
class LightThemeState extends ThemeState {
10+
LightThemeState() : super(themeData: lightTheme());
11+
}
12+
13+
class DarkThemeState extends ThemeState {
14+
DarkThemeState() : super(themeData: darkTheme());
15+
}

lib/theme/theme.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import 'package:flex_color_scheme/flex_color_scheme.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:google_fonts/google_fonts.dart';
4+
5+
// Project imports
6+
7+
ThemeData lightTheme() {
8+
return FlexThemeData.light(
9+
scheme: FlexScheme.material,
10+
fontFamily: GoogleFonts.notoSans().fontFamily,
11+
);
12+
}
13+
14+
ThemeData darkTheme() {
15+
return FlexThemeData.dark(
16+
scheme: FlexScheme.material,
17+
fontFamily: GoogleFonts.notoSans().fontFamily,
18+
);
19+
}

pubspec.lock

Lines changed: 135 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ packages:
121121
url: "https://pub.dev"
122122
source: hosted
123123
version: "1.3.2"
124+
ffi:
125+
dependency: transitive
126+
description:
127+
name: ffi
128+
sha256: "289279317b4b16eb2bb7e271abccd4bf84ec9bdcbe999e278a94b804f5630418"
129+
url: "https://pub.dev"
130+
source: hosted
131+
version: "2.1.4"
124132
file:
125133
dependency: transitive
126134
description:
@@ -129,11 +137,35 @@ packages:
129137
url: "https://pub.dev"
130138
source: hosted
131139
version: "7.0.1"
140+
flex_color_scheme:
141+
dependency: "direct main"
142+
description:
143+
name: flex_color_scheme
144+
sha256: ae638050fceb35b6040a43cf67892f9b956022068e736284919d93322fdd4ba2
145+
url: "https://pub.dev"
146+
source: hosted
147+
version: "8.1.1"
148+
flex_seed_scheme:
149+
dependency: transitive
150+
description:
151+
name: flex_seed_scheme
152+
sha256: d3ba3c5c92d2d79d45e94b4c6c71d01fac3c15017da1545880c53864da5dfeb0
153+
url: "https://pub.dev"
154+
source: hosted
155+
version: "3.5.0"
132156
flutter:
133157
dependency: "direct main"
134158
description: flutter
135159
source: sdk
136160
version: "0.0.0"
161+
flutter_adaptive_scaffold:
162+
dependency: "direct main"
163+
description:
164+
name: flutter_adaptive_scaffold
165+
sha256: "7279d74da2f2531a16d21c2ec327308778c3aedd672dfe4eaf3bf416463501f8"
166+
url: "https://pub.dev"
167+
source: hosted
168+
version: "0.3.2"
137169
flutter_bloc:
138170
dependency: "direct main"
139171
description:
@@ -152,6 +184,11 @@ packages:
152184
description: flutter
153185
source: sdk
154186
version: "0.0.0"
187+
flutter_web_plugins:
188+
dependency: transitive
189+
description: flutter
190+
source: sdk
191+
version: "0.0.0"
155192
frontend_server_client:
156193
dependency: transitive
157194
description:
@@ -168,6 +205,30 @@ packages:
168205
url: "https://pub.dev"
169206
source: hosted
170207
version: "2.1.3"
208+
go_router:
209+
dependency: "direct main"
210+
description:
211+
name: go_router
212+
sha256: f02fd7d2a4dc512fec615529824fdd217fecb3a3d3de68360293a551f21634b3
213+
url: "https://pub.dev"
214+
source: hosted
215+
version: "14.8.1"
216+
google_fonts:
217+
dependency: "direct main"
218+
description:
219+
name: google_fonts
220+
sha256: b1ac0fe2832c9cc95e5e88b57d627c5e68c223b9657f4b96e1487aa9098c7b82
221+
url: "https://pub.dev"
222+
source: hosted
223+
version: "6.2.1"
224+
http:
225+
dependency: transitive
226+
description:
227+
name: http
228+
sha256: fe7ab022b76f3034adc518fb6ea04a82387620e19977665ea18d30a1cf43442f
229+
url: "https://pub.dev"
230+
source: hosted
231+
version: "1.3.0"
171232
http_multi_server:
172233
dependency: transitive
173234
description:
@@ -312,6 +373,70 @@ packages:
312373
url: "https://pub.dev"
313374
source: hosted
314375
version: "1.9.1"
376+
path_provider:
377+
dependency: transitive
378+
description:
379+
name: path_provider
380+
sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd"
381+
url: "https://pub.dev"
382+
source: hosted
383+
version: "2.1.5"
384+
path_provider_android:
385+
dependency: transitive
386+
description:
387+
name: path_provider_android
388+
sha256: "0ca7359dad67fd7063cb2892ab0c0737b2daafd807cf1acecd62374c8fae6c12"
389+
url: "https://pub.dev"
390+
source: hosted
391+
version: "2.2.16"
392+
path_provider_foundation:
393+
dependency: transitive
394+
description:
395+
name: path_provider_foundation
396+
sha256: "4843174df4d288f5e29185bd6e72a6fbdf5a4a4602717eed565497429f179942"
397+
url: "https://pub.dev"
398+
source: hosted
399+
version: "2.4.1"
400+
path_provider_linux:
401+
dependency: transitive
402+
description:
403+
name: path_provider_linux
404+
sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279
405+
url: "https://pub.dev"
406+
source: hosted
407+
version: "2.2.1"
408+
path_provider_platform_interface:
409+
dependency: transitive
410+
description:
411+
name: path_provider_platform_interface
412+
sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334"
413+
url: "https://pub.dev"
414+
source: hosted
415+
version: "2.1.2"
416+
path_provider_windows:
417+
dependency: transitive
418+
description:
419+
name: path_provider_windows
420+
sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7
421+
url: "https://pub.dev"
422+
source: hosted
423+
version: "2.3.0"
424+
platform:
425+
dependency: transitive
426+
description:
427+
name: platform
428+
sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984"
429+
url: "https://pub.dev"
430+
source: hosted
431+
version: "3.1.6"
432+
plugin_platform_interface:
433+
dependency: transitive
434+
description:
435+
name: plugin_platform_interface
436+
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
437+
url: "https://pub.dev"
438+
source: hosted
439+
version: "2.1.8"
315440
pool:
316441
dependency: transitive
317442
description:
@@ -525,6 +650,14 @@ packages:
525650
url: "https://pub.dev"
526651
source: hosted
527652
version: "1.2.1"
653+
xdg_directories:
654+
dependency: transitive
655+
description:
656+
name: xdg_directories
657+
sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15"
658+
url: "https://pub.dev"
659+
source: hosted
660+
version: "1.1.0"
528661
yaml:
529662
dependency: transitive
530663
description:
@@ -534,5 +667,5 @@ packages:
534667
source: hosted
535668
version: "3.1.3"
536669
sdks:
537-
dart: ">=3.7.0-0 <4.0.0"
538-
flutter: ">=3.18.0-18.0.pre.54"
670+
dart: ">=3.7.0 <4.0.0"
671+
flutter: ">=3.27.0"

0 commit comments

Comments
 (0)