Skip to content

Commit

Permalink
feat: adding example and a simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzanardo committed Feb 2, 2025
1 parent b2cdcda commit 51c74f4
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
2 changes: 2 additions & 0 deletions example/lib/gallery/gallery_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
60 changes: 60 additions & 0 deletions example/lib/gallery/sections/dpads.dart
Original file line number Diff line number Diff line change
@@ -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<ControllingDpad> {
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'}',
),
],
),
);
}
}
1 change: 1 addition & 0 deletions example/lib/gallery/sections/sections.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
22 changes: 22 additions & 0 deletions test/src/widgets/nes_dpad_test.dart
Original file line number Diff line number Diff line change
@@ -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));
});
});
}

0 comments on commit 51c74f4

Please sign in to comment.