Commit f0dcc64

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-01-04 15:01:53
generalize style
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent 117108f
Changed files (4)
lib/components/CustomBanner.dart
@@ -0,0 +1,50 @@
+import 'package:flutter/material.dart';
+
+/// A floating banner to display information.
+///
+/// The banner allows to perform actions.
+///
+/// Example usage:
+/// ```dart
+/// CustomBanner(
+///   content: Text(localizations.warnNeedsRestartForUsingApp),
+///   action: TextButton(
+///     onPressed: () => Restart.restartApp(),
+///     child: Text(localizations.restartNow),
+///   )
+/// )
+/// ```
+class CustomBanner extends StatelessWidget {
+  /// Create a banner that displays information and an action.
+  const CustomBanner({super.key, required this.content, this.action});
+
+  /// The main content of the banner.
+  ///
+  /// Gets displayed on the left side.
+  final Widget content;
+
+  /// Primary action of the banner.
+  ///
+  /// Usually a [TextButton].
+  ///
+  /// When this is larger than the screen width, overflow occurs.
+  final Widget? action;
+
+  @override
+  Widget build(BuildContext context) => Container(
+    margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 4),
+    padding: const EdgeInsets.all(15),
+    decoration: BoxDecoration(
+      borderRadius: BorderRadius.circular(20),
+      color: Theme.of(context).cardColor,
+    ),
+    child: Row(
+      children: [
+        Expanded(child: content),
+        if (action != null)
+          action!,
+      ],
+    ),
+  );
+
+}
\ No newline at end of file
lib/components/export_warn_banner.dart
@@ -1,3 +1,4 @@
+import 'package:blood_pressure_app/components/CustomBanner.dart';
 import 'package:blood_pressure_app/model/export_import/column.dart';
 import 'package:blood_pressure_app/model/export_import/export_configuration.dart';
 import 'package:blood_pressure_app/model/export_import/import_field_type.dart';
@@ -105,20 +106,14 @@ class _ExportWarnBannerState extends State<ExportWarnBanner> {
     ), localizations);
   }
 
-  Widget _banner(String text, AppLocalizations localizations) {
-    return MaterialBanner(
-        padding: const EdgeInsets.all(20),
-        content: Text(text),
-        actions: [
-          TextButton(
-            onPressed: () {
-              setState(() {
-                _hidden = true;
-              });
-            },
-            child: Text(localizations.btnConfirm)
-          )
-        ]
-      );
-  }
+  // TODO: ensure this is used instead of material banner everywhere in the app.
+  Widget _banner(String text, AppLocalizations localizations) => CustomBanner(
+      content: Text(text),
+      action: TextButton(
+        onPressed: () => setState(() {
+          _hidden = true;
+        }),
+        child: Text(localizations.btnConfirm)
+      ),
+    );
 }
\ No newline at end of file
lib/screens/subsettings/delete_data_screen.dart
@@ -1,6 +1,7 @@
 import 'dart:io';
 import 'dart:math';
 
+import 'package:blood_pressure_app/components/CustomBanner.dart';
 import 'package:blood_pressure_app/components/consistent_future_builder.dart';
 import 'package:blood_pressure_app/main.dart';
 import 'package:flutter/material.dart';
@@ -42,13 +43,12 @@ class _DeleteDataScreenState extends State<DeleteDataScreen> {
       body: Column(
         children: [
           if (_deletedData)
-            MaterialBanner(
+            CustomBanner(
                 content: Text(localizations.warnNeedsRestartForUsingApp),
-                actions: [
-                  TextButton(onPressed: () {
-                    Restart.restartApp();
-                  }, child: Text(localizations.restartNow))
-                ]
+                action: TextButton(
+                  onPressed: () => Restart.restartApp(),
+                  child: Text(localizations.restartNow),
+                )
             ),
           Expanded(
             child: Container(
lib/main.dart
@@ -143,6 +143,23 @@ class AppRoot extends StatelessWidget {
         border: inputBorder,
         enabledBorder: inputBorder,
       ),
+      pageTransitionsTheme: const PageTransitionsTheme(builders: {
+        TargetPlatform.android: ZoomPageTransitionsBuilder()
+      }),
+      appBarTheme: const AppBarTheme(
+        centerTitle: true,
+        shape: RoundedRectangleBorder(
+          borderRadius: BorderRadius.only(
+            bottomRight: Radius.circular(15),
+            bottomLeft: Radius.circular(15),
+          ),
+        ),
+      ),
+      snackBarTheme: SnackBarThemeData(
+        shape: RoundedRectangleBorder(
+          borderRadius: BorderRadius.circular(8),
+        ),
+      ),
     );
   }
 }