Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(router): implement GoRouter navigation system #32

Merged
merged 12 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified assets/icons/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/logo_name.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"title": "Hello, World!",
"subtitle": "Welcome to Localization",
"description": "You have pushed the button this many times:",
"switch_language": "Switch language"
"switch_language": "Switch language",
"applications": "Applications"
}
5 changes: 3 additions & 2 deletions lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"title": "¡Hola, Mundo!",
"subtitle": "Bienvenido a Localización",
"description": "Has pulsado el botón tantas veces:",
"switch_language": "Cambiar idioma"
"description": "Has pulsado el botón tantas veces:",
"switch_language": "Cambiar idioma",
"applications": "Aplicaciones"
}
7 changes: 4 additions & 3 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"title": "Bonjour",
"subtitle": "Bienvenue dans Localisation",
"description": "Vous avez appuyé sur le bouton autant de fois :",
"switch_language": "Changer de langue"
}
"description": "Vous avez appuyé sur le bouton autant de fois :",
"switch_language": "Changer de langue",
"applications": "Applications"
}
14 changes: 7 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:gui/src/core/router/app_router.dart';
import 'package:gui/src/features/main/theme/bloc/theme_bloc.dart';
import 'src/features/main/language/presentation/bloc/language_bloc.dart';
import 'src/features/splash_screen/presentation/screen/home_page.dart';

void main() {
runApp(
Expand All @@ -31,23 +31,23 @@ class MyApp extends StatelessWidget {
builder: (context, languageState) {
return BlocBuilder<ThemeBloc, ThemeState>(
builder: (context, themeState) {
return MaterialApp(
return MaterialApp.router(
debugShowCheckedModeBanner: false,
routerConfig: routerConfig,
title: 'Flutter Demo',
theme: themeState.themeData,
locale: languageState.selectedLanguage.value,
theme: themeState.themeData,
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('en'), // English
Locale('es'), // Spanish
Locale('fr'), // French
Locale('en'),
Locale('es'),
Locale('fr'),
],
home: const MyHomePage(),
);
},
);
Expand Down
16 changes: 16 additions & 0 deletions lib/presentation/bloc/language_bloc/language_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:bloc/bloc.dart';
import '../../../src/features/main/language/presentation/bloc/language_bloc.dart';

const languagePrefsKey = 'languagePrefs';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please if dont use remove it


@phoenixit99


class LanguageBloc extends Bloc<LanguageEvent, LanguageState> {
LanguageBloc() : super(const LanguageState()) {
on<ChangeLanguage>(onChangeLanguage);
}
Future<void> onChangeLanguage(
ChangeLanguage event,
Emitter<LanguageState> emit,
) async {
emit(state.copyWith(selectedLanguage: event.selectedLanguage));
}
}
1 change: 1 addition & 0 deletions lib/src/core/common/colors/app_colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import 'package:flutter/material.dart' show Color;
class AppColors {
AppColors._();
static const primaryDark = Color(0xFF242424);
static const splashBackground = Color(0xFF00142E);
}
16 changes: 16 additions & 0 deletions lib/src/core/router/app_router.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:go_router/go_router.dart';
import 'package:gui/src/features/splash/presentation/screen/splash_screen.dart';
import 'basic_routes.dart';
import 'registration_routes.dart';

final GoRouter routerConfig = GoRouter(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all this parts used for register route.

we need another route for basic route.

so create two file one for basic route and another for registration route.
and consume two routes in this file. (in future need move any route parts to self modules.)


@phoenixit99

debugLogDiagnostics: true,
routes: [
GoRoute(
path: '/',
builder: (context, state) => SplashScreen(),
),
...basicRoutes,
...registrationRoutes,
],
);
22 changes: 22 additions & 0 deletions lib/src/core/router/basic_routes.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:go_router/go_router.dart';
import 'package:gui/src/features/dashboard/presentation/screen/dashboard_page.dart';
import 'package:gui/src/features/password/presentation/screen/password_page.dart';
import 'route_name.dart';

final List<GoRoute> basicRoutes = [
GoRoute(
path: AppRoute.basicPassword.fullPath,
name: AppRoute.basicPassword.name,
builder: (context, state) => PasswordPage(
fromRegistrationRoute:
state.matchedLocation.contains(AppRoute.finish.name),
),
routes: [
GoRoute(
path: AppRoute.basicDashboard.path,
name: AppRoute.basicDashboard.name,
builder: (context, state) => const DashboardPage(),
),
],
),
];
90 changes: 90 additions & 0 deletions lib/src/core/router/registration_routes.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import 'package:go_router/go_router.dart';
import 'package:gui/src/features/confirmation_seed/presentation/screen/confirmation_seed_page.dart';
import 'package:gui/src/features/dashboard/presentation/screen/dashboard_page.dart';
import 'package:gui/src/features/finish/presentation/screen/finish_page.dart';
import 'package:gui/src/features/initialize_mode/presentation/screen/initialize_mode_page.dart';
import 'package:gui/src/features/initializing/presentation/screen/initializing_page.dart';
import 'package:gui/src/features/master_password/presentation/screen/master_password_page.dart';
import 'package:gui/src/features/password/presentation/screen/password_page.dart';
import 'package:gui/src/features/restoration_seed/presentation/screen/restoration_seed_page.dart';
import 'package:gui/src/features/validator_config/presentation/screen/validator_config_page.dart';
import 'package:gui/src/features/welcome/presentation/screen/welcome_page.dart';
import 'route_name.dart';

final List<GoRoute> registrationRoutes = [
GoRoute(
path: AppRoute.welcome.fullPath,
name: AppRoute.welcome.name,
builder: (context, state) => const WelcomePage(),
routes: [
GoRoute(
path: AppRoute.initializeMode.path,
name: AppRoute.initializeMode.name,
builder: (context, state) => const InitializeModePage(),
routes: [
GoRoute(
path: AppRoute.restorationSeed.path,
name: AppRoute.restorationSeed.name,
builder: (context, state) => const RestorationSeedPage(),
routes: [
GoRoute(
path: AppRoute.confirmationSeed.path,
name: AppRoute.confirmationSeed.name,
builder: (context, state) => const ConfirmationSeedPage(),
routes: [
GoRoute(
path: AppRoute.masterPassword.path,
name: AppRoute.masterPassword.name,
builder: (context, state) => const MasterPasswordPage(),
routes: [
GoRoute(
path: AppRoute.validatorConfig.path,
name: AppRoute.validatorConfig.name,
builder: (context, state) =>
const ValidatorConfigPage(),
routes: [
GoRoute(
path: AppRoute.initializing.path,
name: AppRoute.initializing.name,
builder: (context, state) =>
const InitializingPage(),
routes: [
GoRoute(
path: AppRoute.finish.path,
name: AppRoute.finish.name,
builder: (context, state) => const FinishPage(),
routes: [
GoRoute(
path: AppRoute.password.path,
name: AppRoute.password.name,
builder: (context, state) => PasswordPage(
fromRegistrationRoute: state
.matchedLocation
.contains(AppRoute.finish.name),
),
routes: [
GoRoute(
path: AppRoute.dashboard.path,
name: AppRoute.dashboard.name,
builder: (context, state) =>
const DashboardPage(),
),
],
),
],
),
],
),
],
),
],
),
],
),
],
),
],
),
],
),
];
18 changes: 18 additions & 0 deletions lib/src/core/router/route_name.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
enum AppRoute {
splash,
welcome,
initializeMode,
restorationSeed,
confirmationSeed,
masterPassword,
validatorConfig,
initializing,
finish,
password,
dashboard,
basicPassword,
basicDashboard;

String get fullPath => '/$name';
String get path => name;
}
7 changes: 6 additions & 1 deletion lib/src/core/utils/assets/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:gui/src/core/router/route_name.dart';

class ConfirmationSeedPage extends StatelessWidget {
const ConfirmationSeedPage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Confirmation Seed Page'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
context.goNamed(AppRoute.masterPassword.name);
},
child: Text('Navigate to ${AppRoute.masterPassword.name}'),
),
),
);
}
}
14 changes: 14 additions & 0 deletions lib/src/features/dashboard/presentation/screen/dashboard_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:flutter/material.dart';

class DashboardPage extends StatelessWidget {
const DashboardPage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Dashboard Page'),
),
);
}
}
24 changes: 24 additions & 0 deletions lib/src/features/finish/presentation/screen/finish_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:gui/src/core/router/route_name.dart';

class FinishPage extends StatelessWidget {
const FinishPage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Finish Page'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
context.goNamed(AppRoute.password.name);
},
child: Text('Navigate to ${AppRoute.password.name}'),
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:gui/src/core/router/route_name.dart';

class InitializeModePage extends StatelessWidget {
const InitializeModePage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Initialize Mode'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
context.goNamed(AppRoute.restorationSeed.name);
},
child: Text('Navigate to ${AppRoute.restorationSeed.name}'),
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:gui/src/core/router/route_name.dart';

class InitializingPage extends StatelessWidget {
const InitializingPage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Initializing Page'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
context.goNamed(AppRoute.finish.name);
},
child: Text('Navigate to ${AppRoute.finish.name}'),
),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import 'package:gui/src/features/main/language/data/language_model.dart';
part 'language_event.dart';
part 'language_state.dart';

const languagePrefsKey = 'languagePrefs';

class LanguageBloc extends Bloc<LanguageEvent, LanguageState> {
LanguageBloc() : super(const LanguageState()) {
on<ChangeLanguage>(onChangeLanguage);
Expand Down
Loading
Loading