From e34c7c4ca151d6ca5282176cdbbe8f9d1844c9ae Mon Sep 17 00:00:00 2001 From: unitexe Date: Thu, 19 Dec 2024 10:04:49 -0600 Subject: Initial application --- lib/playground_page.dart | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 lib/playground_page.dart (limited to 'lib/playground_page.dart') 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 createState() => _PlaygroundPageState(); +} + +class _PlaygroundPageState extends State { + 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: [ + 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), + ], + ), + ), + ), + ], + ); + } +} -- cgit v1.2.3