From 51c74f4fb7687d304fc3f7a51bab07d46d647aa6 Mon Sep 17 00:00:00 2001 From: Erick Zanardo Date: Thu, 13 Jun 2024 09:13:30 -0300 Subject: [PATCH] feat: adding example and a simple test --- example/lib/gallery/gallery_page.dart | 2 + example/lib/gallery/sections/dpads.dart | 60 ++++++++++++++++++++++ example/lib/gallery/sections/sections.dart | 1 + test/src/widgets/nes_dpad_test.dart | 22 ++++++++ 4 files changed, 85 insertions(+) create mode 100644 example/lib/gallery/sections/dpads.dart create mode 100644 test/src/widgets/nes_dpad_test.dart diff --git a/example/lib/gallery/gallery_page.dart b/example/lib/gallery/gallery_page.dart index 4491e9b..3967bc7 100644 --- a/example/lib/gallery/gallery_page.dart +++ b/example/lib/gallery/gallery_page.dart @@ -39,6 +39,8 @@ class GalleryPage extends StatelessWidget { const SizedBox(height: 32), const RunningTextSection(), const SizedBox(height: 32), + const DpadsSection(), + const SizedBox(height: 32), const EffectsSection(), const SizedBox(height: 32), const LoadingIndicatorsSection(), diff --git a/example/lib/gallery/sections/dpads.dart b/example/lib/gallery/sections/dpads.dart new file mode 100644 index 0000000..e05f533 --- /dev/null +++ b/example/lib/gallery/sections/dpads.dart @@ -0,0 +1,60 @@ +import 'package:flutter/material.dart'; +import 'package:nes_ui/nes_ui.dart'; + +class DpadsSection extends StatelessWidget { + const DpadsSection({super.key}); + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Dpads', + style: theme.textTheme.displayMedium, + ), + const SizedBox(height: 16), + const ControllingDpad(), + ], + ); + } +} + +class ControllingDpad extends StatefulWidget { + const ControllingDpad({super.key}); + + @override + State createState() => _ControllingDpadState(); +} + +class _ControllingDpadState extends State { + NesDpadDirection? _direction; + + @override + Widget build(BuildContext context) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + NesDpad( + onButtonDown: (direction) { + setState(() { + _direction = direction; + }); + }, + onButtonUp: (direction) { + setState(() { + _direction = null; + }); + }, + ), + const SizedBox(height: 16), + Text( + 'Direction: ${_direction?.name ?? 'none'}', + ), + ], + ), + ); + } +} diff --git a/example/lib/gallery/sections/sections.dart b/example/lib/gallery/sections/sections.dart index 9946be5..4d4d1db 100644 --- a/example/lib/gallery/sections/sections.dart +++ b/example/lib/gallery/sections/sections.dart @@ -4,6 +4,7 @@ export 'checkboxes.dart'; export 'containers.dart'; export 'custom_extensions.dart'; export 'dialogs.dart'; +export 'dpads.dart'; export 'drop_shadows.dart'; export 'dropdown_menus.dart'; export 'effects.dart'; diff --git a/test/src/widgets/nes_dpad_test.dart b/test/src/widgets/nes_dpad_test.dart new file mode 100644 index 0000000..96d15fa --- /dev/null +++ b/test/src/widgets/nes_dpad_test.dart @@ -0,0 +1,22 @@ +// ignore_for_file: prefer_const_constructors + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:nes_ui/nes_ui.dart'; + +void main() { + group('NesContainer', () { + testWidgets('renders its child', (tester) async { + await tester.pumpWidget( + MaterialApp( + theme: flutterNesTheme(), + home: const NesDpad(), + ), + ); + + expect(find.byType(NesDpad), findsOneWidget); + // By default the dpad has 4 icons + expect(find.byType(NesIcon), findsNWidgets(4)); + }); + }); +}