Skip to content

Commit

Permalink
chore: configure rewordle analysis and fix highlighted style errors
Browse files Browse the repository at this point in the history
  • Loading branch information
derdilla committed Jul 30, 2024
1 parent 3cbd524 commit 2d184c7
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 125 deletions.
28 changes: 0 additions & 28 deletions apps/rewordle/analysis_options.yaml

This file was deleted.

184 changes: 95 additions & 89 deletions apps/rewordle/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'persistence.dart';
import 'package:rewordle/persistence.dart';

void main() => runApp(RewordleApp());

Check notice on line 4 in apps/rewordle/lib/main.dart

View workflow job for this annotation

GitHub Actions / 🔍 Analyze code

Use 'const' with the constructor to improve performance.

Try adding the 'const' keyword to the constructor invocation. See https://dart.dev/diagnostics/prefer_const_constructors to learn more about this problem.

Expand Down Expand Up @@ -29,30 +29,48 @@ class RewordleApp extends StatefulWidget {
}

class _RewordleAppState extends State<RewordleApp> {
GameState? state;
GameState? _state;
String err = '';
late DateTime today;

@override
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),

Check notice on line 53 in apps/rewordle/lib/main.dart

View workflow job for this annotation

GitHub Actions / 🔍 Analyze code

Use 'const' with the constructor to improve performance.

Try adding the 'const' keyword to the constructor invocation. See https://dart.dev/diagnostics/prefer_const_constructors to learn more about this problem.
child: Stack(
children: [
Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
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(
Expand All @@ -61,79 +79,67 @@ class _RewordleAppState extends State<RewordleApp> {
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<Color>(
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());

Check notice on line 133 in apps/rewordle/lib/main.dart

View workflow job for this annotation

GitHub Actions / 🔍 Analyze code

Statements in an if should be enclosed in a block.

Try wrapping the statement in a block. See https://dart.dev/diagnostics/curly_braces_in_flow_control_structures to learn more about this problem.
},
),
SingleChildScrollView(
child: Text(err, style: TextStyle(color: Colors.white))),
],
),
),
),
);
}

/// List of past submissions current input and remaing attempts.
Expand All @@ -147,7 +153,7 @@ class GuessesList extends StatelessWidget {
final List<List<LetterData>> guesses;

@override
Widget build(context) => Padding(
Widget build(BuildContext context) => Padding(
padding: EdgeInsets.all(12.0),
child: Column(
mainAxisSize: MainAxisSize.min,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -333,7 +339,7 @@ class Keyboard extends StatelessWidget {
/// Utility method for generic lists.
extension ListExtension<T> on List<T> {
/// 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;
}
15 changes: 7 additions & 8 deletions apps/rewordle/lib/persistence.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -41,15 +41,14 @@ 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];
state.wrongPosLetters = e[2];
state.okLetters = e[3];

final words = e[4].split(',');
final correct = e[0].split('');
words.forEach(state.addWord);
return state;
}
Expand All @@ -58,17 +57,17 @@ class GameState {
final List<List<LetterData>> 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;
}
Expand Down

0 comments on commit 2d184c7

Please sign in to comment.