-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding example and a simple test
- Loading branch information
1 parent
b2cdcda
commit 51c74f4
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'}', | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
}); | ||
} |