-
-
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.
Merge pull request #1 from tecdrop/v2
- Loading branch information
Showing
29 changed files
with
1,298 additions
and
617 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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
{ | ||
"dart.lineLength": 100, | ||
"cSpell.words": [ | ||
"Tecdrop", | ||
"colorhap", | ||
"fullscreen" | ||
"consts", | ||
"fullscreen", | ||
"noname", | ||
"Tecdrop", | ||
"writeln" | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// Copyright 2020-2023 Tecdrop (www.tecdrop.com) | ||
// Use of this source code is governed by an MIT-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:go_router/go_router.dart'; | ||
|
||
import '../common/app_const.dart' as consts; | ||
import '../common/app_settings.dart' as settings; | ||
import '../common/ui_strings.dart' as strings; | ||
import '../models/color_type.dart'; | ||
import '../models/random_color.dart'; | ||
import '../screens/color_favorites_screen.dart'; | ||
import '../screens/color_info_screen.dart'; | ||
import '../screens/invalid_screen.dart'; | ||
import '../screens/random_color_screen.dart'; | ||
import '../utils/color_utils.dart' as color_utils; | ||
|
||
/// The route configuration for the app. | ||
final GoRouter appRouter = GoRouter( | ||
// The error handler redirects to the Invalid screen | ||
onException: (_, GoRouterState state, GoRouter router) { | ||
router.go('/404', extra: state.uri.toString()); | ||
}, | ||
|
||
// The routes configuration | ||
routes: <RouteBase>[ | ||
// The home route of the app is the Random Color screen | ||
GoRoute( | ||
path: '/', | ||
builder: _randomColorRouteBuilder, | ||
routes: [ | ||
// The child route for the Color Info screen | ||
GoRoute( | ||
path: 'color/:colorType/:colorHex/:colorName', | ||
builder: _colorInfoRouteBuilder, | ||
), | ||
// The child route for the Favorite Colors screen | ||
GoRoute( | ||
path: 'fav', | ||
builder: _colorFavoritesRouteBuilder, | ||
routes: [ | ||
// The child route for the Color Info screen (from the Favorite Colors screen) | ||
GoRoute( | ||
path: 'color/:colorType/:colorHex/:colorName', | ||
builder: _colorInfoRouteBuilder, | ||
), | ||
], | ||
), | ||
], | ||
), | ||
|
||
// The route for the Invalid screen, when the route is invalid | ||
GoRoute( | ||
path: '/404', | ||
builder: (BuildContext context, GoRouterState state) { | ||
return InvalidScreen(message: strings.invalidPage(state.extra as String?)); | ||
}, | ||
), | ||
|
||
// The route for the Random Color screen, when the color type is specified in the route | ||
GoRoute( | ||
path: '/:colorType', | ||
redirect: _randomColorRouteRedirect, | ||
), | ||
], | ||
); | ||
|
||
// ----------------------------------------------------------------------------------------------- | ||
// Random Color Route (Home) | ||
// ----------------------------------------------------------------------------------------------- | ||
|
||
/// The route builder for the Random Color screen, which is the home screen of the app. | ||
Widget _randomColorRouteBuilder(BuildContext context, GoRouterState state) { | ||
return RandomColorScreen( | ||
colorType: settings.colorType, | ||
); | ||
} | ||
|
||
/// The route redirect for the Random Color screen, when the color type is specified in the route. | ||
FutureOr<String?> _randomColorRouteRedirect(BuildContext context, GoRouterState state) { | ||
settings.colorType = ColorType.fromShortString(state.pathParameters['colorType']); | ||
return '/'; | ||
} | ||
|
||
/// Navigates to the Random Color screen to generate random colors of the specified type. | ||
void gotoRandomColorRoute(BuildContext context, ColorType colorType) { | ||
settings.colorType = colorType; | ||
context.go('/${colorType.toShortString()}'); | ||
} | ||
|
||
// ----------------------------------------------------------------------------------------------- | ||
// Color Info Route | ||
// ----------------------------------------------------------------------------------------------- | ||
|
||
/// The route builder for the Color Info screen. | ||
Widget _colorInfoRouteBuilder(BuildContext context, GoRouterState state) { | ||
ColorType colorType = ColorType.fromShortString(state.pathParameters['colorType']); | ||
String? colorCode = state.pathParameters['colorHex']; | ||
Color? color = color_utils.rgbHexToColor(colorCode); | ||
String? colorName = state.pathParameters['colorName']; | ||
|
||
// If the color code is invalid, return the Invalid Color screen | ||
if (color == null) { | ||
return InvalidScreen(message: strings.invalidColor(colorCode)); | ||
} | ||
|
||
return ColorInfoScreen( | ||
randomColor: RandomColor( | ||
color: color, | ||
type: colorType, | ||
name: colorName != consts.noNameColorParam ? colorName : null, | ||
), | ||
); | ||
} | ||
|
||
/// Navigates to the Color Info screen to show information about the specified color. | ||
void gotoColorInfoRoute(BuildContext context, RandomColor randomColor, {bool fromFav = false}) { | ||
final String colorType = randomColor.type.toShortString(); | ||
final String colorCode = color_utils.toHexString(randomColor.color, withHash: false); | ||
final String colorName = randomColor.name ?? consts.noNameColorParam; | ||
context.go('${fromFav ? '/fav' : ''}/color/$colorType/$colorCode/$colorName'); | ||
} | ||
|
||
// ----------------------------------------------------------------------------------------------- | ||
// Color Favorites Route | ||
// ----------------------------------------------------------------------------------------------- | ||
|
||
/// The route builder for the Color Favorites screen. | ||
Widget _colorFavoritesRouteBuilder(BuildContext context, GoRouterState state) { | ||
return const ColorFavoritesScreen(); | ||
} | ||
|
||
/// Navigates to the Color Favorites screen to show the list of favorite colors. | ||
Future<void> gotoColorFavoritesRoute(BuildContext context) async { | ||
return await context.push<void>('/fav'); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2020-2023 Tecdrop (www.tecdrop.com) | ||
// Use of this source code is governed by an MIT-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
/// Returns the light or dark theme for the app. | ||
ThemeData getAppTheme(Brightness brightness) { | ||
final bool isDark = brightness == Brightness.dark; | ||
|
||
return ThemeData( | ||
// The color scheme used by the app | ||
primaryColor: isDark ? Colors.white : Colors.black, | ||
colorScheme: isDark | ||
? ColorScheme.dark( | ||
primary: Colors.black, | ||
onPrimary: Colors.white, | ||
secondary: const ColorScheme.dark().surface, | ||
onSecondary: const ColorScheme.dark().onSurface, | ||
) | ||
: ColorScheme.light( | ||
primary: Colors.white, | ||
onPrimary: Colors.black, | ||
secondary: const ColorScheme.light().surface, | ||
onSecondary: const ColorScheme.light().onSurface, | ||
), | ||
textButtonTheme: TextButtonThemeData( | ||
// The text color of text buttons | ||
style: TextButton.styleFrom( | ||
foregroundColor: isDark ? Colors.white : Colors.black, | ||
), | ||
), | ||
|
||
// Always use the dark background snack bar theme | ||
snackBarTheme: SnackBarThemeData( | ||
// Based on https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/snack_bar.dart#L859 | ||
backgroundColor: Color.alphaBlend( | ||
const ColorScheme.light().onSurface.withOpacity(0.80), | ||
const ColorScheme.light().surface, | ||
), | ||
contentTextStyle: const TextStyle(color: Colors.white), | ||
actionTextColor: Colors.white, | ||
), | ||
); | ||
} |
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
Oops, something went wrong.