Skip to content

Commit

Permalink
feat: to override the one set on the theme.
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzanardo committed Jan 3, 2024
1 parent b2fee49 commit bf726ec
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
10 changes: 9 additions & 1 deletion lib/src/widgets/containers/nes_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class NesContainer extends StatelessWidget {
this.height,
this.backgroundColor,
this.padding,
this.painterBuilder,
});

/// An optional label for the container.
Expand All @@ -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<NesContainerTheme>();
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions widgetbook/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import 'package:flutter/material.dart';
import 'package:widgetbook_app/widgetbook/widgetbook.dart';

void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const WidgetbookApp());
}
74 changes: 74 additions & 0 deletions widgetbook/lib/widgetbook/use_cases/containers.dart
Original file line number Diff line number Diff line change
@@ -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',
),
),
),
);
5 changes: 4 additions & 1 deletion widgetbook/lib/widgetbook/widgetbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
);
},
),
Expand Down
27 changes: 27 additions & 0 deletions widgetbook/lib/widgetbook/widgetbook.directories.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
),
],
)
],
),
],
)
];
2 changes: 1 addition & 1 deletion widgetbook/lib/widgetbook/widgets/use_case_decorator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class UseCaseDecorator extends StatelessWidget {
color: Colors.grey[600],
),
child: SizedBox.expand(
child: child,
child: Material(child: child),
),
);
}
Expand Down

0 comments on commit bf726ec

Please sign in to comment.