bullseye/lib/main.dart

90 lines
2.6 KiB
Dart
Raw Normal View History

import 'package:flutter/cupertino.dart';
2021-04-28 06:07:43 -04:00
import 'package:flutter/material.dart';
2021-05-28 06:13:59 -04:00
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';
2021-05-28 06:13:59 -04:00
import 'package:bullseye/game_model.dart';
2021-04-28 06:07:43 -04:00
void main() => runApp(BullsEyeApp());
class BullsEyeApp extends StatelessWidget {
Brightness currentBrightness = Brightness.light;
2021-04-28 06:07:43 -04:00
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
return PlatformApp(
title: 'BullsEye',
// For some reason text is black in dark mode on iOS
cupertino: (_, __) => CupertinoAppData(
theme: CupertinoThemeData(brightness: Brightness.light)),
home: GamePage(title: 'BullsEye'));
2021-04-28 06:07:43 -04:00
}
}
class GamePage extends StatefulWidget {
2021-05-08 19:00:08 -04:00
GamePage({Key? key, this.title}) : super(key: key);
final String? title;
2021-04-28 06:07:43 -04:00
@override
_GamePageState createState() => _GamePageState();
}
class _GamePageState extends State<GamePage> {
2021-05-08 19:41:13 -04:00
bool _alertIsVisable = false;
2021-05-28 06:13:59 -04:00
GameModel _model = GameModel(50);
@override
void initState() {
super.initState();
_model = GameModel(50);
}
2021-05-08 19:41:13 -04:00
2021-04-28 06:07:43 -04:00
@override
Widget build(BuildContext context) {
return PlatformScaffold(
2021-04-28 06:07:43 -04:00
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
2021-05-28 06:13:59 -04:00
Prompt(targetValue: _model.target),
Control(model: _model),
PlatformTextButton(
child: PlatformText('Hit me!'),
2021-05-08 19:41:13 -04:00
onPressed: () {
this._alertIsVisable = true;
_showAlert(context);
}),
2021-05-28 06:13:59 -04:00
Score(totalScore: _model.totalScore, round: _model.round)
2021-04-28 06:07:43 -04:00
],
),
),
);
}
2021-05-08 19:41:13 -04:00
void _showAlert(BuildContext context) {
Widget okButton = PlatformTextButton(
child: PlatformText("Awesome!"),
2021-05-08 19:41:13 -04:00
onPressed: () {
Navigator.of(context).pop();
this._alertIsVisable = false;
print("Awesome Pressed! $_alertIsVisable");
});
showPlatformDialog(
2021-05-08 19:41:13 -04:00
context: context,
builder: (BuildContext context) {
return PlatformAlertDialog(
title: PlatformText("Hello There."),
content: PlatformText("The slider's value is ${_model.current}"),
2021-05-08 19:41:13 -04:00
actions: <Widget>[okButton],
);
});
}
2021-04-28 06:07:43 -04:00
}