Skip to content

Commit 021fc22

Browse files
committed
Bumped minimum dart sdk constraint to 2.17.1 from 2.7.0
Added minimum flutter sdk constraint (3.0.0) Migrated all code to null safety and fixed all warnings
1 parent c2c64b2 commit 021fc22

File tree

6 files changed

+54
-48
lines changed

6 files changed

+54
-48
lines changed

sudoku/lib/alerts.dart

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class AlertGameOver extends StatelessWidget {
1111
static bool newGame = false;
1212
static bool restartGame = false;
1313

14-
const AlertGameOver({Key key}) : super(key: key);
14+
const AlertGameOver({Key? key}) : super(key: key);
1515

1616
@override
1717
Widget build(BuildContext context) {
@@ -56,24 +56,25 @@ class AlertGameOver extends StatelessWidget {
5656
class AlertDifficultyState extends StatefulWidget {
5757
String currentDifficultyLevel;
5858

59-
AlertDifficultyState(this.currentDifficultyLevel, {Key key})
59+
AlertDifficultyState(this.currentDifficultyLevel, {Key? key})
6060
: super(key: key);
6161

6262
@override
6363
// ignore: no_logic_in_create_state
6464
AlertDifficulty createState() => AlertDifficulty(currentDifficultyLevel);
6565

66-
static String get difficulty {
66+
static String? get difficulty {
6767
return AlertDifficulty.difficulty;
6868
}
6969

70-
static set difficulty(String level) {
70+
static set difficulty(String? level) {
7171
AlertDifficulty.difficulty = level;
7272
}
7373
}
7474

7575
class AlertDifficulty extends State<AlertDifficultyState> {
76-
static String difficulty;
76+
// ignore: avoid_init_to_null
77+
static String? difficulty = null;
7778
static final List<String> difficulties = [
7879
'beginner',
7980
'easy',
@@ -120,7 +121,7 @@ class AlertDifficulty extends State<AlertDifficultyState> {
120121
}
121122

122123
class AlertExit extends StatelessWidget {
123-
const AlertExit({Key key}) : super(key: key);
124+
const AlertExit({Key? key}) : super(key: key);
124125

125126
@override
126127
Widget build(BuildContext context) {
@@ -164,23 +165,24 @@ class AlertExit extends StatelessWidget {
164165
}
165166

166167
class AlertNumbersState extends StatefulWidget {
167-
const AlertNumbersState({Key key}) : super(key: key);
168+
const AlertNumbersState({Key? key}) : super(key: key);
168169

169170
@override
170171
AlertNumbers createState() => AlertNumbers();
171172

172-
static int get number {
173+
static int? get number {
173174
return AlertNumbers.number;
174175
}
175176

176-
static set number(int number) {
177+
static set number(int? number) {
177178
AlertNumbers.number = number;
178179
}
179180
}
180181

181182
class AlertNumbers extends State<AlertNumbersState> {
182-
static int number;
183-
int numberSelected;
183+
// ignore: avoid_init_to_null
184+
static int? number = null;
185+
late int numberSelected;
184186
static final List<int> numberList1 = [1, 2, 3];
185187
static final List<int> numberList2 = [4, 5, 6];
186188
static final List<int> numberList3 = [7, 8, 9];
@@ -263,13 +265,13 @@ class AlertNumbers extends State<AlertNumbersState> {
263265
class AlertAccentColorsState extends StatefulWidget {
264266
String currentAccentColor;
265267

266-
AlertAccentColorsState(this.currentAccentColor, {Key key}) : super(key: key);
268+
AlertAccentColorsState(this.currentAccentColor, {Key? key}) : super(key: key);
267269

268-
static String get accentColor {
270+
static String? get accentColor {
269271
return AlertAccentColors.accentColor;
270272
}
271273

272-
static set accentColor(String color) {
274+
static set accentColor(String? color) {
273275
AlertAccentColors.accentColor = color;
274276
}
275277

@@ -279,7 +281,8 @@ class AlertAccentColorsState extends StatefulWidget {
279281
}
280282

281283
class AlertAccentColors extends State<AlertAccentColorsState> {
282-
static String accentColor;
284+
// ignore: avoid_init_to_null
285+
static String? accentColor = null;
283286
static final List<String> accentColors = [...Styles.accentColors.keys];
284287
String currentAccentColor;
285288

@@ -329,7 +332,7 @@ class AlertAbout extends StatelessWidget {
329332
static const String licenseURL =
330333
"https://github.com/VarunS2002/Flutter-Sudoku/blob/master/LICENSE";
331334

332-
const AlertAbout({Key key}) : super(key: key);
335+
const AlertAbout({Key? key}) : super(key: key);
333336

334337
openURL(String url) async {
335338
await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication);

sudoku/lib/main.dart

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void main() {
2121
}
2222

2323
class MyApp extends StatelessWidget {
24-
const MyApp({Key key}) : super(key: key);
24+
const MyApp({Key? key}) : super(key: key);
2525

2626
static const String versionNumber = '2.4.1';
2727

@@ -39,7 +39,7 @@ class MyApp extends StatelessWidget {
3939
}
4040

4141
class HomePage extends StatefulWidget {
42-
const HomePage({Key key}) : super(key: key);
42+
const HomePage({Key? key}) : super(key: key);
4343

4444
@override
4545
State<StatefulWidget> createState() => HomePageState();
@@ -50,13 +50,13 @@ class HomePageState extends State<HomePage> {
5050
bool gameOver = false;
5151
int timesCalled = 0;
5252
bool isButtonDisabled = false;
53-
List<List<List<int>>> gameList;
54-
List<List<int>> game;
55-
List<List<int>> gameCopy;
56-
List<List<int>> gameSolved;
57-
static String currentDifficultyLevel;
58-
static String currentTheme;
59-
static String currentAccentColor;
53+
late List<List<List<int>>> gameList;
54+
late List<List<int>> game;
55+
late List<List<int>> gameCopy;
56+
late List<List<int>> gameSolved;
57+
static String? currentDifficultyLevel;
58+
static String? currentTheme;
59+
static String? currentAccentColor;
6060
static String platform = () {
6161
if (kIsWeb) {
6262
return 'web-${defaultTargetPlatform.toString().replaceFirst("TargetPlatform.", "").toLowerCase()}';
@@ -99,9 +99,9 @@ class HomePageState extends State<HomePage> {
9999
currentAccentColor = 'Blue';
100100
setPrefs('currentAccentColor');
101101
}
102-
newGame(currentDifficultyLevel);
102+
newGame(currentDifficultyLevel!);
103103
changeTheme('set');
104-
changeAccentColor(currentAccentColor, true);
104+
changeAccentColor(currentAccentColor!, true);
105105
});
106106
}
107107

@@ -117,11 +117,11 @@ class HomePageState extends State<HomePage> {
117117
setPrefs(String property) async {
118118
final prefs = await SharedPreferences.getInstance();
119119
if (property == 'currentDifficultyLevel') {
120-
prefs.setString('currentDifficultyLevel', currentDifficultyLevel);
120+
prefs.setString('currentDifficultyLevel', currentDifficultyLevel!);
121121
} else if (property == 'currentTheme') {
122-
prefs.setString('currentTheme', currentTheme);
122+
prefs.setString('currentTheme', currentTheme!);
123123
} else if (property == 'currentAccentColor') {
124-
prefs.setString('currentAccentColor', currentAccentColor);
124+
prefs.setString('currentAccentColor', currentAccentColor!);
125125
}
126126
}
127127

@@ -157,10 +157,10 @@ class HomePageState extends State<HomePage> {
157157
void changeAccentColor(String color, [bool firstRun = false]) {
158158
setState(() {
159159
if (Styles.accentColors.keys.contains(color)) {
160-
Styles.primaryColor = Styles.accentColors[color];
160+
Styles.primaryColor = Styles.accentColors[color]!;
161161
} else {
162162
currentAccentColor = 'Blue';
163-
Styles.primaryColor = Styles.accentColors[color];
163+
Styles.primaryColor = Styles.accentColors[color]!;
164164
}
165165
if (color == 'Red') {
166166
Styles.secondaryColor = Styles.orange;
@@ -228,6 +228,11 @@ class HomePageState extends State<HomePage> {
228228
emptySquares = 54;
229229
}
230230
break;
231+
default:
232+
{
233+
emptySquares = 2;
234+
}
235+
break;
231236
}
232237
SudokuGenerator generator = SudokuGenerator(emptySquares: emptySquares);
233238
return [generator.newSudoku, generator.newSudokuSolved];
@@ -281,7 +286,7 @@ class HomePageState extends State<HomePage> {
281286
if (Styles.primaryBackgroundColor == Styles.darkGrey) {
282287
color = Styles.grey;
283288
} else {
284-
color = Colors.grey[300];
289+
color = Colors.grey[300]!;
285290
}
286291
} else {
287292
color = Styles.primaryBackgroundColor;
@@ -332,7 +337,7 @@ class HomePageState extends State<HomePage> {
332337
} else {
333338
emptyColor = Styles.secondaryColor;
334339
}
335-
List<SizedBox> buttonList = List<SizedBox>.filled(9, null);
340+
List<SizedBox> buttonList = List<SizedBox>.filled(9, const SizedBox());
336341
for (var i = 0; i <= 8; i++) {
337342
var k = timesCalled;
338343
buttonList[i] = SizedBox(
@@ -403,14 +408,11 @@ class HomePageState extends State<HomePage> {
403408
}
404409

405410
List<Row> createRows() {
406-
List<Row> rowList = List<Row>.filled(9, null);
407-
for (var i = 0; i <= 8; i++) {
408-
rowList[i] = oneRow();
409-
}
411+
List<Row> rowList = List<Row>.generate(9, (i) => oneRow());
410412
return rowList;
411413
}
412414

413-
void callback(List<int> index, int number) {
415+
void callback(List<int> index, int? number) {
414416
setState(() {
415417
if (number == null) {
416418
return;
@@ -453,7 +455,7 @@ class HomePageState extends State<HomePage> {
453455
onTap: () {
454456
Navigator.pop(context);
455457
Timer(const Duration(milliseconds: 200),
456-
() => newGame(currentDifficultyLevel));
458+
() => newGame(currentDifficultyLevel!));
457459
},
458460
),
459461
ListTile(
@@ -480,7 +482,7 @@ class HomePageState extends State<HomePage> {
480482
duration: const Duration(milliseconds: 350),
481483
context: outerContext,
482484
builder: (_) => AlertDifficultyState(
483-
currentDifficultyLevel)).whenComplete(() {
485+
currentDifficultyLevel!)).whenComplete(() {
484486
if (AlertDifficultyState.difficulty != null) {
485487
Timer(const Duration(milliseconds: 300), () {
486488
newGame(
@@ -519,7 +521,7 @@ class HomePageState extends State<HomePage> {
519521
duration: const Duration(milliseconds: 350),
520522
context: outerContext,
521523
builder: (_) => AlertAccentColorsState(
522-
currentAccentColor)).whenComplete(() {
524+
currentAccentColor!)).whenComplete(() {
523525
if (AlertAccentColorsState.accentColor != null) {
524526
Timer(const Duration(milliseconds: 300), () {
525527
currentAccentColor =

sudoku/lib/material_color_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:flutter/material.dart';
55
MaterialColor createMaterialColor(String hexColorCode) {
66
Color color = Color(int.parse("0xFF$hexColorCode"));
77
List strengths = <double>[.05];
8-
Map swatch = <int, Color>{};
8+
Map<int, Color> swatch = {};
99
final int r = color.red, g = color.green, b = color.blue;
1010

1111
for (int i = 1; i < 10; i++) {

sudoku/lib/splash_screen_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'main.dart';
55
import 'styles.dart';
66

77
class SplashScreenPage extends StatefulWidget {
8-
const SplashScreenPage({Key key}) : super(key: key);
8+
const SplashScreenPage({Key? key}) : super(key: key);
99

1010
@override
1111
SplashScreenPageState createState() => SplashScreenPageState();
@@ -21,7 +21,7 @@ class SplashScreenPageState extends State<SplashScreenPage> {
2121
Widget build(BuildContext context) {
2222
return SplashScreen(
2323
seconds: 2,
24-
navigateAfterSeconds: HomePage(),
24+
navigateAfterSeconds: const HomePage(),
2525
title: Text(
2626
'\nSudoku',
2727
style: TextStyle(

sudoku/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,5 +486,5 @@ packages:
486486
source: hosted
487487
version: "3.1.1"
488488
sdks:
489-
dart: ">=2.17.0 <3.0.0"
490-
flutter: ">=2.10.0"
489+
dart: ">=2.17.1 <3.0.0"
490+
flutter: ">=3.0.0"

sudoku/pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
1818
version: 2.4.1+2041
1919

2020
environment:
21-
sdk: ">=2.7.0 <3.0.0"
21+
sdk: ">=2.17.1 <3.0.0"
22+
flutter: ">=3.0.0"
2223

2324
# Dependencies specify other packages that your package needs in order to work.
2425
# To automatically upgrade your package dependencies to the latest versions

0 commit comments

Comments
 (0)