mirror of
https://github.com/Linloir/Flutter-Wordle.git
synced 2025-12-16 22:18:10 +08:00
0.3.9 update night mode
This commit is contained in:
parent
c67dce436e
commit
ba918f2b42
79339
assets/ospd.txt
Normal file
79339
assets/ospd.txt
Normal file
File diff suppressed because it is too large
Load Diff
25321
assets/popular.txt
Normal file
25321
assets/popular.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @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
|
||||
*/
|
||||
|
||||
@ -160,21 +160,21 @@ class _WordleDisplayWidgetState extends State<WordleDisplayWidget> with TickerPr
|
||||
border: Border.all(
|
||||
color: inputs[i][j]["State"] == 1 ? Colors.green[600]! :
|
||||
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]! :
|
||||
Colors.grey[400]!,
|
||||
Theme.of(context).brightness == Brightness.dark ? Colors.grey[700]! : Colors.grey[400]!,
|
||||
width: 2.0,
|
||||
),
|
||||
color: inputs[i][j]["State"] == 1 ? Colors.green[600]! :
|
||||
inputs[i][j]["State"] == 2 ? Colors.yellow[800]! :
|
||||
inputs[i][j]["State"] == -1 ? Colors.grey[700]! :
|
||||
Colors.white,
|
||||
Theme.of(context).brightness == Brightness.dark ? Colors.grey[850]! : Colors.white,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
inputs[i][j]["Letter"],
|
||||
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,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-03-06 15:03:57
|
||||
* @LastEditTime : 2022-03-06 23:11:33
|
||||
* @LastEditTime : 2022-03-07 08:34:56
|
||||
* @Description : Word generator
|
||||
*/
|
||||
|
||||
@ -12,14 +12,16 @@ import 'dart:math';
|
||||
abstract class Words {
|
||||
static Set<String> dataBase = <String>{};
|
||||
static int _length = 0;
|
||||
static String _cache = "";
|
||||
//static Map<String, String> explainations = {};
|
||||
|
||||
static Future<void> importWordsDatabase({int length = 5}) async {
|
||||
//explainations.clear();
|
||||
if(length != _length){
|
||||
if(length != _length || dataBase.isEmpty){
|
||||
_length = length;
|
||||
dataBase.clear();
|
||||
var data = await rootBundle.loadString('assets/unixWords.txt');
|
||||
_cache = "";
|
||||
var data = await rootBundle.loadString('popular.txt');
|
||||
// LineSplitter.split(data).forEach((line) {
|
||||
// int seperatePos = line.indexOf(',');
|
||||
// if(seperatePos != length + 2) {
|
||||
@ -31,13 +33,15 @@ abstract class Words {
|
||||
// explainations[word] = expl;
|
||||
// });
|
||||
LineSplitter.split(data).forEach((line) {
|
||||
if(line.length == length) {
|
||||
dataBase.add(line);
|
||||
if(line.length == length && line != _cache) {
|
||||
dataBase.add(line.toLowerCase());
|
||||
}
|
||||
_cache = line + "s";
|
||||
});
|
||||
print('Imported ${dataBase.length}');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static Future<String> generateWord() async{
|
||||
int bound = dataBase.length;
|
||||
if(bound == 0) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @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
|
||||
*/
|
||||
|
||||
@ -104,8 +104,8 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
|
||||
backgroundColor: MaterialStateProperty.all<Color?>(
|
||||
_keyState[_keyPos[0][i]]! == 0 ? Colors.grey[400] :
|
||||
_keyState[_keyPos[0][i]]! == 1 ? Colors.green[600] :
|
||||
_keyState[_keyPos[0][i]]! == 2 ? Colors.orange[600] :
|
||||
Colors.grey[850]
|
||||
_keyState[_keyPos[0][i]]! == 2 ? Colors.yellow[800] :
|
||||
Colors.grey[700]
|
||||
),
|
||||
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
|
||||
),
|
||||
@ -146,8 +146,8 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
|
||||
backgroundColor: MaterialStateProperty.all<Color?>(
|
||||
_keyState[_keyPos[1][i]]! == 0 ? Colors.grey[400] :
|
||||
_keyState[_keyPos[1][i]]! == 1 ? Colors.green[600] :
|
||||
_keyState[_keyPos[1][i]]! == 2 ? Colors.orange[600] :
|
||||
Colors.grey[850]
|
||||
_keyState[_keyPos[1][i]]! == 2 ? Colors.yellow[800] :
|
||||
Colors.grey[700]
|
||||
),
|
||||
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
|
||||
),
|
||||
@ -211,8 +211,8 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
|
||||
backgroundColor: MaterialStateProperty.all<Color?>(
|
||||
_keyState[_keyPos[2][i]]! == 0 ? Colors.grey[400] :
|
||||
_keyState[_keyPos[2][i]]! == 1 ? Colors.green[600] :
|
||||
_keyState[_keyPos[2][i]]! == 2 ? Colors.orange[600] :
|
||||
Colors.grey[850]
|
||||
_keyState[_keyPos[2][i]]! == 2 ? Colors.yellow[800] :
|
||||
Colors.grey[700]
|
||||
),
|
||||
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
|
||||
),
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-03-05 20:21:34
|
||||
* @LastEditTime : 2022-03-06 23:07:38
|
||||
* @LastEditTime : 2022-03-07 09:20:28
|
||||
* @Description :
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
@ -13,16 +13,42 @@ void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
class MyApp extends StatefulWidget {
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Wordle',
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.grey
|
||||
primarySwatch: Colors.grey,
|
||||
brightness: brightness,
|
||||
),
|
||||
routes: {
|
||||
"/": (context) => const HomePage(),
|
||||
@ -60,7 +86,7 @@ class HomePage extends StatelessWidget {
|
||||
Text(
|
||||
'OFFLINE PLAYGROUND',
|
||||
style: TextStyle(
|
||||
color: Colors.grey[850]!,
|
||||
color: Theme.of(context).brightness == Brightness.dark ? Colors.white : Colors.grey[850]!,
|
||||
fontSize: 20.0,
|
||||
fontWeight: FontWeight.bold
|
||||
),
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-03-05 20:41:41
|
||||
* @LastEditTime : 2022-03-06 22:59:34
|
||||
* @LastEditTime : 2022-03-07 09:30:56
|
||||
* @Description : Offline page
|
||||
*/
|
||||
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wordle/event_bus.dart';
|
||||
import 'package:wordle/validation_provider.dart';
|
||||
@ -17,38 +19,67 @@ class OfflinePage extends StatefulWidget {
|
||||
State<OfflinePage> createState() => _OfflinePageState();
|
||||
}
|
||||
|
||||
class _OfflinePageState extends State<OfflinePage> {
|
||||
class _OfflinePageState extends State<OfflinePage> with TickerProviderStateMixin{
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var mode = Theme.of(context).brightness;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
backgroundColor: Theme.of(context).brightness == Brightness.dark ? Colors.grey[850] : Colors.white,
|
||||
elevation: 0.0,
|
||||
shadowColor: Colors.transparent,
|
||||
toolbarHeight: 80.0,
|
||||
titleTextStyle: const TextStyle(
|
||||
color: Colors.black,
|
||||
titleTextStyle: TextStyle(
|
||||
color: Theme.of(context).brightness == Brightness.dark ? Colors.grey[100] : Colors.black,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20.0,
|
||||
),
|
||||
title: const Text('WORDLE OFFLINE'),
|
||||
centerTitle: true,
|
||||
iconTheme: const IconThemeData(color: Colors.black),
|
||||
actions: [
|
||||
//iconTheme: const IconThemeData(color: Colors.black),
|
||||
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(
|
||||
icon: const Icon(Icons.refresh_rounded),
|
||||
color: Colors.black,
|
||||
//color: Colors.black,
|
||||
onPressed: (){
|
||||
mainBus.emit(event: "NewGame", args: []);
|
||||
},
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Container(
|
||||
child: const ValidationProvider(
|
||||
child: WordleDisplayWidget(),
|
||||
),
|
||||
color: Colors.white,
|
||||
color: Theme.of(context).brightness == Brightness.dark ? Colors.grey[850] : Colors.white,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @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
|
||||
*/
|
||||
|
||||
@ -40,6 +40,7 @@ class _ValidationProviderState extends State<ValidationProvider> {
|
||||
|
||||
void _newGame() async{
|
||||
answer = await Words.generateWord();
|
||||
print('Generated answer $answer');
|
||||
answer = answer.toUpperCase();
|
||||
letterMap = {};
|
||||
answer.split('').forEach((c) {
|
||||
|
||||
@ -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.
|
||||
# Read more about iOS versioning at
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
version: 1.0.0+1
|
||||
version: 0.3.9+0939
|
||||
|
||||
environment:
|
||||
sdk: ">=2.16.1 <3.0.0"
|
||||
@ -63,6 +63,8 @@ flutter:
|
||||
# - images/a_dot_ham.jpeg
|
||||
assets:
|
||||
- assets/unixWords.txt
|
||||
- assets/ospd.txt
|
||||
- popular.txt
|
||||
|
||||
# An image asset can refer to one or more resolution-specific "variants", see
|
||||
# https://flutter.dev/assets-and-images/#resolution-aware.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user