From 2d184c73a1b177a0e530b58a904481710c5c3bd3 Mon Sep 17 00:00:00 2001 From: derdilla <82763757+NobodyForNothing@users.noreply.github.com> Date: Tue, 30 Jul 2024 04:05:24 +0400 Subject: [PATCH] chore: configure rewordle analysis and fix highlighted style errors --- apps/rewordle/analysis_options.yaml | 28 ----- apps/rewordle/lib/main.dart | 184 ++++++++++++++-------------- apps/rewordle/lib/persistence.dart | 15 ++- 3 files changed, 102 insertions(+), 125 deletions(-) delete mode 100644 apps/rewordle/analysis_options.yaml diff --git a/apps/rewordle/analysis_options.yaml b/apps/rewordle/analysis_options.yaml deleted file mode 100644 index 0d29021..0000000 --- a/apps/rewordle/analysis_options.yaml +++ /dev/null @@ -1,28 +0,0 @@ -# This file configures the analyzer, which statically analyzes Dart code to -# check for errors, warnings, and lints. -# -# The issues identified by the analyzer are surfaced in the UI of Dart-enabled -# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be -# invoked from the command line by running `flutter analyze`. - -# The following line activates a set of recommended lints for Flutter apps, -# packages, and plugins designed to encourage good coding practices. -include: package:flutter_lints/flutter.yaml - -linter: - # The lint rules applied to this project can be customized in the - # section below to disable rules from the `package:flutter_lints/flutter.yaml` - # included above or to enable additional rules. A list of all available lints - # and their documentation is published at https://dart.dev/lints. - # - # Instead of disabling a lint rule for the entire project in the - # section below, it can also be suppressed for a single line of code - # or a specific dart file by using the `// ignore: name_of_lint` and - # `// ignore_for_file: name_of_lint` syntax on the line or in the file - # producing the lint. - rules: - # avoid_print: false # Uncomment to disable the `avoid_print` rule - # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options diff --git a/apps/rewordle/lib/main.dart b/apps/rewordle/lib/main.dart index 9be6237..074f330 100644 --- a/apps/rewordle/lib/main.dart +++ b/apps/rewordle/lib/main.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'persistence.dart'; +import 'package:rewordle/persistence.dart'; void main() => runApp(RewordleApp()); @@ -29,7 +29,7 @@ class RewordleApp extends StatefulWidget { } class _RewordleAppState extends State { - GameState? state; + GameState? _state; String err = ''; late DateTime today; @@ -37,22 +37,40 @@ class _RewordleAppState extends State { void initState() { super.initState(); today = DateTime.now(); - String dateSlug = today.wFormat(); + final String dateSlug = today.wFormat(); DayLoader.load(dateSlug).then((s) => setState(() { - state = s; + _state = s; })); } @override void dispose() { - if (state != null) DayLoader.save(today.wFormat(), state!); + if (_state != null) DayLoader.save(today.wFormat(), _state!); super.dispose(); } + Widget _buildLoadingIndicator() => Padding( + padding: EdgeInsets.all(3.0), + child: Stack( + children: [ + Center( + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation( + Defaults.textColor, + ), + strokeWidth: 1, + ) + ), + Center( + child: Icon(Icons.cloud, color: Defaults.textColor), + ), + ], + ), + ); + @override - Widget build(context) => MaterialApp( + Widget build(BuildContext context) => MaterialApp( theme: ThemeData( - backgroundColor: Defaults.background, canvasColor: Defaults.background, ), home: DefaultTextStyle( @@ -61,79 +79,67 @@ class _RewordleAppState extends State { fontWeight: FontWeight.bold, ), child: Scaffold( - backgroundColor: Defaults.background, - appBar: AppBar( - forceMaterialTransparency: true, - leading: state != null - ? null - : Padding( - padding: EdgeInsets.all(3.0), - child: Stack(children: [ - Center( - child: CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation( - Defaults.textColor), - strokeWidth: 1, - )), - Center( - child: Icon(Icons.cloud, - color: Defaults.textColor)), - ]), - ), - ), - body: Column( - children: [ - GuessesList(guesses: [ - for (final e in state?.submitted ?? []) e, - state?.current ?? [], // todo cache letters until loaded - ]), - if (!(state?.finished ?? false)) - Keyboard( - okLetters: state?.okLetters ?? '', - wrongPosLetters: state?.wrongPosLetters ?? '', - wrongLetters: state?.wrongLetters ?? '', - onLetter: (l) { - if ((state?.current.length ?? 6) < 5) { - setState(() => state!.current - .add(LetterData(LetterCorrectness.none, l))); - } - }, - onDone: () { - String word = ''; - for (final e in state?.current ?? []) { - word += e.letter; - } - setState(() { - try { - String? resp = state?.addWord(word); - if (state == null) { - resp = 'Loading, please wait'; - } - if (resp != null) { - err = resp; - } else { - err = ''; - state?.current.clear(); - } - } catch (e, s) { - err = word + e.toString() + s.toString(); - } - }); - if (state != null) { - DayLoader.save(today.wFormat(), state!); - } - }, - onBack: () { - if ((state?.current.length ?? 0) > 0) - setState(() => state?.current.removeLast()); - }, - ), - SingleChildScrollView( - child: - Text(err, style: TextStyle(color: Colors.white))), - ], - ))), - ); + backgroundColor: Defaults.background, + appBar: AppBar( + forceMaterialTransparency: true, + leading: _state != null + ? null + : _buildLoadingIndicator(), + ), + body: Column( + children: [ + GuessesList( + guesses: [ + for (final e in _state?.submitted ?? []) e, + _state?.current ?? [], // todo cache letters until loaded + ], + ), + if (!(_state?.finished ?? false)) + Keyboard( + okLetters: _state?.okLetters ?? '', + wrongPosLetters: _state?.wrongPosLetters ?? '', + wrongLetters: _state?.wrongLetters ?? '', + onLetter: (l) { + if ((_state?.current.length ?? 6) < 5) { + setState(() => _state!.current.add( + LetterData(LetterCorrectness.none, l), + )); + } + }, + onDone: () { + String word = ''; + for (final e in _state?.current ?? []) { + word += e.letter; + } + setState(() { + String? resp = _state?.addWord(word); + if (_state == null) { + resp = 'Loading, please wait'; + } + if (resp != null) { + err = resp; + } else { + err = ''; + _state?.current.clear(); + } + }); + + if (_state != null) { + DayLoader.save(today.wFormat(), _state!); + } + }, + onBack: () { + if ((_state?.current.length ?? 0) > 0) + setState(() => _state?.current.removeLast()); + }, + ), + SingleChildScrollView( + child: Text(err, style: TextStyle(color: Colors.white))), + ], + ), + ), + ), + ); } /// List of past submissions current input and remaing attempts. @@ -147,7 +153,7 @@ class GuessesList extends StatelessWidget { final List> guesses; @override - Widget build(context) => Padding( + Widget build(BuildContext context) => Padding( padding: EdgeInsets.all(12.0), child: Column( mainAxisSize: MainAxisSize.min, @@ -190,7 +196,7 @@ class Letter extends StatelessWidget { final w = 57.0; final letter = Center( child: Text( - l?.letter ?? "", + l?.letter ?? '', style: TextStyle( fontSize: Defaults.textSize, fontWeight: FontWeight.bold, @@ -292,13 +298,13 @@ class Keyboard extends StatelessWidget { Row( mainAxisSize: MainAxisSize.min, children: [ - for (final l in "QWERTYUIOP".split("")) _letterBtn(l), + for (final l in 'QWERTYUIOP'.split('')) _letterBtn(l), ], ), Row( mainAxisSize: MainAxisSize.min, children: [ - for (final l in "ASDFGHJKL".split("")) _letterBtn(l), + for (final l in 'ASDFGHJKL'.split('')) _letterBtn(l), ], ), Row( @@ -310,11 +316,11 @@ class Keyboard extends StatelessWidget { width: 60.0, height: 45.0, child: Center( - child: Text("ENTER", + child: Text('ENTER', style: TextStyle(color: Defaults.textColor))), ), ), - for (final l in "ZXCVBNM".split("")) _letterBtn(l), + for (final l in 'ZXCVBNM'.split('')) _letterBtn(l), InkWell( onTap: onBack, child: Container( @@ -333,7 +339,7 @@ class Keyboard extends StatelessWidget { /// Utility method for generic lists. extension ListExtension on List { /// Return null if [index] is out of range else return the content at that index. - T? getOrNull(int index) { - return (index >= 0 && index < length) ? this[index] : null; - } + T? getOrNull(int index) => (index >= 0 && index < length) + ? this[index] + : null; } diff --git a/apps/rewordle/lib/persistence.dart b/apps/rewordle/lib/persistence.dart index b69df6e..11994e4 100644 --- a/apps/rewordle/lib/persistence.dart +++ b/apps/rewordle/lib/persistence.dart @@ -1,7 +1,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import 'valid_words.dart'; +import 'package:rewordle/valid_words.dart'; /// A persistence and external storage manager. class DayLoader { @@ -41,7 +41,7 @@ class GameState { /// Load a [serialize]d game state. factory GameState.deserialize(String data) { - final e = data.split("|"); + final e = data.split('|'); final state = GameState(e[0]); state.wrongLetters = e[1]; @@ -49,7 +49,6 @@ class GameState { state.okLetters = e[3]; final words = e[4].split(','); - final correct = e[0].split(''); words.forEach(state.addWord); return state; } @@ -58,17 +57,17 @@ class GameState { final List> submitted = []; final String correctWord; - String wrongLetters = ""; - String wrongPosLetters = ""; - String okLetters = ""; + String wrongLetters = ''; + String wrongPosLetters = ''; + String okLetters = ''; bool finished = false; /// Store a wordle atate for later deserialization. String serialize() { - String submissionsString = ""; + String submissionsString = ''; for (final wData in submitted) { - String w = ""; + String w = ''; for (final l in wData) { w += l.letter; }