diff --git a/forui/example/lib/main.dart b/forui/example/lib/main.dart index 8ddc61604..c57629f89 100644 --- a/forui/example/lib/main.dart +++ b/forui/example/lib/main.dart @@ -18,10 +18,10 @@ class Application extends StatelessWidget { data: FThemes.zinc.light, child: Scaffold( backgroundColor: FThemes.zinc.light.colorScheme.background, - body: Column( + body: const Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - const ExampleWidget(), + ExampleWidget(), ], ), ), @@ -53,20 +53,16 @@ class _ExampleWidgetState extends State { text: 'Delete?', onPress: () => showAdaptiveDialog( context: context, - builder: (context) { - final style = context.theme.cardStyle; - return FDialog( - title: 'Are you absolutely sure?', - subtitle: 'This action cannot be undone. This will permanently delete your account and remove your data from our servers.', - actions: [ - FButton(text: 'Continue', onPress: () {}), - FButton(design: FButtonVariant.outlined, text: 'Cancel', onPress: () { - Navigator.of(context).pop(); - }), - ], - ); - // return _dialog(context); - }, + builder: (context) => FDialog( + title: 'Are you absolutely sure?', + subtitle: 'This action cannot be undone. This will permanently delete your account and remove your data from our servers.', + actions: [ + FButton(text: 'Continue', onPress: () {}), + FButton(design: FButtonVariant.outlined, text: 'Cancel', onPress: () { + Navigator.of(context).pop(); + }), + ], + ), ), ), ], diff --git a/forui/lib/src/widgets/dialog/dialog.dart b/forui/lib/src/widgets/dialog/dialog.dart index 79d0260ca..9b4c9aeee 100644 --- a/forui/lib/src/widgets/dialog/dialog.dart +++ b/forui/lib/src/widgets/dialog/dialog.dart @@ -1,6 +1,6 @@ import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; import 'package:flutter/semantics.dart'; -import 'package:flutter/widgets.dart'; import 'package:forui/forui.dart'; import 'package:meta/meta.dart'; import 'package:sugar/collection.dart'; diff --git a/forui/test/golden/dialog/zinc-dark-FDialogAlignment.horizontal-content.png b/forui/test/golden/dialog/zinc-dark-FDialogAlignment.horizontal-content.png new file mode 100644 index 000000000..027c140fa Binary files /dev/null and b/forui/test/golden/dialog/zinc-dark-FDialogAlignment.horizontal-content.png differ diff --git a/forui/test/golden/dialog/zinc-dark-FDialogAlignment.vertical-content.png b/forui/test/golden/dialog/zinc-dark-FDialogAlignment.vertical-content.png new file mode 100644 index 000000000..99456e908 Binary files /dev/null and b/forui/test/golden/dialog/zinc-dark-FDialogAlignment.vertical-content.png differ diff --git a/forui/test/golden/dialog/zinc-dark-raw-content.png b/forui/test/golden/dialog/zinc-dark-raw-content.png new file mode 100644 index 000000000..37ec3cd74 Binary files /dev/null and b/forui/test/golden/dialog/zinc-dark-raw-content.png differ diff --git a/forui/test/golden/dialog/zinc-light-FDialogAlignment.horizontal-content.png b/forui/test/golden/dialog/zinc-light-FDialogAlignment.horizontal-content.png new file mode 100644 index 000000000..784f9153d Binary files /dev/null and b/forui/test/golden/dialog/zinc-light-FDialogAlignment.horizontal-content.png differ diff --git a/forui/test/golden/dialog/zinc-light-FDialogAlignment.vertical-content.png b/forui/test/golden/dialog/zinc-light-FDialogAlignment.vertical-content.png new file mode 100644 index 000000000..8e7b45652 Binary files /dev/null and b/forui/test/golden/dialog/zinc-light-FDialogAlignment.vertical-content.png differ diff --git a/forui/test/golden/dialog/zinc-light-raw-content.png b/forui/test/golden/dialog/zinc-light-raw-content.png new file mode 100644 index 000000000..b7da62c79 Binary files /dev/null and b/forui/test/golden/dialog/zinc-light-raw-content.png differ diff --git a/forui/test/src/widgets/dialog_golden_test.dart b/forui/test/src/widgets/dialog_golden_test.dart new file mode 100644 index 000000000..41a86af3d --- /dev/null +++ b/forui/test/src/widgets/dialog_golden_test.dart @@ -0,0 +1,83 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:forui/forui.dart'; + +import '../test_scaffold.dart'; + +class UnderTest extends StatelessWidget { + final FDialogAlignment alignment; + + const UnderTest({required this.alignment, super.key}); + + @override + Widget build(BuildContext context) => FDialog( + alignment: alignment, + title: 'Are you absolutely sure?', + subtitle: 'This action cannot be undone. This will permanently delete your account and remove your data from our servers.', + actions: [ + FButton(text: 'Continue', onPress: () {}), + FButton(design: FButtonVariant.outlined, text: 'Cancel', onPress: () { + Navigator.of(context).pop(); + }), + ], + ); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty('alignment', alignment)); + } +} + + +void main() { + group('FDialog', () { + for (final (name, theme, background) in TestScaffold.themes) { + for (final alignment in [FDialogAlignment.horizontal, FDialogAlignment.vertical]) { + testWidgets('$name with $alignment content', (tester) async { + await tester.pumpWidget( + MaterialApp( + home: TestScaffold( + data: theme, + background: background, + child: UnderTest(alignment: alignment), + ), + ), + ); + + await expectLater( + find.byType(UnderTest), + matchesGoldenFile('dialog/$name-$alignment-content.png'), + ); + }); + } + + + testWidgets('$name with raw content', (tester) async { + await tester.pumpWidget( + TestScaffold( + data: theme, + background: background, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + FDialog.raw( + builder: (context, style) => const SizedBox( + width: 50, + height: 50, + ), + ), + ], + ), + ), + ); + + await expectLater( + find.byType(FDialog), + matchesGoldenFile('dialog/$name-raw-content.png'), + ); + }); + } + }); +}