diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ff3b12..41b3673 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 0.13.0 + - feat: `NesContainer.paintBuilder` to override the one set on the theme. + # 0.12.1 - fix: theme lerp causing error on null access. diff --git a/lib/src/widgets/containers/nes_container.dart b/lib/src/widgets/containers/nes_container.dart index 4674fcd..a596bd1 100644 --- a/lib/src/widgets/containers/nes_container.dart +++ b/lib/src/widgets/containers/nes_container.dart @@ -14,6 +14,7 @@ class NesContainer extends StatelessWidget { this.height, this.backgroundColor, this.padding, + this.painterBuilder, }); /// An optional label for the container. @@ -37,6 +38,11 @@ class NesContainer extends StatelessWidget { /// When omitted, defaults to [NesContainerTheme.padding]. final EdgeInsets? padding; + /// The builder that create the painter to use for this container. + /// + /// When omitted, defaults to [NesContainerTheme.painter]. + final NesContainerPainterBuilder? painterBuilder; + @override Widget build(BuildContext context) { final nesContainerTheme = context.nesThemeExtension(); @@ -51,8 +57,10 @@ class NesContainer extends StatelessWidget { final pixelSize = nesContainerTheme.pixelSize ?? nesTheme.pixelSize; + final painter = painterBuilder ?? nesContainerTheme.painter; + return CustomPaint( - painter: nesContainerTheme.painter( + painter: painter( label: label, pixelSize: pixelSize, textStyle: textStyle, diff --git a/widgetbook/lib/main.dart b/widgetbook/lib/main.dart index 1ece278..40694f3 100644 --- a/widgetbook/lib/main.dart +++ b/widgetbook/lib/main.dart @@ -2,5 +2,6 @@ import 'package:flutter/material.dart'; import 'package:widgetbook_app/widgetbook/widgetbook.dart'; void main() { + WidgetsFlutterBinding.ensureInitialized(); runApp(const WidgetbookApp()); } diff --git a/widgetbook/lib/widgetbook/use_cases/containers.dart b/widgetbook/lib/widgetbook/use_cases/containers.dart new file mode 100644 index 0000000..4aae27a --- /dev/null +++ b/widgetbook/lib/widgetbook/use_cases/containers.dart @@ -0,0 +1,74 @@ +// ignore_for_file: public_member_api_docs + +import 'package:flutter/material.dart'; +import 'package:nes_ui/nes_ui.dart'; +import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook; + +@widgetbook.UseCase( + name: 'default', + type: NesContainer, +) +Widget normal(BuildContext context) => const Center( + child: NesContainer( + width: 200, + height: 200, + child: Center( + child: Text( + 'Hello World', + ), + ), + ), + ); + +@widgetbook.UseCase( + name: 'with label', + type: NesContainer, +) +Widget label(BuildContext context) => const Center( + child: NesContainer( + width: 200, + height: 200, + label: 'Label', + child: Center( + child: Text( + 'Hello World', + ), + ), + ), + ); + +@widgetbook.UseCase( + name: 'with square corner painter', + type: NesContainer, +) +Widget squareConer(BuildContext context) => const Center( + child: NesContainer( + painterBuilder: NesContainerSquareCornerPainter.new, + width: 200, + height: 200, + label: 'Label', + child: Center( + child: Text( + 'Hello World', + ), + ), + ), + ); + +@widgetbook.UseCase( + name: 'with corner inner square painter', + type: NesContainer, +) +Widget cornerInnerSquare(BuildContext context) => const Center( + child: NesContainer( + painterBuilder: NesContainerCornerInnerSquarePainter.new, + width: 200, + height: 200, + label: 'Label', + child: Center( + child: Text( + 'Hello World', + ), + ), + ), + ); diff --git a/widgetbook/lib/widgetbook/widgetbook.dart b/widgetbook/lib/widgetbook/widgetbook.dart index e1f4482..8e6e001 100644 --- a/widgetbook/lib/widgetbook/widgetbook.dart +++ b/widgetbook/lib/widgetbook/widgetbook.dart @@ -39,7 +39,10 @@ class WidgetbookApp extends StatelessWidget { themeBuilder: (context, theme, child) { return Theme( data: theme, - child: child, + child: DefaultTextStyle( + style: theme.textTheme.bodyMedium ?? const TextStyle(), + child: child, + ), ); }, ), diff --git a/widgetbook/lib/widgetbook/widgetbook.directories.g.dart b/widgetbook/lib/widgetbook/widgetbook.directories.g.dart index 2b67b31..1a943de 100644 --- a/widgetbook/lib/widgetbook/widgetbook.directories.g.dart +++ b/widgetbook/lib/widgetbook/widgetbook.directories.g.dart @@ -12,6 +12,7 @@ import 'package:widgetbook/widgetbook.dart' as _i1; import 'package:widgetbook_app/widgetbook/use_cases/buttons.dart' as _i2; import 'package:widgetbook_app/widgetbook/use_cases/checkboxes.dart' as _i3; +import 'package:widgetbook_app/widgetbook/use_cases/containers.dart' as _i4; final directories = <_i1.WidgetbookNode>[ _i1.WidgetbookFolder( @@ -49,6 +50,32 @@ final directories = <_i1.WidgetbookNode>[ builder: _i3.checkbox, ), ), + _i1.WidgetbookFolder( + name: 'containers', + children: [ + _i1.WidgetbookComponent( + name: 'NesContainer', + useCases: [ + _i1.WidgetbookUseCase( + name: 'default', + builder: _i4.normal, + ), + _i1.WidgetbookUseCase( + name: 'with corner inner square painter', + builder: _i4.cornerInnerSquare, + ), + _i1.WidgetbookUseCase( + name: 'with label', + builder: _i4.label, + ), + _i1.WidgetbookUseCase( + name: 'with square corner painter', + builder: _i4.squareConer, + ), + ], + ) + ], + ), ], ) ]; diff --git a/widgetbook/lib/widgetbook/widgets/use_case_decorator.dart b/widgetbook/lib/widgetbook/widgets/use_case_decorator.dart index 058ca54..4ac52fd 100644 --- a/widgetbook/lib/widgetbook/widgets/use_case_decorator.dart +++ b/widgetbook/lib/widgetbook/widgets/use_case_decorator.dart @@ -17,7 +17,7 @@ class UseCaseDecorator extends StatelessWidget { color: Colors.grey[600], ), child: SizedBox.expand( - child: child, + child: Material(child: child), ), ); }