diff --git a/lib/control.dart b/lib/control.dart index 1fd8691..334bd7b 100644 --- a/lib/control.dart +++ b/lib/control.dart @@ -1,34 +1,45 @@ +import 'package:bullseye/game_model.dart'; import 'package:flutter/material.dart'; import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'; class Control extends StatefulWidget { - Control({Key? key}) : super(key: key); + Control({Key? key, @required this.model}) : super(key: key); + final GameModel? model; @override State createState() => _ControlState(); } class _ControlState extends State { - double _currentValue = 50.0; + static const double PADDING = 45; @override Widget build(BuildContext context) { + var currentValue = widget.model?.current; + return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - PlatformText("1"), - PlatformSlider( - value: _currentValue, - onChanged: (newValue) { - setState(() { - _currentValue = newValue; - print(_currentValue); - }); - }, - min: 1.0, - max: 100.0, + Padding( + padding: const EdgeInsets.all(PADDING), + child: PlatformText("1"), ), - PlatformText("100") + Expanded( + child: PlatformSlider( + value: currentValue!.toDouble(), + onChanged: (newValue) { + setState(() { + widget.model!.current = newValue.toInt(); + }); + }, + min: 1.0, + max: 100.0, + ), + ), + Padding( + padding: const EdgeInsets.all(PADDING), + child: PlatformText("100"), + ) ], ); } diff --git a/lib/game_model.dart b/lib/game_model.dart new file mode 100644 index 0000000..446d398 --- /dev/null +++ b/lib/game_model.dart @@ -0,0 +1,15 @@ +class GameModel { + static const SLIDER_CONST = 50; + static const SCORE_START = 0; + static const ROUND_START = 0; + + GameModel(this.target, + [this.current = SLIDER_CONST, + this.totalScore = SCORE_START, + this.round = ROUND_START]); + + int? target; + int? current; + int? totalScore; + int? round; +} diff --git a/lib/main.dart b/lib/main.dart index 015336b..72a11cc 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,9 +1,11 @@ import 'package:flutter/material.dart'; +import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'; + import 'package:flutter/services.dart'; import 'package:bullseye/prompt.dart'; import 'package:bullseye/control.dart'; import 'package:bullseye/score.dart'; -import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'; +import 'package:bullseye/game_model.dart'; void main() => runApp(BullsEyeApp()); @@ -33,6 +35,13 @@ class GamePage extends StatefulWidget { class _GamePageState extends State { bool _alertIsVisable = false; + GameModel _model = GameModel(50); + + @override + void initState() { + super.initState(); + _model = GameModel(50); + } @override Widget build(BuildContext context) { @@ -41,15 +50,15 @@ class _GamePageState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Prompt(targetValue: 100), - Control(), + Prompt(targetValue: _model.target), + Control(model: _model), PlatformTextButton( child: PlatformText('Hit me!'), onPressed: () { this._alertIsVisable = true; _showAlert(context); }), - Score() + Score(totalScore: _model.totalScore, round: _model.round) ], ), ), diff --git a/lib/score.dart b/lib/score.dart index 259437e..c8f634a 100644 --- a/lib/score.dart +++ b/lib/score.dart @@ -2,19 +2,39 @@ import 'package:flutter/material.dart'; import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'; class Score extends StatelessWidget { + Score({Key? key, @required this.totalScore, @required this.round}) + : super(key: key); + + final int? totalScore; + final int? round; + @override Widget build(BuildContext context) { return Row( mainAxisAlignment: MainAxisAlignment.center, - children: [ + children: [ PlatformButton( child: PlatformText("Start Over"), onPressed: () {}, ), - PlatformText("Score:"), - PlatformText("999"), - PlatformText("Round:"), - PlatformText("999"), + Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + children: [ + PlatformText("Score:"), + PlatformText("$totalScore"), + ], + ), + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + children: [ + PlatformText("Round:"), + PlatformText("$round"), + ], + ), + ), PlatformButton( child: PlatformText("Info"), onPressed: () {},