diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f9b303465f19b5fbf5ec669cd083c9cc38ecda9a --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1 @@ +include: package:flutter_lints/flutter.yaml diff --git a/android/app/build.gradle b/android/app/build.gradle index c730254fdbd9d49f51543939b8c028da9a4da7c3..7bc66beb821a28a738f5d86ae5886932f9e67581 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -44,7 +44,7 @@ android { defaultConfig { applicationId "org.benoitharrault.puissance4" - minSdkVersion 16 + minSdkVersion flutter.minSdkVersion targetSdkVersion 30 versionCode appVersionCode.toInteger() versionName appVersionName diff --git a/android/gradle.properties b/android/gradle.properties index a91025357c94cf0966f1c7beed2d8bb52e1bfabb..a6742fa6ef44a10a2e9382d30dbde8e2665f2c91 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ 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 diff --git a/fastlane/metadata/android/en-US/changelogs/18.txt b/fastlane/metadata/android/en-US/changelogs/18.txt new file mode 100644 index 0000000000000000000000000000000000000000..6ab11150150fc75a46c9acc317890208e5a120b9 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/18.txt @@ -0,0 +1 @@ +Add automatic flutter linter. Apply code lints. Update dependencies. diff --git a/fastlane/metadata/android/fr-FR/changelogs/18.txt b/fastlane/metadata/android/fr-FR/changelogs/18.txt new file mode 100644 index 0000000000000000000000000000000000000000..609f5cf6e95a8df0799865df2e1ebde8fa981e5a --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/18.txt @@ -0,0 +1 @@ +Ajout d'un correcteur automatique de code. Application des corrections. Mise à jour des dépendances. diff --git a/lib/board.dart b/lib/board.dart index 4502f08a237b134104ce4b0f304935b75c221405..01afbc3a2bf7c20b892c2a71162d05d05947b6e4 100644 --- a/lib/board.dart +++ b/lib/board.dart @@ -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) || diff --git a/lib/cpu.dart b/lib/cpu.dart index 7f91cf9445106aba094d3c6c0c14df873a0f3075..ff842ed17d89a412f7501e70599f33696768909f 100644 --- a/lib/cpu.dart +++ b/lib/cpu.dart @@ -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 { diff --git a/lib/cpu_level_page.dart b/lib/cpu_level_page.dart index 579158f7fbbef265c5f315fb364e47ce9cdfd0cf..d12af0c477041bb27c629a8ad55a5c60d4cb5741 100644 --- a/lib/cpu_level_page.dart +++ b/lib/cpu_level_page.dart @@ -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), }, ); }, diff --git a/lib/game_chip.dart b/lib/game_chip.dart index 65178cfa51503d63248f354e71b60dc589d42121..57effbab7f9709cab50ff648bddac35cc60a5091 100644 --- a/lib/game_chip.dart +++ b/lib/game_chip.dart @@ -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, ), ), ); diff --git a/lib/home_page.dart b/lib/home_page.dart index 1db42a57d616fa9a285e63e2cfcf8e4c5603828b..6613982ce1a213521a066c634e98d3688d4b3bfe 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -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), }, diff --git a/lib/main.dart b/lib/main.dart index 09f7a1e6585f2a03598dbf558883a6d0a31760fe..e2785b8e832528a9cfc3a5ac90033fc6317ed19d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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(), ); } diff --git a/lib/match_page.dart b/lib/match_page.dart index e18dbae318a0962d18a5c2902075f97394ae6545..66b498ba8948718bd38e02789e468c55fdd9aa5a 100644 --- a/lib/match_page.dart +++ b/lib/match_page.dart @@ -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(); - }); - } } diff --git a/pubspec.lock b/pubspec.lock index 840facd49f1f6229901553dc7572be696edf845b..df2772b134cd0e2dc7cb0ed027cea68828810918 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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" diff --git a/pubspec.yaml b/pubspec.yaml index 885659647d0c1c35f009e8bb9e19e59402a018f5..c047f07550dc3210eda34541e93280b5dd73b720 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ 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