Skip to content
Snippets Groups Projects
Commit b846c521 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Merge branch '23-use-flutter-linter-and-apply-lints' into 'master'

Resolve "Use flutter linter and apply lints"

Closes #23

See merge request !21
parents 0b138bcd 7e56d952
Branches
Tags Release_1.0.17_18
1 merge request!21Resolve "Use flutter linter and apply lints"
Pipeline #5110 passed
include: package:flutter_lints/flutter.yaml
......@@ -44,7 +44,7 @@ android {
defaultConfig {
applicationId "org.benoitharrault.puissance4"
minSdkVersion 16
minSdkVersion flutter.minSdkVersion
targetSdkVersion 30
versionCode appVersionCode.toInteger()
versionName appVersionName
......
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=1.0.16
app.versionCode=17
app.versionName=1.0.17
app.versionCode=18
Add automatic flutter linter. Apply code lints. Update dependencies.
Ajout d'un correcteur automatique de code. Application des corrections. Mise à jour des dépendances.
......@@ -17,18 +17,13 @@ class Board {
_boxes = boxes;
}
Color? getBox(Coordinate coordinate) =>
_boxes[coordinate.col ?? 0][coordinate.row ?? 0];
Color? getBox(Coordinate coordinate) => _boxes[coordinate.col ?? 0][coordinate.row ?? 0];
int getColumnTarget(int? col) => _boxes[col ?? 0].lastIndexOf(null);
void setBox(Coordinate coordinate, Color? player) =>
_boxes[coordinate.col ?? 0][coordinate.row ?? 0] = player;
void reset() {
_boxes.forEach((r) => r.forEach((p) => p = null));
}
bool checkWinner(Coordinate coordinate, Color? player) {
return checkHorizontally(coordinate, player) ||
checkVertically(coordinate, player) ||
......
......@@ -10,15 +10,16 @@ abstract class Cpu {
Cpu(this.color);
Color get otherPlayer => color == Color.RED ? Color.YELLOW : Color.RED;
Color get otherPlayer => color == Color.red ? Color.yellow : Color.red;
Future<int> chooseCol(Board board);
}
class DumbCpu extends Cpu {
DumbCpu(Color player) : super(player);
DumbCpu(super.player);
Color get otherPlayer => color == Color.RED ? Color.YELLOW : Color.RED;
@override
Color get otherPlayer => color == Color.red ? Color.yellow : Color.red;
@override
Future<int> chooseCol(Board board) async {
......@@ -33,7 +34,7 @@ class DumbCpu extends Cpu {
}
class HarderCpu extends Cpu {
HarderCpu(Color player) : super(player);
HarderCpu(super.player);
@override
Future<int> chooseCol(Board board) async {
......@@ -101,7 +102,7 @@ class HarderCpu extends Cpu {
}
class HardestCpu extends HarderCpu {
HardestCpu(Color player) : super(player);
HardestCpu(super.player);
@override
Future<int> chooseCol(Board board) async {
......
......@@ -6,6 +6,8 @@ import 'package:puissance4/cpu.dart';
import 'match_page.dart';
class CpuLevelPage extends StatelessWidget {
const CpuLevelPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
......@@ -22,20 +24,20 @@ class CpuLevelPage extends StatelessWidget {
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.yellow,
padding: EdgeInsets.all(15),
padding: const EdgeInsets.all(15),
),
child: Text(
'☺️ FACILE',
style:
Theme.of(context).textTheme.headline4?.copyWith(color: Colors.black),
Theme.of(context).textTheme.headlineMedium?.copyWith(color: Colors.black),
),
onPressed: () {
Navigator.pushNamed(
context,
'/match',
arguments: {
'mode': Mode.PVC,
'cpu': DumbCpu(Random().nextBool() ? Color.RED : Color.YELLOW),
'mode': Mode.pvc,
'cpu': DumbCpu(Random().nextBool() ? Color.red : Color.yellow),
},
);
},
......@@ -43,20 +45,20 @@ class CpuLevelPage extends StatelessWidget {
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.red,
padding: EdgeInsets.all(15),
padding: const EdgeInsets.all(15),
),
child: Text(
'🤔 DIFFICILE',
style:
Theme.of(context).textTheme.headline4?.copyWith(color: Colors.white),
Theme.of(context).textTheme.headlineMedium?.copyWith(color: Colors.white),
),
onPressed: () {
Navigator.pushNamed(
context,
'/match',
arguments: {
'mode': Mode.PVC,
'cpu': HarderCpu(Random().nextBool() ? Color.RED : Color.YELLOW),
'mode': Mode.pvc,
'cpu': HarderCpu(Random().nextBool() ? Color.red : Color.yellow),
},
);
},
......@@ -64,20 +66,20 @@ class CpuLevelPage extends StatelessWidget {
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.deepPurpleAccent,
padding: EdgeInsets.all(15),
padding: const EdgeInsets.all(15),
),
child: Text(
'🤯 TRES DIFFICILE',
style:
Theme.of(context).textTheme.headline4?.copyWith(color: Colors.white),
Theme.of(context).textTheme.headlineMedium?.copyWith(color: Colors.white),
),
onPressed: () {
Navigator.pushNamed(
context,
'/match',
arguments: {
'mode': Mode.PVC,
'cpu': HardestCpu(Random().nextBool() ? Color.RED : Color.YELLOW),
'mode': Mode.pvc,
'cpu': HardestCpu(Random().nextBool() ? Color.red : Color.yellow),
},
);
},
......
......@@ -4,10 +4,10 @@ import 'match_page.dart';
class GameChip extends StatelessWidget {
const GameChip({
Key? key,
super.key,
this.translation,
this.color,
}) : super(key: key);
});
final Animation<double>? translation;
final Color? color;
......@@ -24,8 +24,8 @@ class GameChip extends StatelessWidget {
height: 40,
width: 40,
child: Material(
shape: CircleBorder(),
color: color == Color.RED ? Colors.red : Colors.yellow,
shape: const CircleBorder(),
color: color == Color.red ? Colors.red : Colors.yellow,
),
),
);
......
......@@ -6,6 +6,8 @@ import 'package:puissance4/cpu.dart';
import 'match_page.dart';
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
......@@ -19,19 +21,19 @@ class HomePage extends StatelessWidget {
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.green,
padding: EdgeInsets.all(15),
padding: const EdgeInsets.all(15),
),
child: Text(
'🧑 2 JOUEURS 🧑',
style:
Theme.of(context).textTheme.headline4?.copyWith(color: Colors.white),
Theme.of(context).textTheme.headlineMedium?.copyWith(color: Colors.white),
),
onPressed: () {
Navigator.pushNamed(
context,
'/match',
arguments: {
'mode': Mode.PVP,
'mode': Mode.pvp,
},
);
},
......@@ -39,19 +41,19 @@ class HomePage extends StatelessWidget {
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.orange,
padding: EdgeInsets.all(15),
padding: const EdgeInsets.all(15),
),
child: Text(
'🧑 1 JOUEUR 🤖',
style:
Theme.of(context).textTheme.headline4?.copyWith(color: Colors.white),
Theme.of(context).textTheme.headlineMedium?.copyWith(color: Colors.white),
),
onPressed: () {
Navigator.pushNamed(
context,
'/cpu-level',
arguments: {
'mode': Mode.PVC,
'mode': Mode.pvc,
},
);
},
......@@ -59,21 +61,20 @@ class HomePage extends StatelessWidget {
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.white,
padding: EdgeInsets.all(15),
padding: const EdgeInsets.all(15),
),
child: Text(
'🤖 DEMO 🤖',
style:
Theme.of(context).textTheme.headline4?.copyWith(color: Colors.black),
Theme.of(context).textTheme.headlineMedium?.copyWith(color: Colors.black),
),
onPressed: () {
final harderCpu =
HarderCpu(Random().nextBool() ? Color.RED : Color.YELLOW);
final harderCpu = HarderCpu(Random().nextBool() ? Color.red : Color.yellow);
Navigator.pushNamed(
context,
'/match',
arguments: {
'mode': Mode.DEMO,
'mode': Mode.demo,
'cpu': harderCpu,
'cpu2': HardestCpu(harderCpu.otherPlayer),
},
......
......@@ -7,10 +7,12 @@ import 'package:puissance4/match_page.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
.then((value) => runApp(MyApp()));
.then((value) => runApp(const MyApp()));
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
......@@ -18,7 +20,7 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
home: const HomePage(),
onGenerateRoute: (settings) {
final args = settings.arguments as Map<String, dynamic>;
if (settings.name == '/match') {
......@@ -31,7 +33,7 @@ class MyApp extends StatelessWidget {
);
} else if (settings.name == '/cpu-level') {
return MaterialPageRoute(
builder: (context) => CpuLevelPage(),
builder: (context) => const CpuLevelPage(),
);
}
......
......@@ -9,14 +9,14 @@ import 'game_chip.dart';
import 'hole_painter.dart';
enum Color {
YELLOW,
RED,
yellow,
red,
}
enum Mode {
PVP,
PVC,
DEMO,
pvp,
pvc,
demo,
}
class MatchPage extends StatefulWidget {
......@@ -25,17 +25,17 @@ class MatchPage extends StatefulWidget {
final Cpu? cpu2;
const MatchPage({
Key? key,
super.key,
required this.mode,
required this.cpu,
required this.cpu2,
}) : super(key: key);
});
@override
_MatchPageState createState() => _MatchPageState();
MatchPageState createState() => MatchPageState();
}
class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
class MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
final board = Board();
Color? turn;
Color? winner;
......@@ -65,7 +65,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
flex: 2,
child: Container(
constraints: BoxConstraints.loose(
Size(
const Size(
500,
532,
),
......@@ -93,21 +93,21 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
padding: const EdgeInsets.all(32.0),
child: winner != null
? Text(
'${winner == Color.RED ? 'RED' : 'YELLOW'} WINS',
'${winner == Color.red ? 'RED' : 'YELLOW'} WINS',
textAlign: TextAlign.center,
style: Theme.of(context)
.textTheme
.headline6
.titleLarge
?.copyWith(color: Colors.white),
)
: Column(
children: <Widget>[
Text(
'${turn == Color.RED ? 'RED' : 'YELLOW'} SPEAKS',
'${turn == Color.red ? 'RED' : 'YELLOW'} SPEAKS',
textAlign: TextAlign.center,
style: Theme.of(context)
.textTheme
.headline5
.headlineSmall
?.copyWith(color: Colors.white),
),
Padding(
......@@ -130,14 +130,14 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
Text _buildPlayerName(BuildContext context) {
String name;
if (widget.mode == Mode.PVC) {
if (widget.mode == Mode.pvc) {
if (turn == widget.cpu?.color) {
name = 'CPU - ${widget.cpu.toString()}';
} else {
name = 'USER';
}
} else if (widget.mode == Mode.PVP) {
if (turn == Color.RED) {
} else if (widget.mode == Mode.pvp) {
if (turn == Color.red) {
name = 'PLAYER1';
} else {
name = 'PLAYER2';
......@@ -152,17 +152,17 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
return Text(
name,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headline5?.copyWith(color: Colors.white),
style: Theme.of(context).textTheme.headlineSmall?.copyWith(color: Colors.white),
);
}
@override
void initState() {
super.initState();
turn = Random().nextBool() ? Color.RED : Color.YELLOW;
if (widget.mode == Mode.PVC && turn == widget.cpu?.color) {
turn = Random().nextBool() ? Color.red : Color.yellow;
if (widget.mode == Mode.pvc && turn == widget.cpu?.color) {
cpuMove(widget.cpu);
} else if (widget.mode == Mode.DEMO) {
} else if (widget.mode == Mode.demo) {
if (turn == widget.cpu?.color) {
cpuMove(widget.cpu);
} else {
......@@ -175,15 +175,15 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
return GridView.custom(
padding: const EdgeInsets.all(0),
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 7),
physics: const NeverScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 7),
childrenDelegate: SliverChildBuilderDelegate(
(context, i) {
final col = i % 7;
final row = i ~/ 7;
if (board.getBox(Coordinate(col, row)) == null) {
return SizedBox();
return const SizedBox();
}
return GameChip(
......@@ -199,8 +199,8 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
GridView buildBoard() {
return GridView.custom(
padding: const EdgeInsets.all(0),
physics: NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 7),
physics: const NeverScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 7),
shrinkWrap: true,
childrenDelegate: SliverChildBuilderDelegate(
(context, i) {
......@@ -213,7 +213,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
}
},
child: CustomPaint(
size: Size(50, 50),
size: const Size(50, 50),
willChange: false,
painter: HolePainter(),
),
......@@ -226,7 +226,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
void userMove(int col) {
putChip(col);
if (winner == null && widget.mode == Mode.PVC) {
if (winner == null && widget.mode == Mode.pvc) {
cpuMove(widget.cpu);
}
}
......@@ -235,7 +235,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
int? col = await cpu?.chooseCol(board);
putChip(col);
if (winner == null && widget.mode == Mode.DEMO) {
if (winner == null && widget.mode == Mode.demo) {
if (turn == widget.cpu?.color) {
cpuMove(widget.cpu);
} else {
......@@ -254,7 +254,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
final controller = AnimationController(
vsync: this,
duration: Duration(seconds: 1),
duration: const Duration(seconds: 1),
)..addListener(() {
if (mounted) {
setState(() {});
......@@ -264,7 +264,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
if (mounted) {
setState(() {
board.setBox(Coordinate(col, target), turn);
turn = turn == Color.RED ? Color.YELLOW : Color.RED;
turn = turn == Color.red ? Color.yellow : Color.red;
});
}
......@@ -294,15 +294,8 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
});
Future.delayed(
Duration(seconds: 5),
const Duration(seconds: 5),
() => mounted ? Navigator.popUntil(context, (r) => r.isFirst) : null,
);
}
void resetBoard() {
setState(() {
winner = null;
board.reset();
});
}
}
......@@ -13,31 +13,47 @@ packages:
dependency: transitive
description:
name: collection
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.2"
version: "1.18.0"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7
url: "https://pub.dev"
source: hosted
version: "3.0.1"
lints:
dependency: transitive
description:
name: lints
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
url: "https://pub.dev"
source: hosted
version: "3.0.0"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.11.0"
sky_engine:
dependency: transitive
description: flutter
......@@ -51,13 +67,5 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
sdks:
dart: ">=3.1.0-185.0.dev <4.0.0"
dart: ">=3.2.0-0 <4.0.0"
name: puissance4
description: puissance4
publish_to: 'none'
version: 1.0.0+1
version: 1.0.17+18
environment:
sdk: '^3.0.0'
......@@ -10,5 +10,8 @@ dependencies:
flutter:
sdk: flutter
dev_dependencies:
flutter_lints: ^3.0.1
flutter:
uses-material-design: true
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment