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

✨ chore: provide defaults for theming styles #11

Merged
merged 5 commits into from
Apr 24, 2023
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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class MyApp extends StatelessWidget {
debugShowCheckedModeBanner: false,
title: 'Smarty',
themeMode: value.theme,
theme: const BatThemeData.light(),
darkTheme: const BatThemeData.dark(),
home: const MyHomePage(),
onGenerateRoute: AppRouter.generateRoutes,
navigatorKey: AppNavigator.key,
Expand Down
48 changes: 48 additions & 0 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions lib/src/themes/button_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ class BatButtonStyle extends ThemeExtension<BatButtonStyle> {
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(
Expand Down
8 changes: 8 additions & 0 deletions lib/src/themes/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ class BatColors extends ThemeExtension<BatColors> {
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,
Expand Down
20 changes: 17 additions & 3 deletions lib/src/themes/theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,26 @@ class BatThemeData extends ThemeExtension<BatThemeData> {
final BatColors colors;
final BatTypography typography;

BatThemeData({
required this.colors,
required this.buttonStyle,
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<BatThemeData>()!;

Expand Down
36 changes: 18 additions & 18 deletions test/src/themes/theme_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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(
Expand Down
18 changes: 9 additions & 9 deletions test/src/themes/theme_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down