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 | |
| parent | 5d7c87a5c3d3dfa3e5cf78f13b85265dc4130fd0 (diff) | |
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/app_bar.dart | 32 | ||||
| -rw-r--r-- | lib/button.dart | 23 | ||||
| -rw-r--r-- | lib/error_page.dart | 14 | ||||
| -rw-r--r-- | lib/home_page.dart | 22 | ||||
| -rw-r--r-- | lib/main.dart | 49 | ||||
| -rw-r--r-- | lib/playground_page.dart | 73 | ||||
| -rw-r--r-- | lib/value_display.dart | 13 |
7 files changed, 226 insertions, 0 deletions
diff --git a/lib/app_bar.dart b/lib/app_bar.dart new file mode 100644 index 0000000..507d55c --- /dev/null +++ b/lib/app_bar.dart @@ -0,0 +1,32 @@ +import 'package:flutter/widgets.dart'; +import 'button.dart'; + +class AppBar extends StatefulWidget { + const AppBar({super.key}); + + @override + State<AppBar> createState() => _AppBarState(); +} + +class _AppBarState extends State<AppBar> { + @override + Widget build(BuildContext context) { + return Container( + decoration: BoxDecoration( + border: Border.all(width: 2, color: const Color(0xFFFFFF00)), + borderRadius: const BorderRadius.all(Radius.circular(8)), + ), + child: Container( + margin: const EdgeInsets.all(8), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Button(onPressed: () => Navigator.of(context).pushNamed('/'), buttonText: 'Home'), + const SizedBox(width: 16), + Button(onPressed: () => Navigator.of(context).pushNamed("/playground"), buttonText: 'Playground'), + ] + ), + ) + ); + } +}
\ No newline at end of file diff --git a/lib/button.dart b/lib/button.dart new file mode 100644 index 0000000..2c51cf6 --- /dev/null +++ b/lib/button.dart @@ -0,0 +1,23 @@ +import 'package:flutter/widgets.dart'; + +class Button extends StatelessWidget { + const Button({required this.onPressed, required this.buttonText, super.key}); + + final VoidCallback onPressed; + final String buttonText; + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: onPressed, + child: Container( + decoration: BoxDecoration( + border: Border.all(width: 2, color: const Color(0xFFFFFF00)), + borderRadius: const BorderRadius.all(Radius.circular(8)), + ), + padding: const EdgeInsets.all(8), + child: Text(buttonText, style: const TextStyle(color: Color(0xFFFFFF00))), + ) + ); + } +}
\ No newline at end of file diff --git a/lib/error_page.dart b/lib/error_page.dart new file mode 100644 index 0000000..d7d0e11 --- /dev/null +++ b/lib/error_page.dart @@ -0,0 +1,14 @@ +import 'package:flutter/widgets.dart'; + +class ErrorPage extends StatelessWidget { + const ErrorPage({super.key}); + + @override + Widget build(BuildContext context) { + return const Center( + child: Text( + 'Error', + style: TextStyle(color: Color(0xFFFFFF00))), + ); + } +} diff --git a/lib/home_page.dart b/lib/home_page.dart new file mode 100644 index 0000000..83346c4 --- /dev/null +++ b/lib/home_page.dart @@ -0,0 +1,22 @@ +import 'package:flutter/widgets.dart'; +import 'app_bar.dart'; + +class HomePage extends StatelessWidget { + const HomePage({super.key}); + + @override + Widget build(BuildContext context) { + return const Column( + children: [ + AppBar(), + Expanded( + child: Center( + child: Text( + 'Home', + style: TextStyle(color: Color(0xFFFFFF00))), + ), + ), + ], + ); + } +} diff --git a/lib/main.dart b/lib/main.dart new file mode 100644 index 0000000..9d2f0d1 --- /dev/null +++ b/lib/main.dart @@ -0,0 +1,49 @@ +import 'package:flutter/widgets.dart'; +import 'playground_page.dart'; +import 'home_page.dart'; +import 'error_page.dart'; + +void main() => runApp(const MinimalApp()); + +PageRouteBuilder unknownRoute(RouteSettings settings) { + return PageRouteBuilder( + pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) { + return const ErrorPage(); + } + ); +} + +class MinimalApp extends StatelessWidget { + const MinimalApp({super.key}); + + Route generate(RouteSettings settings) { + switch (settings.name) { + case '/': + return PageRouteBuilder( + pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) { + return const HomePage(); + }, + ); + case '/playground': + return PageRouteBuilder( + pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) { + return const PlaygroundPage(); + } + ); + default: + return unknownRoute(settings); + } + } + + @override + Widget build(BuildContext context) { + return WidgetsApp( + color: const Color(0xFFFFFFFF), + title: 'Minimal', + debugShowCheckedModeBanner: false, + textStyle: const TextStyle(color: Color(0xFFFFFF00)), + onGenerateRoute: generate, + onUnknownRoute: unknownRoute, + ); + } +} 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), + ], + ), + ), + ), + ], + ); + } +} diff --git a/lib/value_display.dart b/lib/value_display.dart new file mode 100644 index 0000000..44f58fe --- /dev/null +++ b/lib/value_display.dart @@ -0,0 +1,13 @@ +import 'package:flutter/widgets.dart'; + +class ValueDisplay extends StatelessWidget { + const ValueDisplay({required this.label, required this.value, super.key}); + + final String label; + final int value; + + @override + Widget build(BuildContext context) { + return Text('$label: $value'); + } +}
\ No newline at end of file |
