From 339a428e0537d78e5d31baa6d5d11d4b825bed82 Mon Sep 17 00:00:00 2001 From: Levi Zitting Date: Sun, 6 Oct 2024 19:53:44 -0500 Subject: [PATCH] fix: flutter analyze issues (#4) * fix: flutter analysis options * feat: add gha to verify formatting and analysis options * fix: set flutter version in gha * fix: format command * fix: formatting issues * fix: create env.dart in gha * fix: add build script --- .github/workflows/lint-analyze.yml | 20 ++++++++++++++++ lib/providers/session_provider.dart | 6 ++--- lib/providers/sponsor_provider.dart | 6 ++--- lib/screens/not_found_screen.dart | 4 +--- lib/screens/report_screen.dart | 5 ++-- lib/screens/schedule_screen.dart | 2 +- lib/screens/session_feedback_screen.dart | 5 ++-- lib/screens/speaker_detail_screen.dart | 29 ++++++++++++++---------- lib/screens/sponsors_screen.dart | 8 ++++--- lib/utils/app_icons.dart | 18 +++++---------- lib/utils/utils.dart | 13 +++++++---- lib/widgets/app_banner.dart | 4 ++-- lib/widgets/app_list_item.dart | 3 ++- lib/widgets/app_navigation.dart | 4 ++-- lib/widgets/app_navigator.dart | 14 +++++------- lib/widgets/rating.dart | 4 ++-- lib/widgets/session_expansion_tile.dart | 5 ++-- pubspec.lock | 2 +- pubspec.yaml | 1 + 19 files changed, 90 insertions(+), 63 deletions(-) create mode 100644 .github/workflows/lint-analyze.yml diff --git a/.github/workflows/lint-analyze.yml b/.github/workflows/lint-analyze.yml new file mode 100644 index 0000000..2d50a03 --- /dev/null +++ b/.github/workflows/lint-analyze.yml @@ -0,0 +1,20 @@ +name: Lint & Analyze +on: + pull_request: + branches: + - main +jobs: + lint-analyze: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: flutter-actions/setup-flutter@v3 + with: + channel: stable + version: 3.24.3 + cache-sdk: true + - run: flutter pub get + - run: dart format --set-exit-if-changed . + - run: cp ./lib/env.dart.example ./lib/env.dart + - run: flutter pub run build_runner build --delete-conflicting-outputs + - run: flutter analyze diff --git a/lib/providers/session_provider.dart b/lib/providers/session_provider.dart index b36804f..2801b82 100644 --- a/lib/providers/session_provider.dart +++ b/lib/providers/session_provider.dart @@ -10,7 +10,7 @@ import 'package:method_conf_app/providers/speaker_provider.dart'; import 'package:method_conf_app/env.dart'; import 'package:method_conf_app/models/session.dart'; -const SESSIONS_KEY = 'app-sessions'; +const sessionsKey = 'app-sessions'; class SessionProvider extends ChangeNotifier { final SpeakerProvider? speakerProvider; @@ -72,7 +72,7 @@ class SessionProvider extends ChangeNotifier { var prefs = await SharedPreferences.getInstance(); sessions = prefs - .getStringList(SESSIONS_KEY) + .getStringList(sessionsKey) ?.map((s) => Session.fromJson(json.decode(s))) .toList() ?? []; @@ -100,7 +100,7 @@ class SessionProvider extends ChangeNotifier { var prefs = await SharedPreferences.getInstance(); var sessionsJson = sessions.map((s) => json.encode(s.toJson())).toList(); - await prefs.setStringList(SESSIONS_KEY, sessionsJson); + await prefs.setStringList(sessionsKey, sessionsJson); } Session? getSessionForSpeaker(Speaker? speaker) { diff --git a/lib/providers/sponsor_provider.dart b/lib/providers/sponsor_provider.dart index a69d37d..73eeeef 100644 --- a/lib/providers/sponsor_provider.dart +++ b/lib/providers/sponsor_provider.dart @@ -7,7 +7,7 @@ import 'package:http/http.dart' as http; import 'package:method_conf_app/env.dart'; import 'package:method_conf_app/models/sponsor.dart'; -const SPONSOR_KEY = 'app-sponsrs'; +const sponsorKey = 'app-sponsrs'; class SponsorProvider extends ChangeNotifier { bool _initialFetched = false; @@ -39,7 +39,7 @@ class SponsorProvider extends ChangeNotifier { var prefs = await SharedPreferences.getInstance(); sponsors = prefs - .getStringList(SPONSOR_KEY) + .getStringList(sponsorKey) ?.map((s) => Sponsor.fromJson(json.decode(s))) .toList() ?? []; @@ -65,6 +65,6 @@ class SponsorProvider extends ChangeNotifier { var prefs = await SharedPreferences.getInstance(); var sponsorsJson = sponsors.map((s) => json.encode(s.toJson())).toList(); - await prefs.setStringList(SPONSOR_KEY, sponsorsJson); + await prefs.setStringList(sponsorKey, sponsorsJson); } } diff --git a/lib/screens/not_found_screen.dart b/lib/screens/not_found_screen.dart index 73401ff..8cfb80f 100644 --- a/lib/screens/not_found_screen.dart +++ b/lib/screens/not_found_screen.dart @@ -9,9 +9,7 @@ class NotFoundScreen extends StatelessWidget { Widget build(BuildContext context) { return AppScreen( title: 'Not Found', - body: Container( - child: const Text('Not Found'), - ), + body: const Text('Not Found'), ); } } diff --git a/lib/screens/report_screen.dart b/lib/screens/report_screen.dart index 60d705a..c1ee53c 100644 --- a/lib/screens/report_screen.dart +++ b/lib/screens/report_screen.dart @@ -14,7 +14,7 @@ class ReportScreen extends StatefulWidget { const ReportScreen({super.key}); @override - _ReportScreenState createState() => _ReportScreenState(); + State createState() => _ReportScreenState(); } class _ReportScreenState extends State { @@ -142,7 +142,8 @@ class _ReportScreenState extends State { children: [ TextButton( style: TextButton.styleFrom( - padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15), + padding: const EdgeInsets.symmetric( + horizontal: 20, vertical: 15), backgroundColor: Colors.black, ), onPressed: _submitReport, diff --git a/lib/screens/schedule_screen.dart b/lib/screens/schedule_screen.dart index f03ebc5..10d7d9e 100644 --- a/lib/screens/schedule_screen.dart +++ b/lib/screens/schedule_screen.dart @@ -15,7 +15,7 @@ class ScheduleScreen extends StatefulWidget { const ScheduleScreen({super.key}); @override - _ScheduleScreenState createState() => _ScheduleScreenState(); + State createState() => _ScheduleScreenState(); } class _ScheduleScreenState extends State { diff --git a/lib/screens/session_feedback_screen.dart b/lib/screens/session_feedback_screen.dart index f577f57..613e142 100644 --- a/lib/screens/session_feedback_screen.dart +++ b/lib/screens/session_feedback_screen.dart @@ -17,7 +17,7 @@ class SessionFeedbackScreen extends StatefulWidget { const SessionFeedbackScreen({super.key}); @override - _SessionFeedbackScreenState createState() => _SessionFeedbackScreenState(); + State createState() => _SessionFeedbackScreenState(); } class _SessionFeedbackScreenState extends State { @@ -130,7 +130,8 @@ class _SessionFeedbackScreenState extends State { _submitFeedback(session); }, style: TextButton.styleFrom( - padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15), + padding: const EdgeInsets.symmetric( + horizontal: 20, vertical: 15), backgroundColor: Colors.black), child: const Text( 'SEND FEEDBACK', diff --git a/lib/screens/speaker_detail_screen.dart b/lib/screens/speaker_detail_screen.dart index 47895e6..3b962dd 100644 --- a/lib/screens/speaker_detail_screen.dart +++ b/lib/screens/speaker_detail_screen.dart @@ -39,7 +39,8 @@ class SpeakerDetailScreen extends StatelessWidget { Text( speaker.name, textAlign: TextAlign.left, - style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + style: const TextStyle( + fontSize: 20, fontWeight: FontWeight.bold), ), const SizedBox(height: 15), Row( @@ -49,14 +50,13 @@ class SpeakerDetailScreen extends StatelessWidget { child: CachedNetworkImage( imageUrl: speaker.image!, placeholder: (context, url) { - return Container( - child: const CircularProgressIndicator( - valueColor: - AlwaysStoppedAnimation(Colors.transparent), - ), + return const CircularProgressIndicator( + valueColor: + AlwaysStoppedAnimation(Colors.transparent), ); }, - errorWidget: (context, url, error) => const Icon(Icons.error), + errorWidget: (context, url, error) => + const Icon(Icons.error), ), ), const SizedBox(width: 20), @@ -98,35 +98,40 @@ class SpeakerDetailScreen extends StatelessWidget { icons.add(InkWell( // padding: EdgeInsets.all(0), onTap: () => launchUrl(speaker.twitterUrl!), - child: const Icon(AppIcons.twitter_logo, color: AppColors.accent, size: 35), + child: + const Icon(AppIcons.twitterLogo, color: AppColors.accent, size: 35), )); } if (speaker.twitter2Url != null) { icons.add(InkWell( onTap: () => launchUrl(speaker.twitter2Url!), - child: const Icon(AppIcons.twitter_logo, color: AppColors.accent, size: 35), + child: + const Icon(AppIcons.twitterLogo, color: AppColors.accent, size: 35), )); } if (speaker.linkedinUrl != null) { icons.add(InkWell( onTap: () => launchUrl(speaker.linkedinUrl!), - child: const Icon(AppIcons.linkedin_logo, color: AppColors.accent, size: 35), + child: const Icon(AppIcons.linkedInLogo, + color: AppColors.accent, size: 35), )); } if (speaker.githubUrl != null) { icons.add(InkWell( onTap: () => launchUrl(speaker.githubUrl!), - child: const Icon(AppIcons.github_logo, color: AppColors.accent, size: 35), + child: + const Icon(AppIcons.githubLogo, color: AppColors.accent, size: 35), )); } if (speaker.websiteURL != null) { icons.add(InkWell( onTap: () => launchUrl(speaker.websiteURL!), - child: const Icon(AppIcons.website_logo, color: AppColors.accent, size: 35), + child: + const Icon(AppIcons.websiteLogo, color: AppColors.accent, size: 35), )); } diff --git a/lib/screens/sponsors_screen.dart b/lib/screens/sponsors_screen.dart index f81775b..3a841f6 100644 --- a/lib/screens/sponsors_screen.dart +++ b/lib/screens/sponsors_screen.dart @@ -16,7 +16,7 @@ class SponsorsScreen extends StatefulWidget { const SponsorsScreen({super.key}); @override - _SponsorsScreenState createState() => _SponsorsScreenState(); + State createState() => _SponsorsScreenState(); } class _SponsorsScreenState extends State { @@ -89,10 +89,12 @@ class _SponsorsScreenState extends State { maxHeight: sponsor.mobileSponsor! ? 75 : 65, child: CachedNetworkImage( imageUrl: sponsor.image!, - placeholder: (context, url) => const CircularProgressIndicator( + placeholder: (context, url) => + const CircularProgressIndicator( valueColor: AlwaysStoppedAnimation(Colors.transparent), ), - errorWidget: (context, url, error) => const Icon(Icons.error), + errorWidget: (context, url, error) => + const Icon(Icons.error), ), ), ), diff --git a/lib/utils/app_icons.dart b/lib/utils/app_icons.dart index 3bdaae7..af3d781 100644 --- a/lib/utils/app_icons.dart +++ b/lib/utils/app_icons.dart @@ -6,16 +6,10 @@ class AppIcons { static const _kFontFam = 'AppIcons'; static const IconData hashtag = IconData(0xe800, fontFamily: _kFontFam); - static const IconData piggy_bank = - IconData(0xe801, fontFamily: _kFontFam); - static const IconData schedule = - IconData(0xe802, fontFamily: _kFontFam); - static const IconData github_logo = - IconData(0xe803, fontFamily: _kFontFam); - static const IconData linkedin_logo = - IconData(0xe804, fontFamily: _kFontFam); - static const IconData twitter_logo = - IconData(0xe805, fontFamily: _kFontFam); - static const IconData website_logo = - IconData(0xe806, fontFamily: _kFontFam); + static const IconData piggyBank = IconData(0xe801, fontFamily: _kFontFam); + static const IconData schedule = IconData(0xe802, fontFamily: _kFontFam); + static const IconData githubLogo = IconData(0xe803, fontFamily: _kFontFam); + static const IconData linkedInLogo = IconData(0xe804, fontFamily: _kFontFam); + static const IconData twitterLogo = IconData(0xe805, fontFamily: _kFontFam); + static const IconData websiteLogo = IconData(0xe806, fontFamily: _kFontFam); } diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 96e634a..df82eac 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -2,15 +2,20 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; -import 'package:url_launcher/url_launcher.dart'; +import 'package:url_launcher/url_launcher.dart' as url_launcher; import 'package:method_conf_app/theme.dart'; import 'package:method_conf_app/widgets/app_html.dart'; Future launchUrl(String url) async { - if (await canLaunch(url)) { - await launch(url, forceWebView: false, forceSafariVC: false); - return; + try { + final parsed = Uri.parse(url); + if (await url_launcher.canLaunchUrl(parsed)) { + await url_launcher.launchUrl(parsed); + return; + } + } catch (e) { + // ignore errors } Fluttertoast.showToast( diff --git a/lib/widgets/app_banner.dart b/lib/widgets/app_banner.dart index 7ff6004..77576d9 100644 --- a/lib/widgets/app_banner.dart +++ b/lib/widgets/app_banner.dart @@ -61,8 +61,8 @@ class AppBanner extends StatelessWidget { const SizedBox(height: 20), TextButton( style: TextButton.styleFrom( - padding: - const EdgeInsets.symmetric(horizontal: 20, vertical: 15), + padding: const EdgeInsets.symmetric( + horizontal: 20, vertical: 15), backgroundColor: Colors.black), onPressed: onButtonPress, child: Text( diff --git a/lib/widgets/app_list_item.dart b/lib/widgets/app_list_item.dart index 37b3fc5..6039fd1 100644 --- a/lib/widgets/app_list_item.dart +++ b/lib/widgets/app_list_item.dart @@ -35,7 +35,8 @@ class AppListItem extends StatelessWidget { children: [ Text( text, - style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + style: + const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), const Icon(Icons.chevron_right, size: 24), ], diff --git a/lib/widgets/app_navigation.dart b/lib/widgets/app_navigation.dart index 30cb617..c1283dc 100644 --- a/lib/widgets/app_navigation.dart +++ b/lib/widgets/app_navigation.dart @@ -18,7 +18,7 @@ class AppNavigation extends StatefulWidget { const AppNavigation({super.key}); @override - _AppNavigationState createState() => _AppNavigationState(); + State createState() => _AppNavigationState(); } class _AppNavigationState extends State { @@ -42,7 +42,7 @@ class _AppNavigationState extends State { ), _NavigationItem( route: '/partners', - item: _buildNavigationBarItem(AppIcons.piggy_bank, 'Partners'), + item: _buildNavigationBarItem(AppIcons.piggyBank, 'Partners'), ), _NavigationItem( route: '/more', diff --git a/lib/widgets/app_navigator.dart b/lib/widgets/app_navigator.dart index ab8f1fb..7e9bc44 100644 --- a/lib/widgets/app_navigator.dart +++ b/lib/widgets/app_navigator.dart @@ -9,7 +9,7 @@ class AppNavigator extends StatelessWidget { ); static final _navigatorKey = GlobalKey(); - final _RouteChangeCallBack? onRouteChange; + final RouteChangeCallBack? onRouteChange; final Map routes; final String initialRoute; final WidgetBuilder notFoundBuilder; @@ -24,14 +24,12 @@ class AppNavigator extends StatelessWidget { @override Widget build(BuildContext context) { - return WillPopScope( - onWillPop: () async { + return PopScope( + onPopInvokedWithResult: (_, __) { if (_navigatorKey.currentState!.canPop()) { _navigatorKey.currentState!.pop(); - return false; + return; } - - return true; }, child: Navigator( key: _navigatorKey, @@ -99,10 +97,10 @@ class AppNavigator extends StatelessWidget { } } -typedef _RouteChangeCallBack = void Function(Route? newRoute); +typedef RouteChangeCallBack = void Function(Route? newRoute); class _AppNavigationObserver extends NavigatorObserver { - final _RouteChangeCallBack onRouteChange; + final RouteChangeCallBack onRouteChange; _AppNavigationObserver({required this.onRouteChange}); diff --git a/lib/widgets/rating.dart b/lib/widgets/rating.dart index 920958c..0178bfe 100644 --- a/lib/widgets/rating.dart +++ b/lib/widgets/rating.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:method_conf_app/theme.dart'; class Rating extends StatelessWidget { - final _RatingSelectedCallback onSelected; + final RatingSelectedCallback onSelected; final int? currentValue; const Rating({ @@ -48,4 +48,4 @@ class Rating extends StatelessWidget { } } -typedef _RatingSelectedCallback = void Function(int value); +typedef RatingSelectedCallback = void Function(int value); diff --git a/lib/widgets/session_expansion_tile.dart b/lib/widgets/session_expansion_tile.dart index f1b25b8..62f725a 100644 --- a/lib/widgets/session_expansion_tile.dart +++ b/lib/widgets/session_expansion_tile.dart @@ -20,7 +20,7 @@ class SessionExpansionTile extends StatefulWidget { }); @override - _SessionExpansionTileState createState() => _SessionExpansionTileState(); + State createState() => _SessionExpansionTileState(); } class _SessionExpansionTileState extends State { @@ -99,7 +99,8 @@ class _SessionExpansionTileState extends State { Flexible( child: Text( widget.session.title, - style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + style: const TextStyle( + fontSize: 20, fontWeight: FontWeight.bold), ), ), const SizedBox( diff --git a/pubspec.lock b/pubspec.lock index b382abf..5cb032b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -367,7 +367,7 @@ packages: source: hosted version: "0.15.4" http: - dependency: transitive + dependency: "direct main" description: name: http sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010 diff --git a/pubspec.yaml b/pubspec.yaml index 7aeb41e..1fe5401 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,6 +47,7 @@ dependencies: cupertino_icons: ^1.0.8 collection: ^1.18.0 plausible_analytics: ^0.3.0 + http: ^1.2.2 dev_dependencies: flutter_test: