diff options
Diffstat (limited to 'lib/views')
-rw-r--r-- | lib/views/favorites_view.dart | 10 | ||||
-rw-r--r-- | lib/views/file_info_subview.dart (renamed from lib/views/file_info.dart) | 20 | ||||
-rw-r--r-- | lib/views/image_subview.dart (renamed from lib/views/image_view.dart) | 4 | ||||
-rw-r--r-- | lib/views/main_view.dart | 8 | ||||
-rw-r--r-- | lib/views/recipe_subview.dart (renamed from lib/views/recipe_view.dart) | 72 | ||||
-rw-r--r-- | lib/views/settings_view.dart | 37 | ||||
-rw-r--r-- | lib/views/shoplist_view.dart | 10 | ||||
-rw-r--r-- | lib/views/week_view.dart | 4 |
8 files changed, 68 insertions, 97 deletions
diff --git a/lib/views/favorites_view.dart b/lib/views/favorites_view.dart index 97f784c..d133b79 100644 --- a/lib/views/favorites_view.dart +++ b/lib/views/favorites_view.dart @@ -25,7 +25,7 @@ class FavoritesViewState extends State<FavoritesView> { return Scaffold( appBar: _buildAppBar(context), drawer: const CustomDrawer(initialIndex: 1), - body: Container( + body: SizedBox( width: double.infinity, child: Builder( builder: (BuildContext context) { @@ -66,14 +66,14 @@ class FavoritesViewState extends State<FavoritesView> { } Widget _buildListView() { - List<Recipe> _filteredRecipeList = RecipeData.recipeList.where((element) => element.favorite).toList(); + List<Recipe> filteredRecipeList = RecipeData.recipeList.where((element) => element.favorite).toList(); - if (_filteredRecipeList.isEmpty) return const NoContentError(); + if (filteredRecipeList.isEmpty) return const NoContentError(); return ListView.builder( - itemCount: _filteredRecipeList.length, + itemCount: filteredRecipeList.length, itemBuilder: (context, index) => RecipeCard( - recipe: _filteredRecipeList[index], + recipe: filteredRecipeList[index], redrawCallback: redrawFavoritesView, showToastCallback: showToastCallback, ), diff --git a/lib/views/file_info.dart b/lib/views/file_info_subview.dart index 28c45f9..b9cd881 100644 --- a/lib/views/file_info.dart +++ b/lib/views/file_info_subview.dart @@ -8,29 +8,29 @@ import 'package:kulinar_app/widgets/error_widgets.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -class FileInfo extends StatefulWidget { - const FileInfo({Key? key, required this.filePath}) : super(key: key); +class FileInfoSubview extends StatefulWidget { + const FileInfoSubview({Key? key, required this.filePath}) : super(key: key); final String filePath; @override - FileInfoState createState() => FileInfoState(); + FileInfoSubviewState createState() => FileInfoSubviewState(); } -class FileInfoState extends State<FileInfo> { +class FileInfoSubviewState extends State<FileInfoSubview> { @override Widget build(BuildContext context) { - final File _file = File(widget.filePath.split(":")[1]); + final File file = File(widget.filePath.split(":")[1]); return Scaffold( appBar: AppBar(title: Text(AppLocalizations.of(context)!.category9)), body: FutureBuilder( - future: FileHandler.deserializeFileInformation(_file), + future: FileHandler.deserializeFileInformation(file), builder: (BuildContext context, AsyncSnapshot<Map<String, String>> snapshot) { if (snapshot.connectionState != ConnectionState.done) return const CircularProgressIndicator(); if (snapshot.hasError || !snapshot.hasData) return const UnknownError(); - return _buildFileInfoTable(_getSortedSnapshotData(snapshot), _file); + return _buildFileInfoTable(_getSortedSnapshotData(snapshot), file); }, ), ); @@ -52,10 +52,10 @@ class FileInfoState extends State<FileInfo> { } List<TableRow> _getSortedSnapshotData(AsyncSnapshot<Map<String, String>> snapshot) { - List<TableRow> _children = []; + List<TableRow> children = []; snapshot.data!.forEach((key, value) { - _children.add( + children.add( TableRow( children: [ Padding( @@ -71,7 +71,7 @@ class FileInfoState extends State<FileInfo> { ); }); - return _children; + return children; } Widget _buildFileInfoTable(List<TableRow> children, File file) { diff --git a/lib/views/image_view.dart b/lib/views/image_subview.dart index 1363268..bc5ac49 100644 --- a/lib/views/image_view.dart +++ b/lib/views/image_subview.dart @@ -4,8 +4,8 @@ import 'package:flutter/material.dart'; import 'package:kulinar_app/constants.dart'; -class ImageView extends StatelessWidget { - const ImageView({Key? key, required this.image}) : super(key: key); +class ImageSubview extends StatelessWidget { + const ImageSubview({Key? key, required this.image}) : super(key: key); final String image; diff --git a/lib/views/main_view.dart b/lib/views/main_view.dart index 3db3e97..ae63538 100644 --- a/lib/views/main_view.dart +++ b/lib/views/main_view.dart @@ -2,11 +2,11 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:kulinar_app/constants.dart'; -import 'package:kulinar_app/views/file_info.dart'; -import 'package:kulinar_app/views/recipe_view.dart'; +import 'package:kulinar_app/views/recipe_subview.dart'; import 'package:kulinar_app/models/recipe_class.dart'; import 'package:kulinar_app/widgets/error_widgets.dart'; import 'package:kulinar_app/widgets/toastbar_widget.dart'; +import 'package:kulinar_app/views/file_info_subview.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'; @@ -76,7 +76,7 @@ class MainViewState extends State<MainView> with SingleTickerProviderStateMixin, if (url != null) { setState(() { - Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (BuildContext context) => FileInfo(filePath: url)), (_) => false); + Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (BuildContext context) => FileInfoSubview(filePath: url)), (_) => false); }); } } @@ -91,7 +91,7 @@ class MainViewState extends State<MainView> with SingleTickerProviderStateMixin, onPressed: () async { await Navigator.push( context, - SlideFromBottomRoute(child: const RecipeView()), + SlideFromBottomRoute(child: const RecipeSubview()), ); setState(() {}); diff --git a/lib/views/recipe_view.dart b/lib/views/recipe_subview.dart index 3aaa160..9c7d91d 100644 --- a/lib/views/recipe_view.dart +++ b/lib/views/recipe_subview.dart @@ -3,7 +3,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:kulinar_app/constants.dart'; -import 'package:kulinar_app/views/image_view.dart'; +import 'package:kulinar_app/views/image_subview.dart'; import 'package:kulinar_app/models/recipe_class.dart'; import 'package:kulinar_app/widgets/toastbar_widget.dart'; import 'package:kulinar_app/widgets/custom_markdown_style.dart'; @@ -20,8 +20,8 @@ import 'package:share_plus/share_plus.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -class RecipeView extends StatefulWidget { - const RecipeView({Key? key, this.remote = false, this.recipe, this.redrawCallback, this.showToastCallback}) : super(key: key); +class RecipeSubview extends StatefulWidget { + const RecipeSubview({Key? key, this.remote = false, this.recipe, this.redrawCallback, this.showToastCallback}) : super(key: key); final bool remote; final Recipe? recipe; @@ -29,10 +29,10 @@ class RecipeView extends StatefulWidget { final Function? showToastCallback; @override - RecipeViewState createState() => RecipeViewState(); + RecipeSubviewState createState() => RecipeSubviewState(); } -class RecipeViewState extends State<RecipeView> { +class RecipeSubviewState extends State<RecipeSubview> { final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); final TextEditingController _controller1 = TextEditingController(); @@ -118,11 +118,11 @@ class RecipeViewState extends State<RecipeView> { _removedRecipe = widget.recipe; - String _content = AppLocalizations.of(context)!.removed; - String _actionLabel = AppLocalizations.of(context)!.undo; + String content = AppLocalizations.of(context)!.removed; + String actionLabel = AppLocalizations.of(context)!.undo; if (widget.showToastCallback != null) { - widget.showToastCallback!(_content, _actionLabel, () { + widget.showToastCallback!(content, actionLabel, () { _addRecipe(passedRecipe: _removedRecipe); widget.redrawCallback!(); }); @@ -140,21 +140,21 @@ class RecipeViewState extends State<RecipeView> { } void _pickImage() async { - XFile? _pickedFile; + XFile? pickedFile; if (SettingsData.settings["photoSource"] == "0") { - _pickedFile = await ImagePicker().pickImage(source: ImageSource.camera); + pickedFile = await ImagePicker().pickImage(source: ImageSource.camera); } else { - _pickedFile = await ImagePicker().pickImage(source: ImageSource.gallery); + pickedFile = await ImagePicker().pickImage(source: ImageSource.gallery); } - if (_pickedFile != null) { - Directory _directory = await getApplicationDocumentsDirectory(); - String _name = DateTime.now().millisecondsSinceEpoch.toString(); - File _file = File("${_directory.path}/$_name"); + if (pickedFile != null) { + Directory directory = await getApplicationDocumentsDirectory(); + String name = DateTime.now().millisecondsSinceEpoch.toString(); + File file = File("${directory.path}/$name"); - _file.writeAsBytes(await _pickedFile.readAsBytes()); - _unsavedRecipe.image = _file.path; + file.writeAsBytes(await pickedFile.readAsBytes()); + _unsavedRecipe.image = file.path; RecipeData.save(); } @@ -236,7 +236,7 @@ class RecipeViewState extends State<RecipeView> { onTap: () { Navigator.push( context, - FadeRoute(child: ImageView(image: _unsavedRecipe.image!)), + FadeRoute(child: ImageSubview(image: _unsavedRecipe.image!)), ); }, ), @@ -264,6 +264,8 @@ class RecipeViewState extends State<RecipeView> { focusNode: _detailsTextFocus, style: cRecipeDescriptionStyle, enableInteractiveSelection: true, + // TODO: only replace with code with same function + // ignore: deprecated_member_use toolbarOptions: const ToolbarOptions( copy: true, cut: true, @@ -289,18 +291,18 @@ class RecipeViewState extends State<RecipeView> { } void _addToShoppingList(BuildContext _) { - final _ingredients = _unsavedRecipe.description!.split("\n")..retainWhere((element) => element.startsWith("- ")); + final ingredients = _unsavedRecipe.description!.split("\n")..retainWhere((element) => element.startsWith("- ")); - if (_ingredients.isEmpty) { + if (ingredients.isEmpty) { widget.showToastCallback!(AppLocalizations.of(context)!.ingredientsError, "", () {}); return; } - for (String _ingredient in _ingredients) { - String _item = _ingredient.substring(2).trim(); + for (String ingredient in ingredients) { + String item = ingredient.substring(2).trim(); - if (!ShoplistData.shoplist.contains(_item)) { - ShoplistData.shoplist.add(_item); + if (!ShoplistData.shoplist.contains(item)) { + ShoplistData.shoplist.add(item); } } @@ -316,12 +318,12 @@ class RecipeViewState extends State<RecipeView> { } List<Widget> _buildAppBarActions(BuildContext context, Recipe recipe) { - final _actionList = [_shareData, _addToShoppingList, _uploadRecipe, _removeRecipe]; + final actionList = [_shareData, _addToShoppingList, _uploadRecipe, _removeRecipe]; - List<Widget> _localActions = [ + List<Widget> localActions = [ _buildAppBarCheckActions(), PopupMenuButton( - onSelected: (int value) => _actionList.elementAt(value)(context), + onSelected: (int value) => actionList.elementAt(value)(context), itemBuilder: (BuildContext context) => [ PopupMenuItem<int>(value: 0, child: Text(AppLocalizations.of(context)!.menu1)), PopupMenuItem<int>(value: 1, child: Text(AppLocalizations.of(context)!.menu2)), @@ -331,7 +333,7 @@ class RecipeViewState extends State<RecipeView> { ), ]; - List<Widget> _remoteDownloadAction = [ + List<Widget> remoteDownloadAction = [ IconButton( icon: const Icon(Icons.save_alt_rounded), onPressed: () { @@ -340,26 +342,26 @@ class RecipeViewState extends State<RecipeView> { ), ]; - List<Widget> _remoteLookupAction = [ + List<Widget> remoteLookupAction = [ const IconButton( icon: Icon(Icons.menu_open_rounded), onPressed: null, ), ]; - if (widget.remote && RecipeData.recipeList.contains(recipe)) return _remoteLookupAction; - if (widget.remote) return _remoteDownloadAction; + if (widget.remote && RecipeData.recipeList.contains(recipe)) return remoteLookupAction; + if (widget.remote) return remoteDownloadAction; - return _localActions; + return localActions; } PreferredSizeWidget _buildAppBar(BuildContext context, Recipe recipe) { - String _title = AppLocalizations.of(context)!.mode1; + String title = AppLocalizations.of(context)!.mode1; - if (_isEditModeEnabled) _title = AppLocalizations.of(context)!.mode2; + if (_isEditModeEnabled) title = AppLocalizations.of(context)!.mode2; return AppBar( - title: Text(_title), + title: Text(title), leading: IconButton( icon: const Icon(Icons.close), onPressed: () { diff --git a/lib/views/settings_view.dart b/lib/views/settings_view.dart index 7268acf..c4cd1ce 100644 --- a/lib/views/settings_view.dart +++ b/lib/views/settings_view.dart @@ -17,7 +17,6 @@ class SettingsView extends StatefulWidget { class SettingsViewState extends State<SettingsView> { final TextEditingController _controller = TextEditingController(); - final FocusNode _focusNode = FocusNode(); @override void initState() { @@ -83,11 +82,11 @@ class SettingsViewState extends State<SettingsView> { trailing: ElevatedButton( child: Text(AppLocalizations.of(context)!.option312, style: cOptionTextStyle.copyWith(color: cIconColor)), onPressed: () async { - final _file = await FileHandler.pickDeserializableFile(context); + final file = await FileHandler.pickDeserializableFile(context); - if (_file == null) return; + if (file == null) return; - await FileHandler.deserializeFile(context, _file); + await FileHandler.deserializeFile(context, file); setState(() {}); }, @@ -99,36 +98,6 @@ class SettingsViewState extends State<SettingsView> { ); } - void _updateSettings(String? text) { - _focusNode.unfocus(); - - if (text != null) { - SettingsData.settings["serverURL"] = text; - SettingsData.save(); - } - } - -/* - // TODO: Use later in direct settings? - Widget _buildServerIPInput() { - if (MediaQuery.of(context).viewInsets.bottom == 0) _updateSettings(null); - - return Container( - width: 150.0, - child: TextFormField( - keyboardType: TextInputType.url, - controller: _controller, - style: cRecipeTextStyle, - focusNode: _focusNode, - cursorColor: cPrimaryColor, - onEditingComplete: () { - _updateSettings(_controller.text); - }, - ), - ); - } -*/ - Widget _buildPhotoSourceDropDownButton() { return DropdownButton( value: int.parse(SettingsData.settings["photoSource"]!), diff --git a/lib/views/shoplist_view.dart b/lib/views/shoplist_view.dart index 35332bc..638dc1b 100644 --- a/lib/views/shoplist_view.dart +++ b/lib/views/shoplist_view.dart @@ -70,11 +70,11 @@ class ShoplistViewState extends State<ShoplistView> { title: Text(ShoplistData.shoplist[index]), ), onDismissed: (_) { - String _content = AppLocalizations.of(context)!.removed; - String _actionLabel = AppLocalizations.of(context)!.undo; + String content = AppLocalizations.of(context)!.removed; + String actionLabel = AppLocalizations.of(context)!.undo; _removeItem(index); - ToastBar.showToastBar(context, _content, actionLabel: _actionLabel, actionCallback: () => _addItem(ShoplistData.removed.removeLast())); + ToastBar.showToastBar(context, content, actionLabel: actionLabel, actionCallback: () => _addItem(ShoplistData.removed.removeLast())); }, ), ); @@ -118,12 +118,12 @@ class ShoplistViewState extends State<ShoplistView> { focusNode: _focusNode, textInputAction: TextInputAction.done, onEditingComplete: () { - String _text = _controller.text.trim(); + String text = _controller.text.trim(); _closeInput(); _controller.clear(); - if (_text != "") _addItem(_text); + if (text != "") _addItem(text); }, ), ), diff --git a/lib/views/week_view.dart b/lib/views/week_view.dart index de6ebcf..53379b9 100644 --- a/lib/views/week_view.dart +++ b/lib/views/week_view.dart @@ -42,12 +42,12 @@ class WeekViewState extends State<WeekView> { } Future<Response?> _getWeeklyRecipes() async { - Map<String, String> _headers = {"Content-Type": "application/json; charset=UTF-8"}; + Map<String, String> headers = {"Content-Type": "application/json; charset=UTF-8"}; try { return await Future.delayed(const Duration(milliseconds: 500), () { debugPrint("${SettingsData.settings['serverURL']}"); - return get(Uri.https(SettingsData.settings["serverURL"]!, "/weekly"), headers: _headers); + return get(Uri.https(SettingsData.settings["serverURL"]!, "/weekly"), headers: headers); }); } catch (e) { debugPrint("$e"); |