0.3.9 update night mode

This commit is contained in:
Linloir 2022-03-07 09:43:35 +08:00
parent c67dce436e
commit ba918f2b42
9 changed files with 104759 additions and 35 deletions

79339
assets/ospd.txt Normal file

File diff suppressed because it is too large Load Diff

25321
assets/popular.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-05 20:56:05 * @Date : 2022-03-05 20:56:05
* @LastEditTime : 2022-03-06 23:01:03 * @LastEditTime : 2022-03-07 09:35:24
* @Description : The display widget of the wordle game * @Description : The display widget of the wordle game
*/ */
@ -160,21 +160,21 @@ class _WordleDisplayWidgetState extends State<WordleDisplayWidget> with TickerPr
border: Border.all( border: Border.all(
color: inputs[i][j]["State"] == 1 ? Colors.green[600]! : color: inputs[i][j]["State"] == 1 ? Colors.green[600]! :
inputs[i][j]["State"] == 2 ? Colors.yellow[800]! : inputs[i][j]["State"] == 2 ? Colors.yellow[800]! :
inputs[i][j]["State"] == 3 ? Colors.grey[850]! : inputs[i][j]["State"] == 3 ? Theme.of(context).brightness == Brightness.dark ? Colors.grey[400]! : Colors.grey[850]! :
inputs[i][j]["State"] == -1 ? Colors.grey[700]! : inputs[i][j]["State"] == -1 ? Colors.grey[700]! :
Colors.grey[400]!, Theme.of(context).brightness == Brightness.dark ? Colors.grey[700]! : Colors.grey[400]!,
width: 2.0, width: 2.0,
), ),
color: inputs[i][j]["State"] == 1 ? Colors.green[600]! : color: inputs[i][j]["State"] == 1 ? Colors.green[600]! :
inputs[i][j]["State"] == 2 ? Colors.yellow[800]! : inputs[i][j]["State"] == 2 ? Colors.yellow[800]! :
inputs[i][j]["State"] == -1 ? Colors.grey[700]! : inputs[i][j]["State"] == -1 ? Colors.grey[700]! :
Colors.white, Theme.of(context).brightness == Brightness.dark ? Colors.grey[850]! : Colors.white,
), ),
child: Center( child: Center(
child: Text( child: Text(
inputs[i][j]["Letter"], inputs[i][j]["Letter"],
style: TextStyle( style: TextStyle(
color: inputs[i][j]["State"] == 3 ? Colors.grey[850]! :Colors.white, color: inputs[i][j]["State"] == 3 ? Theme.of(context).brightness == Brightness.dark ? Colors.white : Colors.grey[850]! :Colors.white,
fontSize: 30, fontSize: 30,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-06 15:03:57 * @Date : 2022-03-06 15:03:57
* @LastEditTime : 2022-03-06 23:11:33 * @LastEditTime : 2022-03-07 08:34:56
* @Description : Word generator * @Description : Word generator
*/ */
@ -12,14 +12,16 @@ import 'dart:math';
abstract class Words { abstract class Words {
static Set<String> dataBase = <String>{}; static Set<String> dataBase = <String>{};
static int _length = 0; static int _length = 0;
static String _cache = "";
//static Map<String, String> explainations = {}; //static Map<String, String> explainations = {};
static Future<void> importWordsDatabase({int length = 5}) async { static Future<void> importWordsDatabase({int length = 5}) async {
//explainations.clear(); //explainations.clear();
if(length != _length){ if(length != _length || dataBase.isEmpty){
_length = length; _length = length;
dataBase.clear(); dataBase.clear();
var data = await rootBundle.loadString('assets/unixWords.txt'); _cache = "";
var data = await rootBundle.loadString('popular.txt');
// LineSplitter.split(data).forEach((line) { // LineSplitter.split(data).forEach((line) {
// int seperatePos = line.indexOf(','); // int seperatePos = line.indexOf(',');
// if(seperatePos != length + 2) { // if(seperatePos != length + 2) {
@ -31,13 +33,15 @@ abstract class Words {
// explainations[word] = expl; // explainations[word] = expl;
// }); // });
LineSplitter.split(data).forEach((line) { LineSplitter.split(data).forEach((line) {
if(line.length == length) { if(line.length == length && line != _cache) {
dataBase.add(line); dataBase.add(line.toLowerCase());
} }
_cache = line + "s";
}); });
print('Imported ${dataBase.length}');
} }
} }
static Future<String> generateWord() async{ static Future<String> generateWord() async{
int bound = dataBase.length; int bound = dataBase.length;
if(bound == 0) { if(bound == 0) {

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-05 20:55:53 * @Date : 2022-03-05 20:55:53
* @LastEditTime : 2022-03-06 21:44:36 * @LastEditTime : 2022-03-07 08:07:14
* @Description : Input pannel class * @Description : Input pannel class
*/ */
@ -104,8 +104,8 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
backgroundColor: MaterialStateProperty.all<Color?>( backgroundColor: MaterialStateProperty.all<Color?>(
_keyState[_keyPos[0][i]]! == 0 ? Colors.grey[400] : _keyState[_keyPos[0][i]]! == 0 ? Colors.grey[400] :
_keyState[_keyPos[0][i]]! == 1 ? Colors.green[600] : _keyState[_keyPos[0][i]]! == 1 ? Colors.green[600] :
_keyState[_keyPos[0][i]]! == 2 ? Colors.orange[600] : _keyState[_keyPos[0][i]]! == 2 ? Colors.yellow[800] :
Colors.grey[850] Colors.grey[700]
), ),
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)), padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
), ),
@ -146,8 +146,8 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
backgroundColor: MaterialStateProperty.all<Color?>( backgroundColor: MaterialStateProperty.all<Color?>(
_keyState[_keyPos[1][i]]! == 0 ? Colors.grey[400] : _keyState[_keyPos[1][i]]! == 0 ? Colors.grey[400] :
_keyState[_keyPos[1][i]]! == 1 ? Colors.green[600] : _keyState[_keyPos[1][i]]! == 1 ? Colors.green[600] :
_keyState[_keyPos[1][i]]! == 2 ? Colors.orange[600] : _keyState[_keyPos[1][i]]! == 2 ? Colors.yellow[800] :
Colors.grey[850] Colors.grey[700]
), ),
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)), padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
), ),
@ -211,8 +211,8 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
backgroundColor: MaterialStateProperty.all<Color?>( backgroundColor: MaterialStateProperty.all<Color?>(
_keyState[_keyPos[2][i]]! == 0 ? Colors.grey[400] : _keyState[_keyPos[2][i]]! == 0 ? Colors.grey[400] :
_keyState[_keyPos[2][i]]! == 1 ? Colors.green[600] : _keyState[_keyPos[2][i]]! == 1 ? Colors.green[600] :
_keyState[_keyPos[2][i]]! == 2 ? Colors.orange[600] : _keyState[_keyPos[2][i]]! == 2 ? Colors.yellow[800] :
Colors.grey[850] Colors.grey[700]
), ),
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)), padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
), ),

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-05 20:21:34 * @Date : 2022-03-05 20:21:34
* @LastEditTime : 2022-03-06 23:07:38 * @LastEditTime : 2022-03-07 09:20:28
* @Description : * @Description :
*/ */
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -13,16 +13,42 @@ void main() {
runApp(const MyApp()); runApp(const MyApp());
} }
class MyApp extends StatelessWidget { class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key); const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application. @override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
var brightness = Brightness.light;
void _onThemeChange(dynamic args) {
setState(() {
brightness = brightness == Brightness.light ? Brightness.dark : Brightness.light;
});
}
@override
void initState() {
super.initState();
mainBus.onBus(event: "ToggleTheme", onEvent: _onThemeChange);
}
@override
void dispose(){
mainBus.offBus(event: "ToggleTheme", callBack: _onThemeChange);
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
title: 'Wordle', title: 'Wordle',
theme: ThemeData( theme: ThemeData(
primarySwatch: Colors.grey primarySwatch: Colors.grey,
brightness: brightness,
), ),
routes: { routes: {
"/": (context) => const HomePage(), "/": (context) => const HomePage(),
@ -60,7 +86,7 @@ class HomePage extends StatelessWidget {
Text( Text(
'OFFLINE PLAYGROUND', 'OFFLINE PLAYGROUND',
style: TextStyle( style: TextStyle(
color: Colors.grey[850]!, color: Theme.of(context).brightness == Brightness.dark ? Colors.white : Colors.grey[850]!,
fontSize: 20.0, fontSize: 20.0,
fontWeight: FontWeight.bold fontWeight: FontWeight.bold
), ),

View File

@ -1,10 +1,12 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-05 20:41:41 * @Date : 2022-03-05 20:41:41
* @LastEditTime : 2022-03-06 22:59:34 * @LastEditTime : 2022-03-07 09:30:56
* @Description : Offline page * @Description : Offline page
*/ */
import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:wordle/event_bus.dart'; import 'package:wordle/event_bus.dart';
import 'package:wordle/validation_provider.dart'; import 'package:wordle/validation_provider.dart';
@ -17,38 +19,67 @@ class OfflinePage extends StatefulWidget {
State<OfflinePage> createState() => _OfflinePageState(); State<OfflinePage> createState() => _OfflinePageState();
} }
class _OfflinePageState extends State<OfflinePage> { class _OfflinePageState extends State<OfflinePage> with TickerProviderStateMixin{
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var mode = Theme.of(context).brightness;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
backgroundColor: Colors.white, backgroundColor: Theme.of(context).brightness == Brightness.dark ? Colors.grey[850] : Colors.white,
elevation: 0.0, elevation: 0.0,
shadowColor: Colors.transparent, shadowColor: Colors.transparent,
toolbarHeight: 80.0, toolbarHeight: 80.0,
titleTextStyle: const TextStyle( titleTextStyle: TextStyle(
color: Colors.black, color: Theme.of(context).brightness == Brightness.dark ? Colors.grey[100] : Colors.black,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 20.0, fontSize: 20.0,
), ),
title: const Text('WORDLE OFFLINE'), title: const Text('WORDLE OFFLINE'),
centerTitle: true, centerTitle: true,
iconTheme: const IconThemeData(color: Colors.black), //iconTheme: const IconThemeData(color: Colors.black),
actions: [ actions: [AnimatedSwitcher(
duration: const Duration(milliseconds: 750),
reverseDuration: const Duration(milliseconds: 750),
switchInCurve: Curves.bounceInOut,
switchOutCurve: Curves.bounceInOut,
transitionBuilder: (child, animation) {
var rotateAnimation = Tween<double>(begin: 0, end: 2 * pi).animate(animation);
var opacAnimation = Tween<double>(begin: 0, end: 1).animate(animation);
return AnimatedBuilder(
animation: rotateAnimation,
builder: (context, child) {
return Transform(
transform: Matrix4.rotationZ(rotateAnimation.status == AnimationStatus.reverse ? 2 * pi - rotateAnimation.value : rotateAnimation.value),
alignment: Alignment.center,
child: Opacity(
opacity: opacAnimation.value,
child: child,
),
);
},
child: child,
);
},
child: IconButton(
key: ValueKey(mode),
icon: mode == Brightness.light ? const Icon(Icons.dark_mode_outlined) : const Icon(Icons.dark_mode),
onPressed: () => mainBus.emit(event: "ToggleTheme", args: []),
),
),
IconButton( IconButton(
icon: const Icon(Icons.refresh_rounded), icon: const Icon(Icons.refresh_rounded),
color: Colors.black, //color: Colors.black,
onPressed: (){ onPressed: (){
mainBus.emit(event: "NewGame", args: []); mainBus.emit(event: "NewGame", args: []);
}, },
) ),
], ],
), ),
body: Container( body: Container(
child: const ValidationProvider( child: const ValidationProvider(
child: WordleDisplayWidget(), child: WordleDisplayWidget(),
), ),
color: Colors.white, color: Theme.of(context).brightness == Brightness.dark ? Colors.grey[850] : Colors.white,
), ),
); );
} }

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-05 21:40:51 * @Date : 2022-03-05 21:40:51
* @LastEditTime : 2022-03-06 23:13:23 * @LastEditTime : 2022-03-07 08:10:08
* @Description : Validation Provider class * @Description : Validation Provider class
*/ */
@ -40,6 +40,7 @@ class _ValidationProviderState extends State<ValidationProvider> {
void _newGame() async{ void _newGame() async{
answer = await Words.generateWord(); answer = await Words.generateWord();
print('Generated answer $answer');
answer = answer.toUpperCase(); answer = answer.toUpperCase();
letterMap = {}; letterMap = {};
answer.split('').forEach((c) { answer.split('').forEach((c) {

View File

@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at # Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1 version: 0.3.9+0939
environment: environment:
sdk: ">=2.16.1 <3.0.0" sdk: ">=2.16.1 <3.0.0"
@ -63,6 +63,8 @@ flutter:
# - images/a_dot_ham.jpeg # - images/a_dot_ham.jpeg
assets: assets:
- assets/unixWords.txt - assets/unixWords.txt
- assets/ospd.txt
- popular.txt
# An image asset can refer to one or more resolution-specific "variants", see # An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware. # https://flutter.dev/assets-and-images/#resolution-aware.