mirror of
https://github.com/tonytins/bullseye.git
synced 2025-08-14 06:34:43 -04:00
Adpative layout
- The desktop version has the score, ect, in the title bar area now while the mobile version remains the same - Capitalized "bullseye" - Used "late" keyword for certain variables - Updated application Id
This commit is contained in:
parent
964e861450
commit
593fda0975
22 changed files with 154 additions and 68 deletions
20
lib/desktop.dart
Normal file
20
lib/desktop.dart
Normal file
|
@ -0,0 +1,20 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:bitsdojo_window/bitsdojo_window.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
bool get isDesktop =>
|
||||
(Platform.isLinux || Platform.isMacOS || Platform.isWindows);
|
||||
|
||||
class WindowButtons extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
MinimizeWindowButton(),
|
||||
MaximizeWindowButton(),
|
||||
CloseWindowButton()
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -8,8 +8,8 @@ class GameModel {
|
|||
this.totalScore = SCORE_START,
|
||||
this.round = ROUND_START]);
|
||||
|
||||
int? target;
|
||||
int? current;
|
||||
int? totalScore;
|
||||
int? round;
|
||||
late int target;
|
||||
late int current;
|
||||
late int totalScore;
|
||||
late int round;
|
||||
}
|
||||
|
|
108
lib/main.dart
108
lib/main.dart
|
@ -1,29 +1,46 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'dart:math';
|
||||
import 'package:bitsdojo_window/bitsdojo_window.dart';
|
||||
import 'package:bullseye/desktop.dart';
|
||||
|
||||
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:bullseye/game_model.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
|
||||
void main() => runApp(BullsEyeApp());
|
||||
const gameTitle = "Bullseye";
|
||||
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class BullsEyeApp extends StatelessWidget {
|
||||
Brightness currentBrightness = Brightness.light;
|
||||
|
||||
// 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'));
|
||||
title: gameTitle,
|
||||
debugShowCheckedModeBanner: false,
|
||||
home: GamePage(title: gameTitle));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,38 +54,69 @@ class GamePage extends StatefulWidget {
|
|||
|
||||
class _GamePageState extends State<GamePage> {
|
||||
bool _alertIsVisable = false;
|
||||
GameModel _model = GameModel(50);
|
||||
late GameModel _model;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_model = GameModel(50);
|
||||
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()),
|
||||
]);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PlatformScaffold(
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Prompt(targetValue: _model.target),
|
||||
Control(model: _model),
|
||||
PlatformTextButton(
|
||||
child: PlatformText('Hit me!'),
|
||||
onPressed: () {
|
||||
this._alertIsVisable = true;
|
||||
_showAlert(context);
|
||||
}),
|
||||
Score(totalScore: _model.totalScore, round: _model.round)
|
||||
],
|
||||
),
|
||||
),
|
||||
return Scaffold(
|
||||
body: LayoutBuilder(builder: (context, constraints) {
|
||||
if (isDesktop)
|
||||
return desktopContainer();
|
||||
else
|
||||
return mobileContainer();
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
void _showAlert(BuildContext context) {
|
||||
Widget okButton = PlatformTextButton(
|
||||
var okButton = PlatformTextButton(
|
||||
child: PlatformText("Awesome!"),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
|
|
|
@ -13,7 +13,7 @@ class Score extends StatelessWidget {
|
|||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
PlatformButton(
|
||||
PlatformTextButton(
|
||||
child: PlatformText("Start Over"),
|
||||
onPressed: () {},
|
||||
),
|
||||
|
@ -35,7 +35,7 @@ class Score extends StatelessWidget {
|
|||
],
|
||||
),
|
||||
),
|
||||
PlatformButton(
|
||||
PlatformTextButton(
|
||||
child: PlatformText("Info"),
|
||||
onPressed: () {},
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue