From 14e4496de4138c317791030215803e7d57ec85bc Mon Sep 17 00:00:00 2001 From: davidpkj Date: Sun, 5 Mar 2023 13:05:25 +0100 Subject: Refactored according to flutter lint --- lib/main.dart | 30 +++++++++++++++--------------- lib/models/data/recipe_data_class.dart | 9 ++++----- lib/models/recipe_class.dart | 20 ++++++++++---------- lib/util/file_handler.dart | 4 ++-- lib/views/favorites_view.dart | 10 +++++----- lib/views/file_info.dart | 10 +++++----- lib/views/image_view.dart | 18 ++++++++---------- lib/views/info_view.dart | 19 ++++++++++--------- lib/views/main_view.dart | 16 ++++++++-------- lib/views/recipe_view.dart | 24 ++++++++++++------------ lib/views/settings_view.dart | 20 ++++++++++---------- lib/views/shoplist_view.dart | 10 +++++----- lib/views/vote_view.dart | 8 ++++---- lib/views/week_view.dart | 27 ++++++++++----------------- lib/widgets/custom_drawer_widget.dart | 30 +++++++++++++++--------------- lib/widgets/custom_markdown_style.dart | 26 +++++++++++++------------- lib/widgets/error_widgets.dart | 6 +++--- lib/widgets/page_route_transitions.dart | 20 ++++++++++---------- lib/widgets/recipe_card_widget.dart | 16 ++++++++-------- lib/widgets/recipe_search_delegate.dart | 12 ++++++------ lib/widgets/toastbar_widget.dart | 4 ++-- lib/widgets/utility_icon_row_widget.dart | 18 +++++++++--------- 22 files changed, 174 insertions(+), 183 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index f7b3aca..b583f5c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -17,7 +17,7 @@ void main() async { const AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings("@mipmap/notification_icon"); - final InitializationSettings initializationSettings = + const InitializationSettings initializationSettings = InitializationSettings(android: initializationSettingsAndroid); await Notifications.flutterLocalNotificationsPlugin .initialize(initializationSettings); @@ -26,40 +26,40 @@ void main() async { await SettingsData.load(); await ShoplistData.load(); - runApp(AppRoot()); + runApp(const AppRoot()); } class AppRoot extends StatefulWidget { const AppRoot({Key? key}) : super(key: key); @override - _AppRootState createState() => _AppRootState(); + AppRootState createState() => AppRootState(); } -class _AppRootState extends State { +class AppRootState extends State { @override Widget build(BuildContext context) { - SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( + SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle( statusBarColor: cPrimaryColor, statusBarIconBrightness: Brightness.light, )); return MaterialApp( debugShowCheckedModeBanner: false, - localizationsDelegates: [ + localizationsDelegates: const [ AppLocalizations.delegate, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], - supportedLocales: [ - const Locale('de', ''), - const Locale('en', ''), - const Locale('ru', ''), + supportedLocales: const [ + Locale('de', ''), + Locale('en', ''), + Locale('ru', ''), ], theme: themeData(), title: "Kulinar", - home: MainView(), + home: const MainView(), ); } @@ -67,13 +67,13 @@ class _AppRootState extends State { return ThemeData( brightness: Brightness.light, primarySwatch: cPrimarySwatchColor, - textSelectionTheme: TextSelectionThemeData( + textSelectionTheme: const TextSelectionThemeData( cursorColor: cIconColor, ), - inputDecorationTheme: InputDecorationTheme( + inputDecorationTheme: const InputDecorationTheme( hintStyle: cSearchTextStyle, ), - appBarTheme: AppBarTheme( + appBarTheme: const AppBarTheme( actionsIconTheme: IconThemeData(color: cIconColor), titleTextStyle: cTitleStyle, toolbarTextStyle: cTitleStyle, @@ -81,7 +81,7 @@ class _AppRootState extends State { centerTitle: true, elevation: 10.0, ), - buttonTheme: ButtonThemeData( + buttonTheme: const ButtonThemeData( buttonColor: cPrimaryColor, ), ); diff --git a/lib/models/data/recipe_data_class.dart b/lib/models/data/recipe_data_class.dart index 3984ac6..3193b7d 100644 --- a/lib/models/data/recipe_data_class.dart +++ b/lib/models/data/recipe_data_class.dart @@ -2,24 +2,23 @@ import 'dart:convert'; import 'package:kulinar_app/models/recipe_class.dart'; import 'package:kulinar_app/util/isar_handler.dart'; -import 'package:kulinar_app/util/storage_handler.dart'; class RecipeData { static List remoteRecipeList = []; static List recipeList = []; static Future save() async { - recipeList.forEach((recipe) { + for (Recipe recipe in recipeList) { IsarHandler().save(recipe); - }); + } } static Future load() async { List list = await IsarHandler().load(); - list.forEach((recipe) { + for (Recipe? recipe in list) { recipeList.add(recipe!); - }); + } } static String encode() { diff --git a/lib/models/recipe_class.dart b/lib/models/recipe_class.dart index e02ed87..7143547 100644 --- a/lib/models/recipe_class.dart +++ b/lib/models/recipe_class.dart @@ -20,7 +20,7 @@ class Recipe { List _list = remote ? RecipeData.remoteRecipeList : RecipeData.recipeList; for (Recipe recipe in _list) { - if (this.title == recipe.title && this.image == recipe.image && this.description == recipe.description) { + if (title == recipe.title && image == recipe.image && description == recipe.description) { return true; } } @@ -29,24 +29,24 @@ class Recipe { } bool isDefault() { - if (this.title != null) return false; - if (this.image != null) return false; - if (this.description != null) return false; - if (this.favorite != false) return false; - if (this.rating != 0) return false; + if (title != null) return false; + if (image != null) return false; + if (description != null) return false; + if (favorite != false) return false; + if (rating != 0) return false; return true; } void toggleFavorite() { - this.favorite = !this.favorite; + favorite = !favorite; } void updateRating() { - if (this.rating == 5) { - this.rating = 0; + if (rating == 5) { + rating = 0; } else { - this.rating++; + rating++; } } } diff --git a/lib/util/file_handler.dart b/lib/util/file_handler.dart index db1d725..d6b909d 100644 --- a/lib/util/file_handler.dart +++ b/lib/util/file_handler.dart @@ -35,7 +35,7 @@ class FileHandler { ToastBar.showToastBar(context, AppLocalizations.of(context)!.exportSuccess, actionLabel: ""); Notifications.notify(AppLocalizations.of(context)!.exportSuccess, AppLocalizations.of(context)!.tapHint, _file.path); } catch (e) { - print(e); + debugPrint("$e"); ToastBar.showToastBar(context, AppLocalizations.of(context)!.exportError, actionLabel: ""); } } @@ -80,7 +80,7 @@ class FileHandler { return File(result.files.single.path!); } } catch (e) { - print(e); + debugPrint("$e"); ToastBar.showToastBar(context, AppLocalizations.of(context)!.importError, actionLabel: ""); } } diff --git a/lib/views/favorites_view.dart b/lib/views/favorites_view.dart index bb0f7fb..97f784c 100644 --- a/lib/views/favorites_view.dart +++ b/lib/views/favorites_view.dart @@ -14,17 +14,17 @@ class FavoritesView extends StatefulWidget { const FavoritesView({Key? key}) : super(key: key); @override - _FavoritesViewState createState() => _FavoritesViewState(); + FavoritesViewState createState() => FavoritesViewState(); } -class _FavoritesViewState extends State { +class FavoritesViewState extends State { BuildContext? _toastyContext; @override Widget build(BuildContext context) { return Scaffold( appBar: _buildAppBar(context), - drawer: CustomDrawer(initalIndex: 1), + drawer: const CustomDrawer(initialIndex: 1), body: Container( width: double.infinity, child: Builder( @@ -51,7 +51,7 @@ class _FavoritesViewState extends State { title: Text(AppLocalizations.of(context)!.category4), actions: [ IconButton( - icon: Icon(Icons.search), + icon: const Icon(Icons.search), onPressed: () async { await showSearch( context: context, @@ -68,7 +68,7 @@ class _FavoritesViewState extends State { Widget _buildListView() { List _filteredRecipeList = RecipeData.recipeList.where((element) => element.favorite).toList(); - if (_filteredRecipeList.isEmpty) return NoContentError(); + if (_filteredRecipeList.isEmpty) return const NoContentError(); return ListView.builder( itemCount: _filteredRecipeList.length, diff --git a/lib/views/file_info.dart b/lib/views/file_info.dart index e032716..28c45f9 100644 --- a/lib/views/file_info.dart +++ b/lib/views/file_info.dart @@ -9,15 +9,15 @@ import 'package:kulinar_app/widgets/error_widgets.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class FileInfo extends StatefulWidget { - FileInfo({Key? key, required this.filePath}) : super(key: key); + const FileInfo({Key? key, required this.filePath}) : super(key: key); final String filePath; @override - _FileInfoState createState() => _FileInfoState(); + FileInfoState createState() => FileInfoState(); } -class _FileInfoState extends State { +class FileInfoState extends State { @override Widget build(BuildContext context) { final File _file = File(widget.filePath.split(":")[1]); @@ -27,8 +27,8 @@ class _FileInfoState extends State { body: FutureBuilder( future: FileHandler.deserializeFileInformation(_file), builder: (BuildContext context, AsyncSnapshot> snapshot) { - if (snapshot.connectionState != ConnectionState.done) return CircularProgressIndicator(); - if (snapshot.hasError || !snapshot.hasData) return UnknownError(); + if (snapshot.connectionState != ConnectionState.done) return const CircularProgressIndicator(); + if (snapshot.hasError || !snapshot.hasData) return const UnknownError(); return _buildFileInfoTable(_getSortedSnapshotData(snapshot), _file); }, diff --git a/lib/views/image_view.dart b/lib/views/image_view.dart index 615aa26..1363268 100644 --- a/lib/views/image_view.dart +++ b/lib/views/image_view.dart @@ -15,18 +15,16 @@ class ImageView extends StatelessWidget { child: Scaffold( backgroundColor: _averageImageColor(image), body: Center( - child: Container( - child: GestureDetector( - child: Hero( - tag: "image", - child: Image( - image: FileImage(File(image)), - ), + child: GestureDetector( + child: Hero( + tag: "image", + child: Image( + image: FileImage(File(image)), ), - onTap: () { - Navigator.pop(context); - }, ), + onTap: () { + Navigator.pop(context); + }, ), ), ), diff --git a/lib/views/info_view.dart b/lib/views/info_view.dart index bda2d14..0d0897d 100644 --- a/lib/views/info_view.dart +++ b/lib/views/info_view.dart @@ -10,10 +10,10 @@ class InfoView extends StatefulWidget { const InfoView({Key? key}) : super(key: key); @override - _InfoViewState createState() => _InfoViewState(); + InfoViewState createState() => InfoViewState(); } -class _InfoViewState extends State { +class InfoViewState extends State { String name = "David Penkowoj"; String websiteURL = "https://davidpenkowoj.de"; String sourceCodeURL = "https://git.davidpenkowoj.de/kulinar_app.git"; @@ -23,7 +23,7 @@ class _InfoViewState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text(AppLocalizations.of(context)!.category9)), - drawer: CustomDrawer(initalIndex: 6), + drawer: const CustomDrawer(initialIndex: 6), body: ListView( children: [ Padding( @@ -32,7 +32,7 @@ class _InfoViewState extends State { ), ListTile( title: Text(AppLocalizations.of(context)!.info1, style: cDefaultTextStyle), - subtitle: Text(cVersion, style: cDetailsTextStyle), + subtitle: const Text(cVersion, style: cDetailsTextStyle), ), ListTile( title: Text(AppLocalizations.of(context)!.info2, style: cDefaultTextStyle), @@ -42,7 +42,7 @@ class _InfoViewState extends State { title: Text(AppLocalizations.of(context)!.info3, style: cDefaultTextStyle), subtitle: Text(websiteURL, style: cDetailsTextStyle, overflow: TextOverflow.ellipsis), trailing: IconButton( - icon: Icon(Icons.north_east_rounded), + icon: const Icon(Icons.north_east_rounded), onPressed: () { _launchURL(Uri.parse(websiteURL)); }, @@ -52,7 +52,7 @@ class _InfoViewState extends State { title: Text(AppLocalizations.of(context)!.info4, style: cDefaultTextStyle), subtitle: Text(sourceCodeURL, style: cDetailsTextStyle, overflow: TextOverflow.ellipsis), trailing: IconButton( - icon: Icon(Icons.north_east_rounded), + icon: const Icon(Icons.north_east_rounded), onPressed: () { _launchURL(Uri.parse(sourceCodeURL)); }, @@ -62,7 +62,7 @@ class _InfoViewState extends State { title: Text(AppLocalizations.of(context)!.info5, style: cDefaultTextStyle), subtitle: Text(privacyNoticeURL, style: cDetailsTextStyle, overflow: TextOverflow.ellipsis), trailing: IconButton( - icon: Icon(Icons.north_east_rounded), + icon: const Icon(Icons.north_east_rounded), onPressed: () { _launchURL(Uri.parse(privacyNoticeURL)); }, @@ -71,7 +71,7 @@ class _InfoViewState extends State { ListTile( title: Text(AppLocalizations.of(context)!.info6, style: cDefaultTextStyle), trailing: IconButton( - icon: Icon(Icons.launch_rounded), + icon: const Icon(Icons.launch_rounded), onPressed: () { _showDialog(); }, @@ -95,7 +95,8 @@ class _InfoViewState extends State { if (await canLaunchUrl(url)) { await launchUrl(url, mode: LaunchMode.externalApplication); } else { - print('Could not launch $url'); + debugPrint("Could not launch $url"); + // TODO: maybe add toastbar } } } diff --git a/lib/views/main_view.dart b/lib/views/main_view.dart index 759e423..3db3e97 100644 --- a/lib/views/main_view.dart +++ b/lib/views/main_view.dart @@ -19,11 +19,11 @@ class MainView extends StatefulWidget { const MainView({Key? key}) : super(key: key); @override - _MainViewState createState() => _MainViewState(); + MainViewState createState() => MainViewState(); } -class _MainViewState extends State with SingleTickerProviderStateMixin, WidgetsBindingObserver { - static const platform = const MethodChannel("com.davidpenkowoj.kulinar.openfile"); +class MainViewState extends State with SingleTickerProviderStateMixin, WidgetsBindingObserver { + static const platform = MethodChannel("com.davidpenkowoj.kulinar.openfile"); TabController? _tabController; BuildContext? _toastyContext; @@ -55,7 +55,7 @@ class _MainViewState extends State with SingleTickerProviderStateMixin Widget build(BuildContext context) { return Scaffold( appBar: _buildAppBar(context, _tabController!), - drawer: CustomDrawer(initalIndex: 0), + drawer: const CustomDrawer(initialIndex: 0), floatingActionButton: _buildFloatingActionButton(), body: Builder(builder: (BuildContext context) { _toastyContext = context; @@ -87,11 +87,11 @@ class _MainViewState extends State with SingleTickerProviderStateMixin Widget _buildFloatingActionButton() { return FloatingActionButton( - child: Icon(Icons.add, color: cIconColor), + child: const Icon(Icons.add, color: cIconColor), onPressed: () async { await Navigator.push( context, - SlideFromBottomRoute(child: RecipeView()), + SlideFromBottomRoute(child: const RecipeView()), ); setState(() {}); @@ -100,7 +100,7 @@ class _MainViewState extends State with SingleTickerProviderStateMixin } Widget _buildListView(List filteredRecipeList) { - if (filteredRecipeList.isEmpty) return NoContentError(); + if (filteredRecipeList.isEmpty) return const NoContentError(); return ListView.builder( itemCount: filteredRecipeList.length, @@ -113,7 +113,7 @@ class _MainViewState extends State with SingleTickerProviderStateMixin title: Text(AppLocalizations.of(context)!.category1), actions: [ IconButton( - icon: Icon( + icon: const Icon( Icons.search, ), onPressed: () async { diff --git a/lib/views/recipe_view.dart b/lib/views/recipe_view.dart index f512770..faaa0ca 100644 --- a/lib/views/recipe_view.dart +++ b/lib/views/recipe_view.dart @@ -28,10 +28,10 @@ class RecipeView extends StatefulWidget { final Function? showToastCallback; @override - _RecipeViewState createState() => _RecipeViewState(); + RecipeViewState createState() => RecipeViewState(); } -class _RecipeViewState extends State { +class RecipeViewState extends State { final GlobalKey _formKey = GlobalKey(); final GlobalKey _scaffoldKey = GlobalKey(); final TextEditingController _controller1 = TextEditingController(); @@ -170,7 +170,7 @@ class _RecipeViewState extends State { Widget _buildUtilityRow() { if (widget.remote) { - return SizedBox( + return const SizedBox( height: 10.0, width: double.infinity, ); @@ -248,11 +248,11 @@ class _RecipeViewState extends State { Widget _buildDescriptionInput() { return Padding( padding: const EdgeInsets.all(18.0), - child: _isEditModeEnabled ? _buildInputDescriptuion() : _buildMarkdownDescription(), + child: _isEditModeEnabled ? _buildInputDescription() : _buildMarkdownDescription(), ); } - TextField _buildInputDescriptuion() { + TextField _buildInputDescription() { return TextField( expands: true, maxLines: null, @@ -263,7 +263,7 @@ class _RecipeViewState extends State { focusNode: _detailsTextFocus, style: cRecipeDescriptionStyle, enableInteractiveSelection: true, - toolbarOptions: ToolbarOptions( + toolbarOptions: const ToolbarOptions( copy: true, cut: true, paste: true, @@ -276,7 +276,7 @@ class _RecipeViewState extends State { return MarkdownBody( data: _controller2.text, selectable: true, - onTapLink: (text, href, title) => null, + onTapLink: (text, href, title) => {}, imageBuilder: (uri, title, alt) => Container(), // styleSheet: CustomMarkdownStyle(), ); @@ -333,7 +333,7 @@ class _RecipeViewState extends State { List _remoteDownloadAction = [ IconButton( - icon: Icon(Icons.save_alt_rounded), + icon: const Icon(Icons.save_alt_rounded), onPressed: () { downloadRecipe(context, recipe); }, @@ -341,7 +341,7 @@ class _RecipeViewState extends State { ]; List _remoteLookupAction = [ - IconButton( + const IconButton( icon: Icon(Icons.menu_open_rounded), onPressed: null, ), @@ -361,7 +361,7 @@ class _RecipeViewState extends State { return AppBar( title: Text(_title), leading: IconButton( - icon: Icon(Icons.close), + icon: const Icon(Icons.close), onPressed: () { Navigator.pop(context); }, @@ -373,12 +373,12 @@ class _RecipeViewState extends State { Widget _buildAppBarCheckActions() { if (_isEditModeEnabled) { return IconButton( - icon: Icon(Icons.check), + icon: const Icon(Icons.check), onPressed: _addRecipe, ); } else { return IconButton( - icon: Icon(Icons.edit), + icon: const Icon(Icons.edit), onPressed: () { _isEditModeEnabled = true; diff --git a/lib/views/settings_view.dart b/lib/views/settings_view.dart index 367c1a6..7268acf 100644 --- a/lib/views/settings_view.dart +++ b/lib/views/settings_view.dart @@ -12,10 +12,10 @@ class SettingsView extends StatefulWidget { const SettingsView({Key? key}) : super(key: key); @override - _SettingsViewState createState() => _SettingsViewState(); + SettingsViewState createState() => SettingsViewState(); } -class _SettingsViewState extends State { +class SettingsViewState extends State { final TextEditingController _controller = TextEditingController(); final FocusNode _focusNode = FocusNode(); @@ -29,7 +29,7 @@ class _SettingsViewState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text(AppLocalizations.of(context)!.category8)), - drawer: CustomDrawer(initalIndex: 5), + drawer: const CustomDrawer(initialIndex: 5), body: Builder( builder: (BuildContext context) => ListView( children: [ @@ -54,7 +54,7 @@ class _SettingsViewState extends State { ListTile( title: Text(AppLocalizations.of(context)!.setting22, style: cDefaultTextStyle), subtitle: Text(AppLocalizations.of(context)!.explanation3, style: cDetailsTextStyle), - trailing: IconButton( + trailing: const IconButton( icon: Icon(Icons.arrow_forward_rounded), onPressed: null, ), @@ -134,12 +134,12 @@ class _SettingsViewState extends State { value: int.parse(SettingsData.settings["photoSource"]!), items: [ DropdownMenuItem( - child: Text(AppLocalizations.of(context)!.option111, style: cOptionTextStyle), value: 0, + child: Text(AppLocalizations.of(context)!.option111, style: cOptionTextStyle), ), DropdownMenuItem( - child: Text(AppLocalizations.of(context)!.option112, style: cOptionTextStyle), value: 1, + child: Text(AppLocalizations.of(context)!.option112, style: cOptionTextStyle), ), ], onChanged: (value) { @@ -156,20 +156,20 @@ class _SettingsViewState extends State { value: int.parse(SettingsData.settings["showPhotos"]!), items: [ DropdownMenuItem( - child: Text(AppLocalizations.of(context)!.option211, style: cOptionTextStyle), value: 0, + child: Text(AppLocalizations.of(context)!.option211, style: cOptionTextStyle), ), DropdownMenuItem( - child: Text(AppLocalizations.of(context)!.option212, style: cOptionTextStyle), value: 1, + child: Text(AppLocalizations.of(context)!.option212, style: cOptionTextStyle), ), DropdownMenuItem( - child: Text(AppLocalizations.of(context)!.option213, style: cOptionTextStyle), value: 2, + child: Text(AppLocalizations.of(context)!.option213, style: cOptionTextStyle), ), DropdownMenuItem( - child: Text(AppLocalizations.of(context)!.option214, style: cOptionTextStyle), value: 3, + child: Text(AppLocalizations.of(context)!.option214, style: cOptionTextStyle), ), ], onChanged: (value) { diff --git a/lib/views/shoplist_view.dart b/lib/views/shoplist_view.dart index 500b8fc..e13ef21 100644 --- a/lib/views/shoplist_view.dart +++ b/lib/views/shoplist_view.dart @@ -14,10 +14,10 @@ class ShoplistView extends StatefulWidget { const ShoplistView({Key? key}) : super(key: key); @override - _ShoplistView createState() => _ShoplistView(); + ShoplistViewState createState() => ShoplistViewState(); } -class _ShoplistView extends State { +class ShoplistViewState extends State { final FocusNode _focusNode = FocusNode(); final TextEditingController _controller = TextEditingController(); final GlobalKey _scaffoldKey = GlobalKey(); @@ -30,7 +30,7 @@ class _ShoplistView extends State { return Scaffold( key: _scaffoldKey, appBar: AppBar(title: Text(AppLocalizations.of(context)!.category7)), - drawer: CustomDrawer(initalIndex: 4), + drawer: const CustomDrawer(initialIndex: 4), floatingActionButton: _buildFloatingActionButton(), body: _buildAnimatedList(), ); @@ -54,14 +54,14 @@ class _ShoplistView extends State { // TODO: FIXME: Sometimes exception "cant call insertItem of null" is thrown when first item is added or last is removed Widget _buildAnimatedList() { - if (ShoplistData.shoplist.length == 0) return NoContentError(); + if (ShoplistData.shoplist.isEmpty) return const NoContentError(); return AnimatedList( key: _listKey, initialItemCount: ShoplistData.shoplist.length, itemBuilder: (BuildContext context, int index, Animation animation) { return SlideTransition( - position: animation.drive(Tween(begin: Offset(1.0, 0.0), end: Offset(0.0, 0.0))), + position: animation.drive(Tween(begin: const Offset(1.0, 0.0), end: const Offset(0.0, 0.0))), child: Dismissible( key: Key(_getUniqueKeyString(ShoplistData.shoplist[index])), background: _buildDimissibleBackground(true), diff --git a/lib/views/vote_view.dart b/lib/views/vote_view.dart index 86ddc0b..9c5721e 100644 --- a/lib/views/vote_view.dart +++ b/lib/views/vote_view.dart @@ -9,16 +9,16 @@ class VoteView extends StatefulWidget { const VoteView({Key? key}) : super(key: key); @override - _VoteViewState createState() => _VoteViewState(); + VoteViewState createState() => VoteViewState(); } -class _VoteViewState extends State { +class VoteViewState extends State { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text(AppLocalizations.of(context)!.category6)), - drawer: CustomDrawer(initalIndex: 3), - body: NoContentError(), + drawer: const CustomDrawer(initialIndex: 3), + body: const NoContentError(), ); } } diff --git a/lib/views/week_view.dart b/lib/views/week_view.dart index 23d71b8..de6ebcf 100644 --- a/lib/views/week_view.dart +++ b/lib/views/week_view.dart @@ -1,12 +1,7 @@ -import 'dart:convert'; - import 'package:flutter/material.dart'; -import 'package:kulinar_app/models/recipe_class.dart'; import 'package:kulinar_app/widgets/error_widgets.dart'; -import 'package:kulinar_app/widgets/recipe_card_widget.dart'; import 'package:kulinar_app/widgets/custom_drawer_widget.dart'; -import 'package:kulinar_app/models/data/recipe_data_class.dart'; import 'package:kulinar_app/models/data/settings_data_class.dart'; import 'package:http/http.dart'; @@ -16,19 +11,19 @@ class WeekView extends StatefulWidget { const WeekView({Key? key}) : super(key: key); @override - _WeekViewState createState() => _WeekViewState(); + WeekViewState createState() => WeekViewState(); } -class _WeekViewState extends State { +class WeekViewState extends State { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text(AppLocalizations.of(context)!.category5)), - drawer: CustomDrawer(initalIndex: 2), + drawer: const CustomDrawer(initialIndex: 2), body: FutureBuilder( future: _getWeeklyRecipes(), builder: (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.connectionState != ConnectionState.done) return LinearProgressIndicator(); + if (snapshot.connectionState != ConnectionState.done) return const LinearProgressIndicator(); if (snapshot.hasError || !snapshot.hasData) return NetworkContentError(refreshCallback: _retry); return RefreshIndicator( @@ -36,7 +31,7 @@ class _WeekViewState extends State { setState(() {}); }, child: ListView( - children: [ + children: const [ Text("Not implemented"), // TODO: Not implemented ], ), @@ -50,21 +45,19 @@ class _WeekViewState extends State { Map _headers = {"Content-Type": "application/json; charset=UTF-8"}; try { - return await Future.delayed(Duration(milliseconds: 500), () { - print(SettingsData.settings["serverURL"]); + return await Future.delayed(const Duration(milliseconds: 500), () { + debugPrint("${SettingsData.settings['serverURL']}"); return get(Uri.https(SettingsData.settings["serverURL"]!, "/weekly"), headers: _headers); }); } catch (e) { - print(e); + debugPrint("$e"); return null; } } - Future _retry() async { - await Future.delayed(Duration(milliseconds: 300)); + Future _retry() async { + await Future.delayed(const Duration(milliseconds: 300)); setState(() {}); - - return null; } } diff --git a/lib/widgets/custom_drawer_widget.dart b/lib/widgets/custom_drawer_widget.dart index 3fd8c2e..671ff70 100644 --- a/lib/widgets/custom_drawer_widget.dart +++ b/lib/widgets/custom_drawer_widget.dart @@ -14,21 +14,21 @@ import 'package:kulinar_app/widgets/page_route_transitions.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class CustomDrawer extends StatefulWidget { - CustomDrawer({Key? key, required this.initalIndex}) : super(key: key); + const CustomDrawer({Key? key, required this.initialIndex}) : super(key: key); - final int initalIndex; + final int initialIndex; @override - _CustomDrawerState createState() => _CustomDrawerState(); + CustomDrawerState createState() => CustomDrawerState(); } -class _CustomDrawerState extends State { +class CustomDrawerState extends State { int? _index; @override void initState() { super.initState(); - _index = widget.initalIndex; + _index = widget.initialIndex; } @override @@ -46,28 +46,28 @@ class _CustomDrawerState extends State { children: [ _buildDrawerHeader(), _buildDrawerItem(0, Icons.receipt_rounded, AppLocalizations.of(context)!.category1, () { - _navigateTo(MainView(), 0); + _navigateTo(const MainView(), 0); }), _buildDrawerItem(1, Icons.favorite_rounded, AppLocalizations.of(context)!.category4, () { - _navigateTo(FavoritesView(), 1); + _navigateTo(const FavoritesView(), 1); }), _buildDrawerItem(2, Icons.calendar_today_rounded, AppLocalizations.of(context)!.category5, () { - _navigateTo(WeekView(), 2); + _navigateTo(const WeekView(), 2); }), _buildDrawerItem(3, Icons.how_to_vote_rounded, AppLocalizations.of(context)!.category6, () { - _navigateTo(VoteView(), 3); + _navigateTo(const VoteView(), 3); }), _buildDrawerItem(4, Icons.shopping_cart_rounded, AppLocalizations.of(context)!.category7, () { - _navigateTo(ShoplistView(), 4); + _navigateTo(const ShoplistView(), 4); }), ], ), ), _buildDrawerItem(5, Icons.settings_rounded, AppLocalizations.of(context)!.category8, () { - _navigateTo(SettingsView(), 5); + _navigateTo(const SettingsView(), 5); }), _buildDrawerItem(6, Icons.info_rounded, AppLocalizations.of(context)!.category9, () { - _navigateTo(InfoView(), 6); + _navigateTo(const InfoView(), 6); }), ], ), @@ -75,16 +75,17 @@ class _CustomDrawerState extends State { } Widget _buildDrawerHeader() { - return SizedBox( + return const SizedBox( width: double.infinity, child: DrawerHeader( margin: EdgeInsets.zero, + decoration: BoxDecoration(color: cPrimaryColor), child: Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: const EdgeInsets.only(bottom: 12.0), + padding: EdgeInsets.only(bottom: 12.0), child: Icon( Icons.restaurant_menu_rounded, color: cIconColor, @@ -93,7 +94,6 @@ class _CustomDrawerState extends State { ), ], ), - decoration: BoxDecoration(color: cPrimaryColor), ), ); } diff --git a/lib/widgets/custom_markdown_style.dart b/lib/widgets/custom_markdown_style.dart index 8a1c421..41173f5 100644 --- a/lib/widgets/custom_markdown_style.dart +++ b/lib/widgets/custom_markdown_style.dart @@ -5,23 +5,23 @@ import 'package:kulinar_app/constants.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; class CustomMarkdownStyle extends MarkdownStyleSheet { - MarkdownStyleSheet({ - tableBody: cRecipeDescriptionStyle, - a: cRecipeDescriptionStyle, - p: cRecipeDescriptionStyle, - h1: cRecipeSubtitleStyle, - h2: cRecipeSubtitleStyle, - h3: cRecipeSubtitleStyle, - h4: cRecipeSubtitleStyle, - h5: cRecipeSubtitleStyle, - h6: cRecipeSubtitleStyle, + markdownStyleSheet({ + tableBody = cRecipeDescriptionStyle, + a = cRecipeDescriptionStyle, + p = cRecipeDescriptionStyle, + h1 = cRecipeSubtitleStyle, + h2 = cRecipeSubtitleStyle, + h3 = cRecipeSubtitleStyle, + h4 = cRecipeSubtitleStyle, + h5 = cRecipeSubtitleStyle, + h6 = cRecipeSubtitleStyle, /* TODO: remove code and quote block blockquoteDecoration: BoxDecoration(color: Color.fromARGB(255, 255, 13, 13)), code: cDetailsTextStyle, */ - listIndent: 15.0, - listBullet: cRecipeDescriptionStyle, - listBulletPadding: const EdgeInsets.only(right: 10.0), + listIndent = 15.0, + listBullet = cRecipeDescriptionStyle, + listBulletPadding = const EdgeInsets.only(right: 10.0), // horizontalRuleDecoration: BoxDecoration(border: Border.all(color: Colors.grey, width: 0.5)), }) {} } diff --git a/lib/widgets/error_widgets.dart b/lib/widgets/error_widgets.dart index 52ac0bb..e17e409 100644 --- a/lib/widgets/error_widgets.dart +++ b/lib/widgets/error_widgets.dart @@ -14,7 +14,7 @@ class NoContentError extends StatelessWidget { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Icon( + const Icon( Icons.sentiment_dissatisfied_rounded, size: 100, ), @@ -42,7 +42,7 @@ class NetworkContentError extends StatelessWidget { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Icon( + const Icon( Icons.signal_wifi_off_rounded, size: 100, ), @@ -81,7 +81,7 @@ class UnknownError extends StatelessWidget { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Icon( + const Icon( Icons.warning_amber_rounded, size: 100, ), diff --git a/lib/widgets/page_route_transitions.dart b/lib/widgets/page_route_transitions.dart index 8491555..a4dc061 100644 --- a/lib/widgets/page_route_transitions.dart +++ b/lib/widgets/page_route_transitions.dart @@ -5,13 +5,13 @@ class SlideFromLeftRoute extends PageRouteBuilder { SlideFromLeftRoute({required this.child}) : super( - transitionDuration: Duration(milliseconds: 300), + transitionDuration: const Duration(milliseconds: 300), pageBuilder: (BuildContext _, Animation __, Animation ___) => child, transitionsBuilder: (BuildContext _, Animation animation, Animation __, Widget child) => SlideTransition( position: Tween( - begin: Offset(-1, 0), + begin: const Offset(-1, 0), end: Offset.zero, - ).animate(CurvedAnimation(parent: animation, curve: Interval(0.00, 1.00, curve: Curves.ease))), + ).animate(CurvedAnimation(parent: animation, curve: const Interval(0.00, 1.00, curve: Curves.ease))), child: child, ), ); @@ -22,13 +22,13 @@ class SlideFromRightRoute extends PageRouteBuilder { SlideFromRightRoute({required this.child}) : super( - transitionDuration: Duration(milliseconds: 300), + transitionDuration: const Duration(milliseconds: 300), pageBuilder: (BuildContext _, Animation __, Animation ___) => child, transitionsBuilder: (BuildContext _, Animation animation, Animation __, Widget child) => SlideTransition( position: Tween( - begin: Offset(1, 0), + begin: const Offset(1, 0), end: Offset.zero, - ).animate(CurvedAnimation(parent: animation, curve: Interval(0.00, 1.00, curve: Curves.ease))), + ).animate(CurvedAnimation(parent: animation, curve: const Interval(0.00, 1.00, curve: Curves.ease))), child: child, ), ); @@ -39,13 +39,13 @@ class SlideFromBottomRoute extends PageRouteBuilder { SlideFromBottomRoute({required this.child}) : super( - transitionDuration: Duration(milliseconds: 300), + transitionDuration: const Duration(milliseconds: 300), pageBuilder: (BuildContext _, Animation __, Animation ___) => child, transitionsBuilder: (BuildContext _, Animation animation, Animation __, Widget child) => SlideTransition( position: Tween( - begin: Offset(0, 1), + begin: const Offset(0, 1), end: Offset.zero, - ).animate(CurvedAnimation(parent: animation, curve: Interval(0.00, 1.00, curve: Curves.ease))), + ).animate(CurvedAnimation(parent: animation, curve: const Interval(0.00, 1.00, curve: Curves.ease))), child: child, ), ); @@ -56,7 +56,7 @@ class FadeRoute extends PageRouteBuilder { FadeRoute({required this.child}) : super( - transitionDuration: Duration(milliseconds: 300), + transitionDuration: const Duration(milliseconds: 300), pageBuilder: (BuildContext _, Animation animation, Animation __) => FadeTransition( opacity: animation, child: child, diff --git a/lib/widgets/recipe_card_widget.dart b/lib/widgets/recipe_card_widget.dart index 4828b9a..a3db5f7 100644 --- a/lib/widgets/recipe_card_widget.dart +++ b/lib/widgets/recipe_card_widget.dart @@ -19,10 +19,10 @@ class RecipeCard extends StatefulWidget { final Function? showToastCallback; @override - _RecipeCardState createState() => _RecipeCardState(); + RecipeCardState createState() => RecipeCardState(); } -class _RecipeCardState extends State { +class RecipeCardState extends State { @override void dispose() { super.dispose(); @@ -68,7 +68,7 @@ class _RecipeCardState extends State { widget.redrawCallback!(); } catch (e) { - print(e); + debugPrint("$e"); } } @@ -97,7 +97,7 @@ class _RecipeCardState extends State { } class _RecipeInfo extends StatefulWidget { - _RecipeInfo({Key? key, required this.recipe}) : super(key: key); + const _RecipeInfo({Key? key, required this.recipe}) : super(key: key); final Recipe recipe; @@ -112,7 +112,7 @@ class _RecipeInfoState extends State<_RecipeInfo> { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ _buildRecipeInfo(), - _buildFavortiteIcon(), + _buildFavoriteIcon(), ], ); } @@ -123,7 +123,7 @@ class _RecipeInfoState extends State<_RecipeInfo> { if (rating == 0) return _result; for (int i = 0; i < 5; i++) { - _result.add(rating >= 1 ? Icon(Icons.star_rounded) : Icon(Icons.star_border_rounded)); + _result.add(rating >= 1 ? const Icon(Icons.star_rounded) : const Icon(Icons.star_border_rounded)); rating--; } @@ -163,9 +163,9 @@ class _RecipeInfoState extends State<_RecipeInfo> { ); } - Widget _buildFavortiteIcon() { + Widget _buildFavoriteIcon() { return IconButton( - icon: widget.recipe.favorite ? Icon(Icons.favorite_rounded, color: Colors.red) : Icon(Icons.favorite_border_rounded), + icon: widget.recipe.favorite ? const Icon(Icons.favorite_rounded, color: Colors.red) : const Icon(Icons.favorite_border_rounded), onPressed: () { widget.recipe.toggleFavorite(); RecipeData.save(); diff --git a/lib/widgets/recipe_search_delegate.dart b/lib/widgets/recipe_search_delegate.dart index 1cb02e7..cd58b29 100644 --- a/lib/widgets/recipe_search_delegate.dart +++ b/lib/widgets/recipe_search_delegate.dart @@ -10,7 +10,7 @@ class RecipeSearch extends SearchDelegate { List buildActions(BuildContext context) { return [ IconButton( - icon: Icon(Icons.clear), + icon: const Icon(Icons.clear), onPressed: () { query = ""; }, @@ -21,7 +21,7 @@ class RecipeSearch extends SearchDelegate { @override Widget buildLeading(BuildContext context) { return IconButton( - icon: Icon(Icons.arrow_back, color: cIconColor), + icon: const Icon(Icons.arrow_back, color: cIconColor), onPressed: () { close(context, null); }, @@ -51,7 +51,7 @@ class RecipeSearch extends SearchDelegate { @override ThemeData appBarTheme(BuildContext context) { return Theme.of(context).copyWith( - textTheme: TextTheme( + textTheme: const TextTheme( headline6: cSearchTextStyle, ), ); @@ -63,7 +63,7 @@ class FavoriteRecipeSearch extends SearchDelegate { List buildActions(BuildContext context) { return [ IconButton( - icon: Icon(Icons.clear), + icon: const Icon(Icons.clear), onPressed: () { query = ""; }, @@ -74,7 +74,7 @@ class FavoriteRecipeSearch extends SearchDelegate { @override Widget buildLeading(BuildContext context) { return IconButton( - icon: Icon(Icons.arrow_back, color: cIconColor), + icon: const Icon(Icons.arrow_back, color: cIconColor), onPressed: () { close(context, null); }, @@ -104,7 +104,7 @@ class FavoriteRecipeSearch extends SearchDelegate { @override ThemeData appBarTheme(BuildContext context) { return Theme.of(context).copyWith( - textTheme: TextTheme( + textTheme: const TextTheme( headline6: cSearchTextStyle, ), ); diff --git a/lib/widgets/toastbar_widget.dart b/lib/widgets/toastbar_widget.dart index 760ce2e..35068df 100644 --- a/lib/widgets/toastbar_widget.dart +++ b/lib/widgets/toastbar_widget.dart @@ -13,11 +13,11 @@ class ToastBar { : null, backgroundColor: error == true ? Colors.red : Colors.grey[900], behavior: SnackBarBehavior.floating, - duration: Duration(seconds: 5), + duration: const Duration(seconds: 5), elevation: 5.0, content: Text( content, - style: TextStyle(color: Colors.white), + style: const TextStyle(color: Colors.white), overflow: TextOverflow.ellipsis, ), ); diff --git a/lib/widgets/utility_icon_row_widget.dart b/lib/widgets/utility_icon_row_widget.dart index 158110a..224823f 100644 --- a/lib/widgets/utility_icon_row_widget.dart +++ b/lib/widgets/utility_icon_row_widget.dart @@ -28,10 +28,10 @@ class UtilityIconRow extends StatefulWidget { final Function cacheUnsavedRecipeCallback; @override - _UtilityIconRowState createState() => _UtilityIconRowState(); + UtilityIconRowState createState() => UtilityIconRowState(); } -class _UtilityIconRowState extends State { +class UtilityIconRowState extends State { bool _isInputSourceCamera = SettingsData.settings["photoSource"] == "0" ? true : false; @override @@ -69,11 +69,11 @@ class _UtilityIconRowState extends State { bool _recipeHasImage = widget.unsavedRecipe.image == null; if (_isInputSourceCamera) { - _pickImageIcon = Icon(Icons.add_a_photo_rounded); - _removeImageIcon = Icon(Icons.no_photography_rounded); + _pickImageIcon = const Icon(Icons.add_a_photo_rounded); + _removeImageIcon = const Icon(Icons.no_photography_rounded); } else { - _pickImageIcon = Icon(Icons.add_photo_alternate_rounded); - _removeImageIcon = Icon(Icons.image_not_supported_rounded); + _pickImageIcon = const Icon(Icons.add_photo_alternate_rounded); + _removeImageIcon = const Icon(Icons.image_not_supported_rounded); } void _onPress() { @@ -107,7 +107,7 @@ class _UtilityIconRowState extends State { ), IconButton( iconSize: 28.0, - icon: Icon(Icons.star_border_rounded), + icon: const Icon(Icons.star_border_rounded), onPressed: !widget.remote ? _onPress : null, ), ], @@ -115,11 +115,11 @@ class _UtilityIconRowState extends State { } Widget _buildIconFavorite() { - Icon icon = Icon(Icons.favorite_border_rounded); + Icon icon = const Icon(Icons.favorite_border_rounded); Color color = Colors.black; if (widget.unsavedRecipe.favorite) { - icon = Icon(Icons.favorite_rounded); + icon = const Icon(Icons.favorite_rounded); color = Colors.red; } -- cgit v1.2.3