2021-05-29 12:01:35 -04:00
|
|
|
import 'dart:math';
|
|
|
|
import 'package:bitsdojo_window/bitsdojo_window.dart';
|
|
|
|
import 'package:bullseye/desktop.dart';
|
|
|
|
|
2021-04-28 06:07:43 -04:00
|
|
|
import 'package:flutter/material.dart';
|
2021-05-28 06:13:59 -04:00
|
|
|
|
2021-05-28 04:59:28 -04:00
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:bullseye/prompt.dart';
|
|
|
|
import 'package:bullseye/control.dart';
|
2021-05-28 05:34:28 -04:00
|
|
|
import 'package:bullseye/score.dart';
|
2021-05-28 06:13:59 -04:00
|
|
|
import 'package:bullseye/game_model.dart';
|
2021-05-29 12:01:35 -04:00
|
|
|
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
2021-04-28 06:07:43 -04:00
|
|
|
|
2021-05-29 12:01:35 -04:00
|
|
|
const gameTitle = "Bullseye";
|
2021-04-28 06:07:43 -04:00
|
|
|
|
2021-05-29 12:01:35 -04:00
|
|
|
void main() {
|
|
|
|
runApp(BullsEyeApp());
|
|
|
|
|
|
|
|
if (isDesktop) {
|
|
|
|
doWhenWindowReady(() {
|
|
|
|
final win = appWindow;
|
|
|
|
final minSize = Size(600, 450);
|
|
|
|
|
|
|
|
win.minSize = minSize;
|
|
|
|
win.size = minSize;
|
|
|
|
win.alignment = Alignment.center;
|
|
|
|
win.title = gameTitle;
|
|
|
|
|
|
|
|
win.show();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-05-28 07:00:08 -04:00
|
|
|
|
2021-05-29 12:01:35 -04:00
|
|
|
class BullsEyeApp extends StatelessWidget {
|
2021-04-28 06:07:43 -04:00
|
|
|
// This widget is the root of your application.
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-05-28 04:59:28 -04:00
|
|
|
SystemChrome.setPreferredOrientations(
|
|
|
|
[DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
|
2021-05-28 07:00:08 -04:00
|
|
|
return PlatformApp(
|
2021-05-29 12:01:35 -04:00
|
|
|
title: gameTitle,
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
home: GamePage(title: gameTitle));
|
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-29 12:01:35 -04:00
|
|
|
late GameModel _model;
|
2021-05-28 06:13:59 -04:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2021-05-29 12:01:35 -04:00
|
|
|
var rng = Random();
|
|
|
|
_model = GameModel(rng.nextInt(100) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget gameContainer() {
|
|
|
|
return Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Prompt(targetValue: _model.target),
|
|
|
|
Control(model: _model),
|
|
|
|
PlatformTextButton(
|
|
|
|
child: PlatformText('Hit me!'),
|
|
|
|
onPressed: () {
|
|
|
|
this._alertIsVisable = true;
|
|
|
|
_showAlert(context);
|
|
|
|
})
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget mobileContainer() {
|
|
|
|
return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
|
|
|
|
gameContainer(),
|
|
|
|
Score(totalScore: _model.totalScore, round: _model.round)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget desktopContainer() {
|
|
|
|
return Column(children: [
|
|
|
|
Container(
|
|
|
|
height: 50,
|
|
|
|
child: WindowTitleBarBox(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: MoveWindow(
|
|
|
|
child: Score(
|
|
|
|
totalScore: _model.totalScore, round: _model.round)))
|
|
|
|
],
|
|
|
|
))),
|
|
|
|
Expanded(child: gameContainer()),
|
|
|
|
]);
|
2021-05-28 06:13:59 -04:00
|
|
|
}
|
2021-05-08 19:41:13 -04:00
|
|
|
|
2021-04-28 06:07:43 -04:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-05-29 12:01:35 -04:00
|
|
|
return Scaffold(
|
|
|
|
body: LayoutBuilder(builder: (context, constraints) {
|
|
|
|
if (isDesktop)
|
|
|
|
return desktopContainer();
|
|
|
|
else
|
|
|
|
return mobileContainer();
|
|
|
|
}),
|
2021-04-28 06:07:43 -04:00
|
|
|
);
|
|
|
|
}
|
2021-05-08 19:41:13 -04:00
|
|
|
|
|
|
|
void _showAlert(BuildContext context) {
|
2021-05-29 12:01:35 -04:00
|
|
|
var okButton = PlatformTextButton(
|
2021-05-28 05:34:28 -04:00
|
|
|
child: PlatformText("Awesome!"),
|
2021-05-08 19:41:13 -04:00
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
this._alertIsVisable = false;
|
|
|
|
print("Awesome Pressed! $_alertIsVisable");
|
|
|
|
});
|
|
|
|
|
2021-05-28 07:00:08 -04:00
|
|
|
showPlatformDialog(
|
2021-05-08 19:41:13 -04:00
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
2021-05-28 05:34:28 -04:00
|
|
|
return PlatformAlertDialog(
|
2021-05-28 06:20:13 -04:00
|
|
|
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
|
|
|
}
|