Commit f8de561
Changed files (14)
docs
lib
components
screens
docs/codestyle.md
@@ -16,5 +16,6 @@ The goal of this style guideline is to make dart code maintainable and to reduce
- 2 spaces indentation
- partially extract build to hidden methods where the main build method becomes hard to read
- Try to create useful documentation for every method / class you create. In case you find yourself looking at a methods source code to figure out a particular aspect of it, add that information to the documentation.
+- Avoid using `Navigator.of` and prefer calling `Navigator.pop` and `Navigator.push` directly
Refer to [effective dart](https://dart.dev/effective-dart) for inspiration in case you find yourself spending too much time making style decisions.
\ No newline at end of file
lib/components/dialoges/add_export_column_dialoge.dart
@@ -221,7 +221,7 @@ class _AddExportColumnDialogeState extends State<AddExportColumnDialoge>
labelText: labelText,
suffixIcon: IconButton(
onPressed: () {
- Navigator.of(context).push(MaterialPageRoute(
+ Navigator.push(context, MaterialPageRoute(
builder: (context) => InformationScreen(
text: inputDocumentation,
),
lib/components/dialoges/add_measurement_dialoge.dart
@@ -249,13 +249,13 @@ class _AddEntryDialogeState extends State<AddEntryDialoge> {
}
if (record != null && intake != null) {
- Navigator.of(context).pop((record, intake));
+ Navigator.pop(context, (record, intake));
}
if (record == null && !_measurementFormActive && intake != null) {
- Navigator.of(context).pop((record, intake));
+ Navigator.pop(context, (record, intake));
}
if (record != null && intake == null && medicineId == null) {
- Navigator.of(context).pop((record, intake));
+ Navigator.pop(context, (record, intake));
}
},
actionButtonText: localizations.btnSave,
lib/components/dialoges/add_medication_dialoge.dart
@@ -42,7 +42,7 @@ class _AddMedicationDialogeState extends State<AddMedicationDialoge> {
actionButtonText: localizations.btnSave,
onActionButtonPressed: () {
formKey.currentState?.save();
- Navigator.of(context).pop(Medicine(
+ Navigator.pop(context, Medicine(
widget.settings.highestMedIndex,
designation: _designation ?? '',
color: _color,
lib/components/dialoges/enter_timeformat_dialoge.dart
@@ -57,7 +57,7 @@ class _EnterTimeFormatDialogeState extends State<EnterTimeFormatDialoge> {
bottomAppBar: widget.bottomAppBars,
onActionButtonPressed: () {
if(timeFormatFieldController.text.isNotEmpty) {
- Navigator.of(context).pop(timeFormatFieldController.text);
+ Navigator.pop(context, timeFormatFieldController.text);
}
},
body: SingleChildScrollView(
lib/components/dialoges/fullscreen_dialoge.dart
@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
/// Base for fullscreen dialoges that allow value input.
class FullscreenDialoge extends StatelessWidget {
+ // TODO: directly wrap in dialoge.fullscreen and remove it from code
+
/// Create a dialoge that has a icon- and a textbutton in the app bar.
const FullscreenDialoge({super.key,
this.body,
@@ -54,7 +56,7 @@ class FullscreenDialoge extends StatelessWidget {
PreferredSizeWidget _buildAppBar(BuildContext context) => AppBar(
forceMaterialTransparency: true,
leading: (closeIcon == null) ? null : IconButton(
- onPressed: () => Navigator.of(context).pop(null),
+ onPressed: () => Navigator.pop(context, null),
icon: Icon(closeIcon),
),
actions: [
lib/components/dialoges/input_dialoge.dart
@@ -77,7 +77,7 @@ class _InputDialogeState extends State<InputDialoge> {
),
actions: [
ElevatedButton(
- onPressed: () => Navigator.of(context).pop(null),
+ onPressed: () => Navigator.pop(context, null),
child: Text(localizations.btnCancel),),
ElevatedButton(
onPressed: () => _onSubmit(controller.text),
@@ -94,7 +94,7 @@ class _InputDialogeState extends State<InputDialoge> {
});
return;
}
- Navigator.of(context).pop(value);
+ Navigator.pop(context, value);
}
}
lib/components/measurement_list/measurement_list_entry.dart
@@ -122,11 +122,11 @@ Future<bool> showConfirmDeletionDialoge(BuildContext context) async =>
content: Text(AppLocalizations.of(context)!.confirmDeleteDesc),
actions: [
ElevatedButton(
- onPressed: () => Navigator.of(context).pop(false),
+ onPressed: () => Navigator.pop(context, false),
child: Text(AppLocalizations.of(context)!.btnCancel),
),
ElevatedButton(
- onPressed: () => Navigator.of(context).pop(true),
+ onPressed: () => Navigator.pop(context, true),
child: Text(AppLocalizations.of(context)!.btnConfirm),
),
],
lib/components/color_picker.dart
@@ -157,7 +157,7 @@ Future<Color?> showColorPickerDialog(
content: ColorPicker(
initialColor: initialColor,
onColorSelected: (color) {
- Navigator.of(context).pop(color);
+ Navigator.pop(context, color);
},
),
actions: [
lib/screens/elements/legacy_measurement_list.dart
@@ -108,14 +108,14 @@ class LegacyMeasurementsList extends StatelessWidget {
content: Text(AppLocalizations.of(context)!.confirmDeleteDesc),
actions: [
ElevatedButton(
- onPressed: () => Navigator.of(context).pop(),
+ onPressed: () => Navigator.pop(context, ),
child: Text(AppLocalizations.of(context)!.btnCancel),),
ElevatedButton(
onPressed: () {
model.delete(data[index].creationTime);
dialogeDeletionConfirmed = true;
- Navigator.of(context).pop();
+ Navigator.pop(context, );
},
child: Text(AppLocalizations.of(context)!.btnConfirm),),
],
lib/screens/subsettings/export_import/active_field_customization.dart
@@ -97,7 +97,7 @@ class ActiveExportFieldCustomization extends StatelessWidget {
children: availableColumns.getAllColumns().map((column) =>
ListTile(
title: Text(column.userTitle(localizations)),
- onTap: () => Navigator.of(context).pop(column),
+ onTap: () => Navigator.pop(context, column),
),
).toList(),
),
lib/screens/subsettings/export_import/export_column_management_screen.dart
@@ -62,10 +62,10 @@ class ExportColumnsManagementScreen extends StatelessWidget {
title: Text(AppLocalizations.of(context)!.confirmDelete),
actions: [
ElevatedButton(
- onPressed: () => Navigator.of(context).pop(false),
+ onPressed: () => Navigator.pop(context, false),
child: Text(AppLocalizations.of(context)!.btnCancel),),
ElevatedButton(
- onPressed: () => Navigator.of(context).pop(true),
+ onPressed: () => Navigator.pop(context, true),
child: Text(AppLocalizations.of(context)!.btnConfirm),),
],
),
lib/screens/subsettings/export_import/export_field_format_documentation_screen.dart
@@ -5,8 +5,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:url_launcher/url_launcher.dart';
-/// Screen to show large markdown text.
+/// Screen to show long markdown text.
class InformationScreen extends StatelessWidget {
+ /// Create a screen to display long markdown text.
const InformationScreen({super.key, required this.text});
/// text in markdown format
@@ -14,22 +15,29 @@ class InformationScreen extends StatelessWidget {
@override
Widget build(BuildContext context) => Scaffold(
- appBar: AppBar(
- forceMaterialTransparency: true,
- ),
- body: Container(
- padding: const EdgeInsets.all(10),
- child: Markdown(
- selectable: true,
- onTapLink: getLinkTapHandler(context),
- data: text,
- ),
- ),
- );
+ appBar: AppBar(
+ forceMaterialTransparency: true,
+ ),
+ body: Container(
+ padding: const EdgeInsets.all(10),
+ child: Markdown(
+ selectable: true,
+ onTapLink: getLinkTapHandler(context),
+ data: text,
+ ),
+ ),
+ );
}
-typedef LinkTapHandler = FutureOr<void> Function(String, String?, String)?;
+/// Definition of a function that resolves lik presses
+typedef LinkTapHandler = FutureOr<void> Function(String text, String? destination, String title)?;
+/// Constructs a function that handles link presses to urls and some screens.
+///
+/// Currently supported
+/// - `http://*`
+/// - `https://*`
+/// - `screen://TimeFormattingHelp`
LinkTapHandler getLinkTapHandler(BuildContext context) => (String text, String? destination, String title) async {
if (destination == null) {
return;
@@ -43,7 +51,8 @@ LinkTapHandler getLinkTapHandler(BuildContext context) => (String text, String?
} else if (destination.startsWith('screen://')) {
switch (destination.split('//')[1]) {
case 'TimeFormattingHelp':
- Navigator.of(context).push(MaterialPageRoute(builder: (context) => const TimeFormattingReferenceScreen()));
+ Navigator.push(context, MaterialPageRoute(builder:
+ (context) => const TimeFormattingReferenceScreen(),),);
return;
}
}
lib/screens/subsettings/delete_data_screen.dart
@@ -35,7 +35,7 @@ class _DeleteDataScreenState extends State<DeleteDataScreen> {
if (_deletedData) {
Restart.restartApp();
} else {
- Navigator.of(context).pop();
+ Navigator.pop(context, );
}
},
),
@@ -189,7 +189,7 @@ class _DeleteDataScreenState extends State<DeleteDataScreen> {
actionsAlignment: MainAxisAlignment.spaceBetween,
actions: [
TextButton(
- onPressed: () => Navigator.of(context).pop(false),
+ onPressed: () => Navigator.pop(context, false),
child: Text(AppLocalizations.of(context)!.btnCancel),),
Theme(
data: ThemeData.from(
@@ -197,7 +197,7 @@ class _DeleteDataScreenState extends State<DeleteDataScreen> {
useMaterial3: true,
),
child: ElevatedButton.icon(
- onPressed: () => Navigator.of(context).pop(true),
+ onPressed: () => Navigator.pop(context, true),
icon: const Icon(Icons.delete_forever),
label: Text(AppLocalizations.of(context)!.btnConfirm),
),