diff options
| author | unitexe <unitexe70@gmail.com> | 2024-12-19 10:04:49 -0600 |
|---|---|---|
| committer | unitexe <unitexe70@gmail.com> | 2024-12-19 10:04:49 -0600 |
| commit | e34c7c4ca151d6ca5282176cdbbe8f9d1844c9ae (patch) | |
| tree | f063f2dd9261969778bd0ca84bd037879ca0ce7a /lib/playground_page.dart | |
| parent | 5d7c87a5c3d3dfa3e5cf78f13b85265dc4130fd0 (diff) | |
Diffstat (limited to 'lib/playground_page.dart')
| -rw-r--r-- | lib/playground_page.dart | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/lib/playground_page.dart b/lib/playground_page.dart new file mode 100644 index 0000000..3c090ac --- /dev/null +++ b/lib/playground_page.dart @@ -0,0 +1,73 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/widgets.dart'; +import 'app_bar.dart'; +import 'button.dart'; +import 'value_display.dart'; + +class PlaygroundPage extends StatefulWidget { + const PlaygroundPage({super.key}); + + @override + State<PlaygroundPage> createState() => _PlaygroundPageState(); +} + +class _PlaygroundPageState extends State<PlaygroundPage> { + int _counter = 0; + int _elapsedMilliseconds = 0; + final stopwatch = Stopwatch(); + + void increment() { + setState(() { + ++_counter; + if (stopwatch.isRunning) { + stopwatch.stop(); + _elapsedMilliseconds = stopwatch.elapsedMilliseconds; + stopwatch.reset(); + } + else { + stopwatch.start(); + _elapsedMilliseconds = 0; + } + }); + } + + void clear() { + setState(() { + if (stopwatch.isRunning) { + return; + } + _counter = 0; + _elapsedMilliseconds = 0; + }); + } + + @override + Widget build(BuildContext context) { + return Column( + children: [ + const AppBar(), + Expanded( + child: Center( + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: <Widget> [ + Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Button(onPressed: increment, buttonText: 'Increment'), + const SizedBox(height: 8), + Button(onPressed: clear, buttonText: 'Clear'), + ], + ), + const SizedBox(width: 16), + ValueDisplay(label: 'Count', value: _counter), + const SizedBox(width: 16), + ValueDisplay(label: 'Elapsed (ms)', value: _elapsedMilliseconds), + ], + ), + ), + ), + ], + ); + } +} |
