flutter: refactor class ColorConst

This commit is contained in:
Calcitem 2020-11-07 00:46:39 +08:00
parent 9307cf474e
commit 8479487295
10 changed files with 112 additions and 94 deletions

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import '../board/painter-base.dart';
import '../common/color-consts.dart';
import 'board-widget.dart';
@ -15,8 +16,8 @@ class BoardPainter extends PainterBase {
thePaint,
gridWidth,
squareSide,
offsetX: BoardWidget.Padding + squareSide / 2,
offsetY: BoardWidget.Padding + BoardWidget.DigitsHeight + squareSide / 2,
offsetX: BoardWidget.padding + squareSide / 2,
offsetY: BoardWidget.padding + BoardWidget.digitsHeight + squareSide / 2,
);
}
@ -34,7 +35,7 @@ class BoardPainter extends PainterBase {
double offsetY,
}) {
//
paint.color = ColorConsts.BoardLine;
paint.color = ColorConst.boardLineColor;
paint.style = PaintingStyle.stroke;
var left = offsetX;

View File

@ -1,15 +1,18 @@
import '../game/battle.dart';
import 'package:flutter/material.dart';
import '../common/color-consts.dart';
import '../game/battle.dart';
import 'board-painter.dart';
import 'pieces-painter.dart';
import 'words-on-board.dart';
class BoardWidget extends StatelessWidget {
//
static const Padding = 5.0, DigitsHeight = 0.0;
static const padding = 5.0;
static const digitsHeight = 0.0;
final double width, height;
final double width;
final double height;
final Function(BuildContext, int) onBoardTap;
BoardWidget({@required this.width, @required this.onBoardTap})
@ -23,7 +26,7 @@ class BoardWidget extends StatelessWidget {
height: height,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: ColorConsts.BoardBackground,
color: ColorConst.boardBackgroundColor,
),
child: CustomPaint(
painter: BoardPainter(width: width),
@ -35,9 +38,9 @@ class BoardWidget extends StatelessWidget {
),
child: Container(
margin: EdgeInsets.symmetric(
vertical: Padding,
horizontal: (width - Padding * 2) / 7 / 2 +
Padding -
vertical: padding,
horizontal: (width - padding * 2) / 7 / 2 +
padding -
WordsOnBoard.DigitsFontSize / 2,
),
//child: WordsOnBoard(),
@ -49,14 +52,15 @@ class BoardWidget extends StatelessWidget {
child: boardContainer,
onTapUp: (d) {
//
final gridWidth = (width - Padding * 2) * 6 / 7;
final gridWidth = (width - padding * 2) * 6 / 7;
final squareSide = gridWidth / 8;
final dx = d.localPosition.dx, dy = d.localPosition.dy;
final row = (dy - Padding - DigitsHeight) ~/ squareSide;
final column = (dx - Padding) ~/ squareSide;
final row = (dy - padding - digitsHeight) ~/ squareSide;
final column = (dx - padding) ~/ squareSide;
if (row < 0 || row > 6) return;
if (column < 0 || column > 6) return;
onBoardTap(context, row * 7 + column);

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'board-widget.dart';
abstract class PainterBase extends CustomPainter {
@ -9,6 +10,6 @@ abstract class PainterBase extends CustomPainter {
final gridWidth, squareSide;
PainterBase({@required this.width})
: gridWidth = (width - BoardWidget.Padding * 2) ,
squareSide = (width - BoardWidget.Padding * 2) / 7;
: gridWidth = (width - BoardWidget.padding * 2),
squareSide = (width - BoardWidget.padding * 2) / 7;
}

View File

@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import '../mill/mill-base.dart';
import '../common/color-consts.dart';
import '../board/painter-base.dart';
import '../common/color-consts.dart';
import '../mill/mill-base.dart';
import '../mill/position.dart';
import 'board-widget.dart';
@ -39,8 +40,8 @@ class PiecesPainter extends PainterBase {
squareSide: squareSide,
pieceSide: pieceSide,
// 线
offsetX: BoardWidget.Padding + squareSide / 2,
offsetY: BoardWidget.Padding + BoardWidget.DigitsHeight + squareSide / 2,
offsetX: BoardWidget.padding + squareSide / 2,
offsetY: BoardWidget.padding + BoardWidget.digitsHeight + squareSide / 2,
focusIndex: focusIndex,
blurIndex: blurIndex,
);
@ -106,15 +107,15 @@ class PiecesPainter extends PainterBase {
piecesToDraw.forEach((pps) {
//
paint.color = Piece.isWhite(pps.piece)
? ColorConsts.WhitePieceBorderColor
: ColorConsts.BlackPieceBorderColor;
? ColorConst.whitePieceBorderColor
: ColorConst.blackPieceBorderColor;
canvas.drawCircle(pps.pos, pieceSide / 2, paint); //
//
paint.color = Piece.isWhite(pps.piece)
? ColorConsts.WhitePieceColor
: ColorConsts.BlackPieceColor;
? ColorConst.whitePieceColor
: ColorConst.blackPieceColor;
//paint.color = ColorConsts.WhitePieceColor;
canvas.drawCircle(pps.pos, pieceSide * 0.8 / 2, paint); //
@ -143,7 +144,7 @@ class PiecesPainter extends PainterBase {
//
final int row = focusIndex ~/ 7, column = focusIndex % 7;
paint.color = ColorConsts.FocusPosition;
paint.color = ColorConst.focusPositionColor;
paint.style = PaintingStyle.stroke;
paint.strokeWidth = 2;
@ -158,7 +159,7 @@ class PiecesPainter extends PainterBase {
//
final row = blurIndex ~/ 7, column = blurIndex % 7;
paint.color = ColorConsts.BlurPosition;
paint.color = ColorConst.blurPositionColor;
paint.style = PaintingStyle.fill;
canvas.drawCircle(

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import '../common/color-consts.dart';
class WordsOnBoard extends StatelessWidget {
@ -25,7 +26,7 @@ class WordsOnBoard extends StatelessWidget {
Row(children: rChildren),
],
),
style: TextStyle(color: ColorConsts.BoardTips),
style: TextStyle(color: ColorConst.boardTipsColor),
);
}
}

View File

@ -1,33 +1,33 @@
import 'package:flutter/material.dart';
class ColorConsts {
class ColorConst {
//
static const LogoColor = Color(0xFF6D000D);
static const logoColor = Color(0xFF6D000D);
static const Primary = Color(0xFF461220);
static const Secondary = Color(0x99461220);
static const primaryColor = Color(0xFF461220);
static const secondaryColor = Color(0x99461220);
static const DarkBackground = Colors.brown;
static const LightBackground = Color(0xFFEEE0CB);
static const darkBackgroundColor = Colors.brown;
static const lightBackgroundColor = Color(0xFFEEE0CB);
static const BoardBackground = Color(0xFFEBC38D);
static const boardBackgroundColor = Color(0xFFEBC38D);
static const DarkTextPrimary = Colors.white;
static const DarkTextSecondary = Color(0x99FFFFFF);
static const darkTextPrimaryColor = Colors.white;
static const darkTextSecondaryColor = Color(0x99FFFFFF);
static const BoardLine = Color(0x996D000D);
static const BoardTips = Color(0x666D000D);
static const boardLineColor = Color(0x996D000D);
static const boardTipsColor = Color(0x666D000D);
static const LightLine = Color(0x336D000D);
static const lightLineColor = Color(0x336D000D);
static const FocusPosition = Color(0x99FFFFFF);
static const BlurPosition = Color(0x99FFFFFF);
static const focusPositionColor = Color(0x99FFFFFF);
static const blurPositionColor = Color(0x99FFFFFF);
static const BlackPieceColor = Color.fromARGB(0xFF, 0x00, 0x00, 0x00);
static const BlackPieceBorderColor = Color.fromARGB(0xFF, 0x22, 0x22, 0x22);
static const blackPieceColor = Color.fromARGB(0xFF, 0x00, 0x00, 0x00);
static const blackPieceBorderColor = Color.fromARGB(0xFF, 0x22, 0x22, 0x22);
static const WhitePieceColor = Color.fromARGB(0xFF, 0xFF, 0xFF, 0xFF);
static const WhitePieceBorderColor = Color.fromARGB(0xFF, 0x66, 0x00, 0x00);
static const whitePieceColor = Color.fromARGB(0xFF, 0xFF, 0xFF, 0xFF);
static const whitePieceBorderColor = Color.fromARGB(0xFF, 0x66, 0x00, 0x00);
static const PieceTextColor = Color.fromARGB(0xCC, 0xFF, 0xFF, 0xFF);
static const pieceTextColor = Color.fromARGB(0xCC, 0xFF, 0xFF, 0xFF);
}

View File

@ -1,15 +1,15 @@
import '../mill/mill-base.dart';
import 'package:flutter/material.dart';
import '../board/board-widget.dart';
import '../common/color-consts.dart';
import '../common/toast.dart';
import '../engine/analysis.dart';
import '../engine/engine.dart';
import '../engine/native-engine.dart';
//import '../services/audios.dart';
import '../services/player.dart';
import 'package:flutter/material.dart';
import '../game/battle.dart';
import '../board/board-widget.dart';
import '../main.dart';
import '../mill/mill-base.dart';
import '../services/player.dart';
import 'settings-page.dart';
class BattlePage extends StatefulWidget {
@ -140,7 +140,8 @@ class _BattlePageState extends State<BattlePage> {
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('放弃对局?', style: TextStyle(color: ColorConsts.Primary)),
title:
Text('放弃对局?', style: TextStyle(color: ColorConst.primaryColor)),
content: SingleChildScrollView(child: Text('你确定要放弃当前的对局吗?')),
actions: <Widget>[
FlatButton(child: Text('确定'), onPressed: confirm),
@ -206,7 +207,7 @@ class _BattlePageState extends State<BattlePage> {
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text('赢了', style: TextStyle(color: ColorConsts.Primary)),
title: Text('赢了', style: TextStyle(color: ColorConst.primaryColor)),
content: Text('恭喜您取得了伟大的胜利!'),
actions: <Widget>[
FlatButton(child: Text('再来一盘'), onPressed: newGame),
@ -234,7 +235,7 @@ class _BattlePageState extends State<BattlePage> {
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text('输了', style: TextStyle(color: ColorConsts.Primary)),
title: Text('输了', style: TextStyle(color: ColorConst.primaryColor)),
content: Text('勇士!坚定战斗,虽败犹荣!'),
actions: <Widget>[
FlatButton(child: Text('再来一盘'), onPressed: newGame),
@ -256,7 +257,7 @@ class _BattlePageState extends State<BattlePage> {
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text('<EFBFBD><EFBFBD><EFBFBD>', style: TextStyle(color: ColorConsts.Primary)),
title: Text('<EFBFBD><EFBFBD><EFBFBD>', style: TextStyle(color: ColorConst.primaryColor)),
content: Text('您用自己的力量捍卫了和平!'),
actions: <Widget>[
FlatButton(child: Text('再来一盘'), onPressed: newGame),
@ -285,9 +286,9 @@ class _BattlePageState extends State<BattlePage> {
Widget createPageHeader() {
//
final titleStyle =
TextStyle(fontSize: 28, color: ColorConsts.DarkTextPrimary);
TextStyle(fontSize: 28, color: ColorConst.darkTextPrimaryColor);
final subTitleStyle =
TextStyle(fontSize: 16, color: ColorConsts.DarkTextSecondary);
TextStyle(fontSize: 16, color: ColorConst.darkTextSecondaryColor);
return Container(
margin: EdgeInsets.only(top: SanmillApp.StatusBarHeight),
@ -296,8 +297,8 @@ class _BattlePageState extends State<BattlePage> {
Row(
children: <Widget>[
IconButton(
icon:
Icon(Icons.arrow_back, color: ColorConsts.DarkTextPrimary),
icon: Icon(Icons.arrow_back,
color: ColorConst.darkTextPrimaryColor),
onPressed: () => Navigator.of(context).pop(),
),
Expanded(child: SizedBox()),
@ -307,7 +308,8 @@ class _BattlePageState extends State<BattlePage> {
style: titleStyle),
Expanded(child: SizedBox()),
IconButton(
icon: Icon(Icons.settings, color: ColorConsts.DarkTextPrimary),
icon: Icon(Icons.settings,
color: ColorConst.darkTextPrimaryColor),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(builder: (context) => SettingsPage()),
),
@ -319,7 +321,7 @@ class _BattlePageState extends State<BattlePage> {
width: 180,
margin: EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
color: ColorConsts.BoardBackground,
color: ColorConst.boardBackgroundColor,
borderRadius: BorderRadius.circular(2),
),
),
@ -349,12 +351,12 @@ class _BattlePageState extends State<BattlePage> {
Widget createOperatorBar() {
//
final buttonStyle = TextStyle(color: ColorConsts.Primary, fontSize: 20);
final buttonStyle = TextStyle(color: ColorConst.primaryColor, fontSize: 20);
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: ColorConsts.BoardBackground,
color: ColorConst.boardBackgroundColor,
),
margin: EdgeInsets.symmetric(horizontal: BattlePage.screenPaddingH),
padding: EdgeInsets.symmetric(vertical: 2),
@ -396,7 +398,7 @@ class _BattlePageState extends State<BattlePage> {
//
final manualStyle = TextStyle(
fontSize: 18,
color: ColorConsts.DarkTextSecondary,
color: ColorConst.darkTextSecondaryColor,
height: 1.5,
);
@ -414,13 +416,14 @@ class _BattlePageState extends State<BattlePage> {
return Expanded(
child: IconButton(
icon: Icon(Icons.expand_less, color: ColorConsts.DarkTextPrimary),
icon: Icon(Icons.expand_less, color: ColorConst.darkTextPrimaryColor),
onPressed: () => showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text('棋谱', style: TextStyle(color: ColorConsts.Primary)),
title:
Text('棋谱', style: TextStyle(color: ColorConst.primaryColor)),
content:
SingleChildScrollView(child: Text(text, style: manualStyle)),
actions: <Widget>[
@ -447,7 +450,7 @@ class _BattlePageState extends State<BattlePage> {
final footer = buildFooter();
return Scaffold(
backgroundColor: ColorConsts.DarkBackground,
backgroundColor: ColorConst.darkBackgroundColor,
body: Column(children: <Widget>[header, board, operatorBar, footer]),
);
}

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import '../common/color-consts.dart';
class EditPage extends StatefulWidget {
@ -38,7 +39,7 @@ class _EditPageState extends State<EditPage> {
//
final inputBorder = OutlineInputBorder(
borderRadius: BorderRadius.circular(25),
borderSide: BorderSide(color: ColorConsts.Secondary),
borderSide: BorderSide(color: ColorConst.secondaryColor),
);
return Scaffold(
@ -46,12 +47,13 @@ class _EditPageState extends State<EditPage> {
title: Text(widget.title, style: TextStyle(fontFamily: '')),
actions: <Widget>[
FlatButton(
child: Text('确定', style: TextStyle(fontFamily: '', color: Colors.white)),
child: Text('确定',
style: TextStyle(fontFamily: '', color: Colors.white)),
onPressed: () => onSubmit(_textController.text),
)
],
),
backgroundColor: ColorConsts.LightBackground,
backgroundColor: ColorConst.lightBackgroundColor,
body: Container(
margin: EdgeInsets.all(16),
child: Column(
@ -59,11 +61,13 @@ class _EditPageState extends State<EditPage> {
TextField(
controller: _textController,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 0, horizontal: 16),
contentPadding:
EdgeInsets.symmetric(vertical: 0, horizontal: 16),
enabledBorder: inputBorder,
focusedBorder: inputBorder,
),
style: TextStyle(color: ColorConsts.Primary, fontSize: 16, fontFamily: ''),
style: TextStyle(
color: ColorConst.primaryColor, fontSize: 16, fontFamily: ''),
onSubmitted: (input) => onSubmit(input),
focusNode: _commentFocus,
),

View File

@ -1,6 +1,7 @@
import '../engine/engine.dart';
import 'package:flutter/material.dart';
import '../common/color-consts.dart';
import '../engine/engine.dart';
import '../main.dart';
import 'battle-page.dart';
import 'settings-page.dart';
@ -88,7 +89,7 @@ class _MainMenuState extends State<MainMenu> with TickerProviderStateMixin {
);
final menuItemStyle = TextStyle(
fontSize: 28,
color: ColorConsts.Primary,
color: ColorConst.primaryColor,
shadows: [menuItemShadow],
);
@ -114,7 +115,7 @@ class _MainMenuState extends State<MainMenu> with TickerProviderStateMixin {
);
return Scaffold(
backgroundColor: ColorConsts.LightBackground,
backgroundColor: ColorConst.lightBackgroundColor,
body: Stack(
children: <Widget>[
menuItems,
@ -122,7 +123,7 @@ class _MainMenuState extends State<MainMenu> with TickerProviderStateMixin {
top: SanmillApp.StatusBarHeight,
left: 10,
child: IconButton(
icon: Icon(Icons.settings, color: ColorConsts.Primary),
icon: Icon(Icons.settings, color: ColorConst.primaryColor),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(builder: (context) => SettingsPage()),
),

View File

@ -1,11 +1,12 @@
import '../services/player.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:package_info/package_info.dart';
import '../common/toast.dart';
import '../common/color-consts.dart';
import '../common/config.dart';
import '../common/toast.dart';
import '../services/audios.dart';
import '../services/player.dart';
import 'edit-page.dart';
class SettingsPage extends StatefulWidget {
@ -51,7 +52,7 @@ class _SettingsPageState extends State<SettingsPage> {
children: <Widget>[
SizedBox(height: 10),
RadioListTile(
activeColor: ColorConsts.Primary,
activeColor: ColorConst.primaryColor,
title: Text('初级'),
groupValue: Config.stepTime,
value: 5000,
@ -59,7 +60,7 @@ class _SettingsPageState extends State<SettingsPage> {
),
Divider(),
RadioListTile(
activeColor: ColorConsts.Primary,
activeColor: ColorConst.primaryColor,
title: Text('中级'),
groupValue: Config.stepTime,
value: 15000,
@ -67,7 +68,7 @@ class _SettingsPageState extends State<SettingsPage> {
),
Divider(),
RadioListTile(
activeColor: ColorConsts.Primary,
activeColor: ColorConst.primaryColor,
title: Text('高级'),
groupValue: Config.stepTime,
value: 30000,
@ -130,7 +131,8 @@ class _SettingsPageState extends State<SettingsPage> {
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: Text('关于「直棋 」', style: TextStyle(color: ColorConsts.Primary)),
title:
Text('关于「直棋 」', style: TextStyle(color: ColorConst.primaryColor)),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
@ -166,11 +168,11 @@ class _SettingsPageState extends State<SettingsPage> {
Widget build(BuildContext context) {
//
final TextStyle headerStyle =
TextStyle(color: ColorConsts.Secondary, fontSize: 20.0);
final TextStyle itemStyle = TextStyle(color: ColorConsts.Primary);
TextStyle(color: ColorConst.secondaryColor, fontSize: 20.0);
final TextStyle itemStyle = TextStyle(color: ColorConst.primaryColor);
return Scaffold(
backgroundColor: ColorConsts.LightBackground,
backgroundColor: ColorConst.lightBackgroundColor,
appBar: AppBar(title: Text('设置')),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16),
@ -181,7 +183,7 @@ class _SettingsPageState extends State<SettingsPage> {
Text("人机难度", style: headerStyle),
const SizedBox(height: 10.0),
Card(
color: ColorConsts.BoardBackground,
color: ColorConst.boardBackgroundColor,
elevation: 0.5,
margin: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 0),
child: Column(
@ -194,7 +196,7 @@ class _SettingsPageState extends State<SettingsPage> {
? '初级'
: Config.stepTime <= 15000 ? '中级' : '高级'),
Icon(Icons.keyboard_arrow_right,
color: ColorConsts.Secondary),
color: ColorConst.secondaryColor),
]),
onTap: changeDifficult,
),
@ -204,19 +206,19 @@ class _SettingsPageState extends State<SettingsPage> {
const SizedBox(height: 16),
Text("声音", style: headerStyle),
Card(
color: ColorConsts.BoardBackground,
color: ColorConst.boardBackgroundColor,
margin: const EdgeInsets.symmetric(vertical: 10),
child: Column(
children: <Widget>[
SwitchListTile(
activeColor: ColorConsts.Primary,
activeColor: ColorConst.primaryColor,
value: Config.bgmEnabled,
title: Text("背景音乐", style: itemStyle),
onChanged: switchMusic,
),
_buildDivider(),
SwitchListTile(
activeColor: ColorConsts.Primary,
activeColor: ColorConst.primaryColor,
value: Config.toneEnabled,
title: Text("提示音效", style: itemStyle),
onChanged: switchTone,
@ -227,7 +229,7 @@ class _SettingsPageState extends State<SettingsPage> {
const SizedBox(height: 16),
Text("排行榜", style: headerStyle),
Card(
color: ColorConsts.BoardBackground,
color: ColorConst.boardBackgroundColor,
margin: const EdgeInsets.symmetric(vertical: 10),
child: Column(
children: <Widget>[
@ -237,7 +239,7 @@ class _SettingsPageState extends State<SettingsPage> {
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Text(Player.shared.name),
Icon(Icons.keyboard_arrow_right,
color: ColorConsts.Secondary),
color: ColorConst.secondaryColor),
]),
onTap: changeName,
),
@ -247,7 +249,7 @@ class _SettingsPageState extends State<SettingsPage> {
const SizedBox(height: 16),
Text("关于", style: headerStyle),
Card(
color: ColorConsts.BoardBackground,
color: ColorConst.boardBackgroundColor,
margin: const EdgeInsets.symmetric(vertical: 10),
child: Column(
children: <Widget>[
@ -257,7 +259,7 @@ class _SettingsPageState extends State<SettingsPage> {
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Text(_version ?? ''),
Icon(Icons.keyboard_arrow_right,
color: ColorConsts.Secondary),
color: ColorConst.secondaryColor),
]),
onTap: showAbout,
),
@ -276,7 +278,7 @@ class _SettingsPageState extends State<SettingsPage> {
margin: const EdgeInsets.symmetric(horizontal: 16),
width: double.infinity,
height: 1.0,
color: ColorConsts.LightLine,
color: ColorConst.lightLineColor,
);
}
}