Skip to content

Commit

Permalink
migrate to material3
Browse files Browse the repository at this point in the history
  • Loading branch information
Sciroccogti committed May 16, 2022
1 parent a11fcc8 commit 61ff111
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 111 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 10 additions & 4 deletions lib/drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_linkify/flutter_linkify.dart';

const themeColor = Colors.blue;
const primaryColor = Colors.indigo;
// const a = Colors.
const secondaryColor = Colors.indigoAccent;
String appName = "", version = ""; // from ./pubspec.yaml

class MyDrawer extends StatelessWidget {
Expand Down Expand Up @@ -33,7 +35,7 @@ class MyDrawer extends StatelessWidget {
children: [
DrawerHeader(
decoration: const BoxDecoration(
color: Colors.blue,
color: primaryColor,
),
child: Text(
appName,
Expand All @@ -52,15 +54,19 @@ class MyDrawer extends StatelessWidget {
),
ListTile(
leading: const Icon(
IconData(0xe61e, fontFamily: "iconfont"), color: Colors.red,),
IconData(0xe61e, fontFamily: "iconfont"),
color: Colors.red,
),
title: const Text('Snooker'),
onTap: () {
Navigator.pushNamed(context, '/snooker');
},
),
ListTile(
leading: const Icon(
IconData(0xe63a, fontFamily: "iconfont"), color: Colors.black,),
IconData(0xe63a, fontFamily: "iconfont"),
color: Colors.black,
),
title: const Text('Eight-ball'),
enabled: false,
onTap: () {
Expand Down
5 changes: 2 additions & 3 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,21 @@ class _HomeState extends State<HomePage> {
floatingActionButton:
Column(mainAxisAlignment: MainAxisAlignment.end, children: [
FloatingActionButton(
child: const Icon(Icons.delete),
onPressed: () => setState(() {
_count = 0;
}),
heroTag: null,
child: const Icon(Icons.delete),
),
const SizedBox(
height: 10,
),
FloatingActionButton(
child: const Icon(Icons.add),
// onPressed: () => _someFunc(),
onPressed: () => setState(() {
_count++;
}),
heroTag: null,
child: const Icon(Icons.add),
)
]));
}
Expand Down
3 changes: 2 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: appName, // used by the OS task switcher
theme: ThemeData(
primarySwatch: themeColor,
useMaterial3: true,
primarySwatch: primaryColor,
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
TargetPlatform.android: ZoomPageTransitionsBuilder(),
Expand Down
138 changes: 73 additions & 65 deletions lib/snooker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ import 'package:flutter_material_pickers/flutter_material_pickers.dart';
import 'package:material_segmented_control/material_segmented_control.dart';
import 'drawer.dart';

const scoreSize = Size(128, 1);

Icon getBallIcon(Color color) {
return Icon(
Icons.circle,
color: color,
size: 64,
shadows: const [
Shadow(
blurRadius: 15,
offset: Offset(0.0, 2.0),
color: Colors.grey,
)
],
);
}

class Snooker extends StatefulWidget {
Snooker({Key? key}) : super(key: key);

Expand All @@ -16,7 +33,7 @@ class _SnookerState extends State<Snooker> {
// var _lastScores_ = <int>[0, 0]; // TODO: return
static const Icon _playing = Icon(
IconData(0xe655, fontFamily: "iconfont"),
color: themeColor,
color: primaryColor,
);
static const Icon _waiting = Icon(
Icons.airline_seat_recline_normal_rounded,
Expand All @@ -38,18 +55,17 @@ class _SnookerState extends State<Snooker> {
children: const {
0: Text(
"Player1",
style: TextStyle(fontSize: 24),
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
1: Text(
"Player2",
style: TextStyle(fontSize: 24),
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
},
selectionIndex: _curPlayer,
borderColor: Colors.grey,
selectedColor: themeColor,
borderColor: Colors.black,
selectedColor: secondaryColor,
unselectedColor: Colors.white,
borderRadius: 16.0,
onSegmentChosen: (int index) {
setState(() {
_curPlayer = index;
Expand All @@ -64,6 +80,7 @@ class _SnookerState extends State<Snooker> {
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(
onPressed: () => showMaterialNumberPicker(
Expand All @@ -75,30 +92,35 @@ class _SnookerState extends State<Snooker> {
onChanged: (value) =>
setState(() => _scores_[0] = value),
),
style: ButtonStyle(
minimumSize: MaterialStateProperty.all(scoreSize),
),
child: Text(
"${_scores_[0]}",
style: const TextStyle(fontSize: 64),
)),
const Text(
":",
style: TextStyle(fontSize: 64, color: themeColor),
style: TextStyle(fontSize: 64, color: primaryColor),
),
TextButton(
onPressed: () => showMaterialNumberPicker(
context: context,
title: "Score of Player1",
title: "Score of Player2",
maxNumber: 147,
minNumber: 0,
selectedNumber: _scores_[1],
onChanged: (value) =>
setState(() => _scores_[1] = value),
),
style: ButtonStyle(
minimumSize: MaterialStateProperty.all(scoreSize),
),
child: Text(
"${_scores_[1]}",
style: const TextStyle(fontSize: 64),
)),
],
mainAxisAlignment: MainAxisAlignment.center,
),
Expanded(
child: GridView.count(
Expand All @@ -109,68 +131,47 @@ class _SnookerState extends State<Snooker> {
crossAxisCount: 3,
children: <Widget>[
IconButton(
onPressed: () => setState(() {
_scores_[_curPlayer]++;
}),
icon: const Icon(
Icons.circle,
color: Color(0xFFFF0000),
size: 64,
)),
onPressed: () => setState(() {
_scores_[_curPlayer]++;
}),
icon: getBallIcon(const Color(0xFFFF0000)),
),
IconButton(
onPressed: () => setState(() {
_scores_[_curPlayer] += 2;
}),
icon: const Icon(
Icons.circle,
color: Colors.yellow,
size: 64,
)),
onPressed: () => setState(() {
_scores_[_curPlayer] += 2;
}),
icon: getBallIcon(Colors.yellow),
),
IconButton(
onPressed: () => setState(() {
_scores_[_curPlayer] += 3;
}),
icon: const Icon(
Icons.circle,
color: Colors.green,
size: 64,
)),
onPressed: () => setState(() {
_scores_[_curPlayer] += 3;
}),
icon: getBallIcon(Colors.green),
),
IconButton(
onPressed: () => setState(() {
_scores_[_curPlayer] += 4;
}),
icon: const Icon(
Icons.circle,
color: Color(0xFFA52A2A),
size: 64,
)),
onPressed: () => setState(() {
_scores_[_curPlayer] += 4;
}),
icon: getBallIcon(const Color(0xFFA52A2A)),
),
IconButton(
onPressed: () => setState(() {
_scores_[_curPlayer] += 5;
}),
icon: const Icon(
Icons.circle,
color: Colors.blue,
size: 64,
)),
onPressed: () => setState(() {
_scores_[_curPlayer] += 5;
}),
icon: getBallIcon(Colors.blue),
),
IconButton(
onPressed: () => setState(() {
_scores_[_curPlayer] += 6;
}),
icon: const Icon(
Icons.circle,
color: Color(0xFFFF7FFF),
size: 64,
)),
onPressed: () => setState(() {
_scores_[_curPlayer] += 6;
}),
icon: getBallIcon(const Color(0xFFFF7FFF)),
),
IconButton(
onPressed: () => setState(() {
_scores_[_curPlayer] += 7;
}),
icon: const Icon(
Icons.circle,
color: Colors.black,
size: 64,
)),
onPressed: () => setState(() {
_scores_[_curPlayer] += 7;
}),
icon: getBallIcon(Colors.black),
),
IconButton(
onPressed: () => setState(() {
_scores_[1 - _curPlayer] += 4;
Expand All @@ -179,6 +180,13 @@ class _SnookerState extends State<Snooker> {
Icons.warning_rounded,
color: Colors.red,
size: 64,
shadows: [
Shadow(
blurRadius: 15,
offset: Offset(0.0, 2.0),
color: Colors.grey,
)
],
),
tooltip: "罚 4 分",
),
Expand Down
Loading

0 comments on commit 61ff111

Please sign in to comment.