From e53456bf55d6803402727a70db4d0f13e6224637 Mon Sep 17 00:00:00 2001 From: Ricardo Dalarme Date: Thu, 12 Jan 2023 20:44:00 -0300 Subject: [PATCH] chore(lint): add flutter_lints And also fix all warnings --- analysis_options.yaml | 1 + example/lib/card_view.dart | 11 +++++----- example/lib/main.dart | 44 ++++++++++++++++++++------------------ example/pubspec.lock | 2 +- example/pubspec.yaml | 4 ++-- lib/stacked_cards.dart | 40 +++++++++++++++++++--------------- pubspec.lock | 16 +++++++++++++- pubspec.yaml | 1 + 8 files changed, 72 insertions(+), 47 deletions(-) create mode 100644 analysis_options.yaml diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..f9b3034 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1 @@ +include: package:flutter_lints/flutter.yaml diff --git a/example/lib/card_view.dart b/example/lib/card_view.dart index 83db97c..7abd527 100644 --- a/example/lib/card_view.dart +++ b/example/lib/card_view.dart @@ -22,7 +22,7 @@ class CardView extends StatelessWidget { ), SizedBox.expand( child: Container( - decoration: BoxDecoration( + decoration: const BoxDecoration( gradient: LinearGradient( colors: [Colors.transparent, Colors.black54], begin: Alignment.center, @@ -32,20 +32,21 @@ class CardView extends StatelessWidget { Align( alignment: Alignment.bottomLeft, child: Container( - padding: EdgeInsets.symmetric(vertical: 16.0, horizontal: 16.0), + padding: const EdgeInsets.symmetric( + vertical: 16.0, horizontal: 16.0), child: Column( mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(text, - style: TextStyle( + style: const TextStyle( color: Colors.white, fontSize: 20.0, fontWeight: FontWeight.w700)), - Padding(padding: EdgeInsets.only(bottom: 8.0)), + const Padding(padding: EdgeInsets.only(bottom: 8.0)), Text("$text details", textAlign: TextAlign.start, - style: TextStyle(color: Colors.white)), + style: const TextStyle(color: Colors.white)), ], )), ) diff --git a/example/lib/main.dart b/example/lib/main.dart index 3c932d2..ea4dc6d 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -3,10 +3,12 @@ import 'package:flutter/material.dart'; import 'package:stacked_cards/stacked_cards.dart'; void main() { - runApp(MyApp()); + runApp(const MyApp()); } class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { return MaterialApp( @@ -14,17 +16,17 @@ class MyApp extends StatelessWidget { theme: ThemeData( primarySwatch: Colors.blue, ), - home: MyHomePage(title: 'Flutter Demo Home Page'), + home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { - MyHomePage({Key? key, required this.title}) : super(key: key); + const MyHomePage({Key? key, required this.title}) : super(key: key); final String title; @override - _MyHomePageState createState() => _MyHomePageState(); + State createState() => _MyHomePageState(); } class _MyHomePageState extends State { @@ -33,7 +35,7 @@ class _MyHomePageState extends State { @override Widget build(BuildContext context) { //create a CardController - SwipeableCardSectionController _cardController = + SwipeableCardSectionController cardController = SwipeableCardSectionController(); return Scaffold( @@ -44,10 +46,10 @@ class _MyHomePageState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ SwipeableCardsSection( - cardController: _cardController, + cardController: cardController, context: context, //add the first 3 cards - items: [ + items: const [ CardView(text: "First card"), CardView(text: "Second card"), CardView(text: "Third card"), @@ -55,43 +57,43 @@ class _MyHomePageState extends State { onCardSwiped: (dir, index, widget) { //Add the next card if (counter <= 20) { - _cardController.addItem(CardView(text: "Card $counter")); + cardController.addItem(CardView(text: "Card $counter")); counter++; } if (dir == Direction.left) { - print('onDisliked ${(widget as CardView).text} $index'); + debugPrint('onDisliked ${(widget as CardView).text} $index'); } else if (dir == Direction.right) { - print('onLiked ${(widget as CardView).text} $index'); + debugPrint('onLiked ${(widget as CardView).text} $index'); } else if (dir == Direction.up) { - print('onUp ${(widget as CardView).text} $index'); + debugPrint('onUp ${(widget as CardView).text} $index'); } else if (dir == Direction.down) { - print('onDown ${(widget as CardView).text} $index'); + debugPrint('onDown ${(widget as CardView).text} $index'); } }, enableSwipeUp: true, enableSwipeDown: true, ), Container( - margin: EdgeInsets.symmetric(vertical: 20.0), + margin: const EdgeInsets.symmetric(vertical: 20.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ FloatingActionButton( - child: Icon(Icons.chevron_left), - onPressed: () => _cardController.triggerSwipeLeft(), + child: const Icon(Icons.chevron_left), + onPressed: () => cardController.triggerSwipeLeft(), ), FloatingActionButton( - child: Icon(Icons.chevron_right), - onPressed: () => _cardController.triggerSwipeRight(), + child: const Icon(Icons.chevron_right), + onPressed: () => cardController.triggerSwipeRight(), ), FloatingActionButton( - child: Icon(Icons.arrow_upward), - onPressed: () => _cardController.triggerSwipeUp(), + child: const Icon(Icons.arrow_upward), + onPressed: () => cardController.triggerSwipeUp(), ), FloatingActionButton( - child: Icon(Icons.arrow_downward), - onPressed: () => _cardController.triggerSwipeDown(), + child: const Icon(Icons.arrow_downward), + onPressed: () => cardController.triggerSwipeDown(), ), ], ), diff --git a/example/pubspec.lock b/example/pubspec.lock index 745e619..6e08c58 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -108,7 +108,7 @@ packages: source: hosted version: "1.10.0" stacked_cards: - dependency: "direct dev" + dependency: "direct main" description: path: ".." relative: true diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 1ce8ce7..6fb4a6c 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -24,6 +24,8 @@ dependencies: flutter: sdk: flutter + stacked_cards: + path: ../ # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. @@ -33,8 +35,6 @@ dev_dependencies: flutter_test: sdk: flutter - stacked_cards: - path: ../ # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/lib/stacked_cards.dart b/lib/stacked_cards.dart index b58a0ea..468aa14 100644 --- a/lib/stacked_cards.dart +++ b/lib/stacked_cards.dart @@ -12,7 +12,7 @@ const List cardsAlign = [ Alignment(0.0, 0.8), Alignment(0.0, 0.0) ]; -List cardsSize = List.filled(3, Size(1, 1)); +List cardsSize = List.filled(3, const Size(1, 1)); class SwipeableCardsSection extends StatefulWidget { final SwipeableCardSectionController? cardController; @@ -45,7 +45,7 @@ class SwipeableCardsSection extends StatefulWidget { this.appendItemCallback, this.enableSwipeUp = true, this.enableSwipeDown = true, - }) { + }) : super(key: key) { cardsSize[0] = Size(MediaQuery.of(context).size.width * cardWidthTopMul, MediaQuery.of(context).size.height * cardHeightTopMul); cardsSize[1] = Size(MediaQuery.of(context).size.width * cardWidthMiddleMul, @@ -55,7 +55,7 @@ class SwipeableCardsSection extends StatefulWidget { } @override - _CardsSectionState createState() => _CardsSectionState(); + State createState() => _CardsSectionState(); } class _CardsSectionState extends State @@ -68,7 +68,7 @@ class _CardsSectionState extends State late AnimationController _controller; bool enableSwipe = true; - final Alignment defaultFrontCardAlign = Alignment(0.0, 0.0); + final Alignment defaultFrontCardAlign = const Alignment(0.0, 0.0); Alignment frontCardAlign = cardsAlign[2]; double frontCardRot = 0.0; @@ -77,16 +77,16 @@ class _CardsSectionState extends State bool? shouldAnimate = false; if (dir == Direction.left) { shouldAnimate = swipedCallback(Direction.left, index, cards[0]); - frontCardAlign = Alignment(-0.001, 0.0); + frontCardAlign = const Alignment(-0.001, 0.0); } else if (dir == Direction.right) { shouldAnimate = swipedCallback(Direction.right, index, cards[0]); - frontCardAlign = Alignment(0.001, 0.0); + frontCardAlign = const Alignment(0.001, 0.0); } else if (dir == Direction.up) { shouldAnimate = swipedCallback(Direction.up, index, cards[0]); - frontCardAlign = Alignment(0.0, -0.001); + frontCardAlign = const Alignment(0.0, -0.001); } else if (dir == Direction.down) { shouldAnimate = swipedCallback(Direction.down, index, cards[0]); - frontCardAlign = Alignment(0.0, 0.001); + frontCardAlign = const Alignment(0.0, 0.001); } shouldAnimate ??= true; @@ -102,7 +102,7 @@ class _CardsSectionState extends State void _enableSwipe(bool isSwipeEnabled) { setState(() { - this.enableSwipe = isSwipeEnabled; + enableSwipe = isSwipeEnabled; }); } @@ -129,8 +129,8 @@ class _CardsSectionState extends State frontCardAlign = cardsAlign[2]; // Init the animation controller - _controller = - AnimationController(duration: Duration(milliseconds: 700), vsync: this); + _controller = AnimationController( + duration: const Duration(milliseconds: 700), vsync: this); _controller.addListener(() => setState(() {})); _controller.addStatusListener((AnimationStatus status) { if (status == AnimationStatus.completed) changeCardsOrder(); @@ -276,26 +276,30 @@ class CardsAnimation { AnimationController parent) { return AlignmentTween(begin: cardsAlign[0], end: cardsAlign[1]).animate( CurvedAnimation( - parent: parent, curve: Interval(0.4, 0.7, curve: Curves.easeIn))); + parent: parent, + curve: const Interval(0.4, 0.7, curve: Curves.easeIn))); } static Animation backCardSizeAnim(AnimationController parent) { return SizeTween(begin: cardsSize[2], end: cardsSize[1]).animate( CurvedAnimation( - parent: parent, curve: Interval(0.4, 0.7, curve: Curves.easeIn))); + parent: parent, + curve: const Interval(0.4, 0.7, curve: Curves.easeIn))); } static Animation middleCardAlignmentAnim( AnimationController parent) { return AlignmentTween(begin: cardsAlign[1], end: cardsAlign[2]).animate( CurvedAnimation( - parent: parent, curve: Interval(0.2, 0.5, curve: Curves.easeIn))); + parent: parent, + curve: const Interval(0.2, 0.5, curve: Curves.easeIn))); } static Animation middleCardSizeAnim(AnimationController parent) { return SizeTween(begin: cardsSize[1], end: cardsSize[0]).animate( CurvedAnimation( - parent: parent, curve: Interval(0.2, 0.5, curve: Curves.easeIn))); + parent: parent, + curve: const Interval(0.2, 0.5, curve: Curves.easeIn))); } static Animation frontCardDisappearAlignmentAnim( @@ -311,7 +315,8 @@ class CardsAnimation { 0.0) // Has swiped to the left or right? ) .animate(CurvedAnimation( - parent: parent, curve: Interval(0.0, 0.5, curve: Curves.easeIn))); + parent: parent, + curve: const Interval(0.0, 0.5, curve: Curves.easeIn))); } else { return AlignmentTween( begin: beginAlign, @@ -322,7 +327,8 @@ class CardsAnimation { : beginAlign.y - 30.0) // Has swiped to the top or bottom? ) .animate(CurvedAnimation( - parent: parent, curve: Interval(0.0, 0.5, curve: Curves.easeIn))); + parent: parent, + curve: const Interval(0.0, 0.5, curve: Curves.easeIn))); } } } diff --git a/pubspec.lock b/pubspec.lock index 2bdbfa4..4851002 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -48,11 +48,25 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + lints: + dependency: transitive + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" matcher: dependency: transitive description: @@ -136,5 +150,5 @@ packages: source: hosted version: "2.1.2" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=2.17.0 <3.0.0" flutter: ">=2.5.0" diff --git a/pubspec.yaml b/pubspec.yaml index d390c27..cb36ad6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,3 +14,4 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + flutter_lints: ^2.0.1