From 1fc21ad22110c167f061241d50f101121504c7bb Mon Sep 17 00:00:00 2001 From: Mastersam07 Date: Mon, 24 Apr 2023 19:58:30 +0100 Subject: [PATCH 1/5] :sparkles: chore: provide defaults for theming styles --- example/lib/main.dart | 1 + example/pubspec.lock | 48 ++++++++++++++++++++++++++++++++ example/pubspec.yaml | 1 + lib/src/themes/button_style.dart | 11 ++++++++ lib/src/themes/colors.dart | 8 ++++++ lib/src/themes/theme_data.dart | 4 +-- 6 files changed, 71 insertions(+), 2 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 49d64f2..670f844 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -39,6 +39,7 @@ class MyApp extends StatelessWidget { debugShowCheckedModeBanner: false, title: 'Smarty', themeMode: value.theme, + theme: BatThemeData(), home: const MyHomePage(), onGenerateRoute: AppRouter.generateRoutes, navigatorKey: AppNavigator.key, diff --git a/example/pubspec.lock b/example/pubspec.lock index 6533bc6..6561aac 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -231,6 +231,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.5" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: c33da08e136c3df0190bd5bbe51ae1df4a7d96e7954d1d7249fea2968a72d317 + url: "https://pub.dev" + source: hosted + version: "4.8.0" lints: dependency: transitive description: @@ -271,6 +279,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" + opay_online_flutter_sdk: + dependency: "direct main" + description: + name: opay_online_flutter_sdk + sha256: b76039ade09403ca845876dc4cae734047f27a57048f671bcf4e9477da8022f5 + url: "https://pub.dev" + source: hosted + version: "0.9.6" path: dependency: transitive description: @@ -500,6 +516,38 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + webview_flutter: + dependency: transitive + description: + name: webview_flutter + sha256: "392c1d83b70fe2495de3ea2c84531268d5b8de2de3f01086a53334d8b6030a88" + url: "https://pub.dev" + source: hosted + version: "3.0.4" + webview_flutter_android: + dependency: transitive + description: + name: webview_flutter_android + sha256: "8b3b2450e98876c70bfcead876d9390573b34b9418c19e28168b74f6cb252dbd" + url: "https://pub.dev" + source: hosted + version: "2.10.4" + webview_flutter_platform_interface: + dependency: transitive + description: + name: webview_flutter_platform_interface + sha256: "812165e4e34ca677bdfbfa58c01e33b27fd03ab5fa75b70832d4b7d4ca1fa8cf" + url: "https://pub.dev" + source: hosted + version: "1.9.5" + webview_flutter_wkwebview: + dependency: transitive + description: + name: webview_flutter_wkwebview + sha256: a5364369c758892aa487cbf59ea41d9edd10f9d9baf06a94e80f1bd1b4c7bbc0 + url: "https://pub.dev" + source: hosted + version: "2.9.5" win32: dependency: transitive description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index ed2f09a..17bc727 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -41,6 +41,7 @@ dependencies: bat_theme: path: ../ provider: ^6.0.5 + opay_online_flutter_sdk: dev_dependencies: flutter_lints: ^1.0.0 diff --git a/lib/src/themes/button_style.dart b/lib/src/themes/button_style.dart index 3247732..147fee1 100644 --- a/lib/src/themes/button_style.dart +++ b/lib/src/themes/button_style.dart @@ -21,6 +21,17 @@ class BatButtonStyle extends ThemeExtension { this.elevation, }); + /// Default for the button style. + const BatButtonStyle.fallback() + : this( + shape: const RoundedRectangleBorder(), + elevation: 0.0, + childColor: BatPalette.white, + color: BatPalette.primary, + height: 53, + padding: const EdgeInsets.symmetric(vertical: 16), + ); + /// Default for the light button style. const BatButtonStyle.light() : this( diff --git a/lib/src/themes/colors.dart b/lib/src/themes/colors.dart index 689640e..f5ed3d2 100644 --- a/lib/src/themes/colors.dart +++ b/lib/src/themes/colors.dart @@ -14,6 +14,14 @@ class BatColors extends ThemeExtension { required this.tertiary, }); + const BatColors.fallback() + : this( + background: BatPalette.white, + primary: BatPalette.primary, + secondary: BatPalette.secondary, + tertiary: BatPalette.grey, + ); + const BatColors.light() : this( background: BatPalette.white, diff --git a/lib/src/themes/theme_data.dart b/lib/src/themes/theme_data.dart index f814448..dd4cc64 100644 --- a/lib/src/themes/theme_data.dart +++ b/lib/src/themes/theme_data.dart @@ -10,8 +10,8 @@ class BatThemeData extends ThemeExtension { final BatTypography typography; BatThemeData({ - required this.colors, - required this.buttonStyle, + this.colors = const BatColors.fallback(), + this.buttonStyle = const BatButtonStyle.fallback(), this.typography = const BatTypography.regular(), }); From 06ee6844ac2fde468c9db927da2b7aa56850d256 Mon Sep 17 00:00:00 2001 From: Mastersam07 Date: Mon, 24 Apr 2023 20:08:14 +0100 Subject: [PATCH 2/5] :sparkles: feat: add light and dark constructor to battheme --- example/lib/main.dart | 3 ++- lib/src/themes/theme_data.dart | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 670f844..e8049f3 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -39,7 +39,8 @@ class MyApp extends StatelessWidget { debugShowCheckedModeBanner: false, title: 'Smarty', themeMode: value.theme, - theme: BatThemeData(), + theme: const BatThemeData.light(), + darkTheme: const BatThemeData.dark(), home: const MyHomePage(), onGenerateRoute: AppRouter.generateRoutes, navigatorKey: AppNavigator.key, diff --git a/lib/src/themes/theme_data.dart b/lib/src/themes/theme_data.dart index dd4cc64..ddfd175 100644 --- a/lib/src/themes/theme_data.dart +++ b/lib/src/themes/theme_data.dart @@ -9,12 +9,26 @@ class BatThemeData extends ThemeExtension { final BatColors colors; final BatTypography typography; - BatThemeData({ + const BatThemeData({ this.colors = const BatColors.fallback(), this.buttonStyle = const BatButtonStyle.fallback(), this.typography = const BatTypography.regular(), }); + const BatThemeData.light() + : this( + colors: const BatColors.light(), + buttonStyle: const BatButtonStyle.light(), + typography: const BatTypography.regular(), + ); + + const BatThemeData.dark() + : this( + colors: const BatColors.dark(), + buttonStyle: const BatButtonStyle.dark(), + typography: const BatTypography.regular(), + ); + static BatThemeData of(BuildContext context) => Theme.of(context).extension()!; From 208edda21c32ac52355ccd07cbe474e8d2757c55 Mon Sep 17 00:00:00 2001 From: Mastersam07 Date: Mon, 24 Apr 2023 20:09:18 +0100 Subject: [PATCH 3/5] :rotating_light: chore: lint fixes --- test/src/themes/theme_data_test.dart | 36 +++++++++++++------------- test/src/themes/theme_widget_test.dart | 18 ++++++------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/test/src/themes/theme_data_test.dart b/test/src/themes/theme_data_test.dart index 1faaed1..72a23f7 100644 --- a/test/src/themes/theme_data_test.dart +++ b/test/src/themes/theme_data_test.dart @@ -14,7 +14,7 @@ void main() { const buttonStyle = BatButtonStyle(); const typography = BatTypography.regular(); - final batTheme = BatThemeData( + const batTheme = BatThemeData( colors: colors, buttonStyle: buttonStyle, typography: typography, @@ -26,15 +26,15 @@ void main() { }); test('copyWith() creates a new instance with updated properties', () { - final batTheme = BatThemeData( - colors: const BatColors( + const batTheme = BatThemeData( + colors: BatColors( primary: Colors.red, secondary: Colors.blue, background: Colors.white, tertiary: Colors.green, ), - buttonStyle: const BatButtonStyle(), - typography: const BatTypography.regular(), + buttonStyle: BatButtonStyle(), + typography: BatTypography.regular(), ); const updatedColors = BatColors( @@ -58,26 +58,26 @@ void main() { }); test('lerp() interpolates properties of two BatThemeData instances', () { - final batTheme1 = BatThemeData( - colors: const BatColors( + const batTheme1 = BatThemeData( + colors: BatColors( primary: Colors.red, secondary: Colors.blue, background: Colors.white, tertiary: Colors.green, ), - buttonStyle: const BatButtonStyle(), - typography: const BatTypography.regular(), + buttonStyle: BatButtonStyle(), + typography: BatTypography.regular(), ); - final batTheme2 = BatThemeData( - colors: const BatColors( + const batTheme2 = BatThemeData( + colors: BatColors( primary: Colors.green, secondary: Colors.yellow, background: Colors.black, tertiary: Colors.green, ), - buttonStyle: const BatButtonStyle(), - typography: const BatTypography.regular(), + buttonStyle: BatButtonStyle(), + typography: BatTypography.regular(), ); final interpolatedBatTheme = batTheme1.lerp(batTheme2, 0); @@ -100,7 +100,7 @@ void main() { const typography = BatTypography.regular(); final themeData = ThemeData(); - final batTheme = BatThemeData( + const batTheme = BatThemeData( colors: colors, buttonStyle: buttonStyle, typography: typography, @@ -126,15 +126,15 @@ void main() { }); test('copyWith', () { - final original = BatThemeData( - colors: const BatColors( + const original = BatThemeData( + colors: BatColors( primary: Colors.red, secondary: Colors.blue, background: Colors.white, tertiary: Colors.green, ), - buttonStyle: const BatButtonStyle(elevation: 2.0), - typography: const BatTypography.regular(), + buttonStyle: BatButtonStyle(elevation: 2.0), + typography: BatTypography.regular(), ); final copy = original.copyWith( diff --git a/test/src/themes/theme_widget_test.dart b/test/src/themes/theme_widget_test.dart index cc00f07..dc107bc 100644 --- a/test/src/themes/theme_widget_test.dart +++ b/test/src/themes/theme_widget_test.dart @@ -10,9 +10,9 @@ void main() { (WidgetTester tester) async { await tester.pumpWidget( BatThemeWidget( - data: BatThemeData( - buttonStyle: const BatButtonStyle(), - colors: const BatColors( + data: const BatThemeData( + buttonStyle: BatButtonStyle(), + colors: BatColors( background: Colors.white, primary: Colors.blue, secondary: Colors.green, @@ -27,9 +27,9 @@ void main() { }); testWidgets('BatThemeWidget applies BatThemeData to Theme', (WidgetTester tester) async { - final batThemeData = BatThemeData( - buttonStyle: const BatButtonStyle(), - colors: const BatColors( + const batThemeData = BatThemeData( + buttonStyle: BatButtonStyle(), + colors: BatColors( background: Colors.white, primary: Colors.blue, secondary: Colors.green, @@ -56,9 +56,9 @@ void main() { final existingThemeData = ThemeData( colorScheme: ColorScheme.fromSwatch().copyWith(secondary: Colors.green)); - final batThemeData = BatThemeData( - buttonStyle: const BatButtonStyle(), - colors: const BatColors( + const batThemeData = BatThemeData( + buttonStyle: BatButtonStyle(), + colors: BatColors( background: Colors.white, primary: Colors.blue, secondary: Colors.green, From f863db8434c5d0ce40a8bc8f7a6ea50e9b9a92bb Mon Sep 17 00:00:00 2001 From: Mastersam07 Date: Mon, 24 Apr 2023 20:10:30 +0100 Subject: [PATCH 4/5] :memo: docs: update readme with usage --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 68d37e7..c91750d 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,23 @@ class MyApp extends StatelessWidget { } ``` +Or you can also use the `BatThemeData` light/dark constructors: + +```dart +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialApp( + theme: BatThemeData.light(), + darkTheme: BatThemeData.dark(), + home: Homepage(), + ); + } +} +``` + ## Full Usage You can check the [example](./example) to see this theming system in usage. From 9d8d1900af142faa152b18e5ab9a364afbd52cc5 Mon Sep 17 00:00:00 2001 From: Mastersam07 Date: Mon, 24 Apr 2023 20:13:39 +0100 Subject: [PATCH 5/5] :heavy_minus_sign: chore: remove uneccessary deps --- example/pubspec.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 17bc727..ed2f09a 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -41,7 +41,6 @@ dependencies: bat_theme: path: ../ provider: ^6.0.5 - opay_online_flutter_sdk: dev_dependencies: flutter_lints: ^1.0.0