-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(generator): ✨ add CustomThemeAddon to generator
- Loading branch information
Showing
10 changed files
with
139 additions
and
2 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
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
2 changes: 2 additions & 0 deletions
2
...rator/lib/code_generators/instances/addons/material_theme_addon/material_theme_addon.dart
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,2 +1,4 @@ | ||
// TODO this whole implementation is currently not used and is covered by | ||
// CustomThemeAddon | ||
export './material_theme_addon_instance.dart'; | ||
export './material_theme_setting_instance.dart'; |
29 changes: 29 additions & 0 deletions
29
...nerator/lib/code_generators/instances/addons/theme_addon/custom_theme_addon_instance.dart
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,29 @@ | ||
import 'package:widgetbook_generator/code_generators/instances/addons/addon_instance.dart'; | ||
import 'package:widgetbook_generator/code_generators/instances/addons/theme_addon/theme_addon.dart'; | ||
import 'package:widgetbook_generator/code_generators/properties/property.dart'; | ||
import 'package:widgetbook_generator/models/widgetbook_theme_data.dart'; | ||
|
||
class CustomThemeAddonInstance extends AddOnInstance { | ||
CustomThemeAddonInstance({ | ||
required String themeType, | ||
required List<WidgetbookThemeData> themes, | ||
}) : super( | ||
name: 'CustomThemeAddon', | ||
genericParameters: [ | ||
themeType, | ||
], | ||
properties: [ | ||
Property( | ||
key: 'setting', | ||
instance: ThemeSettingInstance( | ||
themeType: themeType, | ||
themes: themes, | ||
defaultTheme: themes.firstWhere( | ||
(element) => element.isDefault, | ||
orElse: () => themes.first, | ||
), | ||
), | ||
), | ||
], | ||
); | ||
} |
2 changes: 2 additions & 0 deletions
2
...es/widgetbook_generator/lib/code_generators/instances/addons/theme_addon/theme_addon.dart
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,2 @@ | ||
export 'custom_theme_addon_instance.dart'; | ||
export 'theme_setting_instance.dart'; |
30 changes: 30 additions & 0 deletions
30
...ok_generator/lib/code_generators/instances/addons/theme_addon/theme_setting_instance.dart
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,30 @@ | ||
import 'package:widgetbook_generator/code_generators/instances/instance.dart'; | ||
import 'package:widgetbook_generator/code_generators/instances/list_instance.dart'; | ||
import 'package:widgetbook_generator/code_generators/instances/theme_instance.dart'; | ||
import 'package:widgetbook_generator/code_generators/properties/property.dart'; | ||
import 'package:widgetbook_generator/models/widgetbook_theme_data.dart'; | ||
|
||
class ThemeSettingInstance extends Instance { | ||
ThemeSettingInstance({ | ||
required String themeType, | ||
required List<WidgetbookThemeData> themes, | ||
required WidgetbookThemeData defaultTheme, | ||
}) : super( | ||
name: 'ThemeSetting', | ||
genericParameters: [ | ||
themeType, | ||
], | ||
properties: [ | ||
Property( | ||
key: 'themes', | ||
instance: ListInstance( | ||
instances: themes.map((e) => ThemeInstance(theme: e)).toList(), | ||
), | ||
), | ||
Property( | ||
key: 'activeTheme', | ||
instance: ThemeInstance(theme: defaultTheme), | ||
), | ||
], | ||
); | ||
} |
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
19 changes: 19 additions & 0 deletions
19
...st/src/code_generators/instances/addons/theme_addon/custom_theme_addon_instance_test.dart
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,19 @@ | ||
import 'package:test/test.dart'; | ||
import 'package:widgetbook_generator/code_generators/instances/instances.dart'; | ||
|
||
import '../../../../mocks/mocks.dart'; | ||
|
||
void main() { | ||
group( | ||
'$CustomThemeAddonInstance', | ||
() { | ||
test('.name is "CustomThemeAddon"', () { | ||
final sut = CustomThemeAddonInstance( | ||
themes: themes, | ||
themeType: 'ThemeData', | ||
); | ||
expect(sut.name, equals('CustomThemeAddon')); | ||
}); | ||
}, | ||
); | ||
} |
22 changes: 22 additions & 0 deletions
22
...or/test/src/code_generators/instances/addons/theme_addon/theme_setting_instance_test.dart
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,22 @@ | ||
import 'package:test/test.dart'; | ||
import 'package:widgetbook_generator/code_generators/instances/instances.dart'; | ||
|
||
import '../../../../mocks/mocks.dart'; | ||
|
||
void main() { | ||
group('$ThemeSettingInstance', () { | ||
test( | ||
'.name returns "ThemeSetting"', | ||
() { | ||
expect( | ||
ThemeSettingInstance( | ||
themes: themes, | ||
defaultTheme: themeLight, | ||
themeType: 'ThemeData', | ||
).name, | ||
equals('ThemeSetting'), | ||
); | ||
}, | ||
); | ||
}); | ||
} |