Commit 546857f

derdilla <derdilla06@gmail.com>
2023-05-13 12:27:24
FEAT: landscape mode
1 parent 6ee97c5
Changed files (3)
lib/components/complex_settings.dart
@@ -1,4 +1,3 @@
-import 'package:blood_pressure_app/model/settings.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
 
lib/components/measurement_graph.dart
@@ -9,6 +9,9 @@ import 'package:intl/intl.dart';
 import 'package:blood_pressure_app/model/settings.dart';
 
 class _LineChart extends StatelessWidget {
+  final double height;
+  const _LineChart({super.key, this.height = 200});
+  
   @override
   Widget build(BuildContext context) {
     return Stack(
@@ -16,7 +19,7 @@ class _LineChart extends StatelessWidget {
         Align(
           alignment: Alignment.topCenter,
           child: Container(
-              height: 200,
+            height: height,
               child: Consumer<Settings>(
                 builder: (context, settings, child) {
                   return Consumer<BloodPressureModel>(
@@ -61,7 +64,6 @@ class _LineChart extends StatelessWidget {
                                     sysMax = max(sysMax, element.systolic);
                                   }
 
-
                                   final noTitels = AxisTitles(sideTitles: SideTitles(reservedSize: 40, showTitles: false));
                                   res = LineChart(
                                       swapAnimationDuration: const Duration(milliseconds: 250),
@@ -149,7 +151,8 @@ class _LineChart extends StatelessWidget {
 }
 
 class MeasurementGraph extends StatelessWidget {
-  const MeasurementGraph({super.key});
+  final double height;
+  const MeasurementGraph({super.key, this.height = 290});
 
   void moveGraphWithStep(int directionalStep, Settings settings) {
     final oldStart = settings.graphStart;
@@ -177,13 +180,13 @@ class MeasurementGraph extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
     return SizedBox(
-      height: 290,
+      height: height,
       child: Padding(
         padding: const EdgeInsets.only(right: 16, left: 6, top: 2),
         child: Column(
           children: [
             const SizedBox(height: 20,),
-            _LineChart(),
+            _LineChart(height: height-100),
             const SizedBox(height: 7,),
             Consumer<Settings>(
                 builder: (context, settings, child) {
lib/screens/home.dart
@@ -3,6 +3,7 @@ import 'package:blood_pressure_app/screens/settings.dart';
 import 'package:flutter/material.dart';
 import 'package:blood_pressure_app/components/measurement_graph.dart';
 import 'package:blood_pressure_app/components/measurement_list.dart';
+import 'package:flutter/services.dart';
 
 class AppHome extends StatelessWidget {
   const AppHome({super.key});
@@ -17,67 +18,81 @@ class AppHome extends StatelessWidget {
     }
 
     return Scaffold(
-      body: Center(
-        child: Container(
-          padding: padding,
-          child: Column(
-            children: [
-              const MeasurementGraph(),
-              Expanded(
-                flex: 50,
-                  child: MeasurementList(context)
+      body: OrientationBuilder(
+        builder: (context, orientation) {
+          if (orientation == Orientation.landscape && MediaQuery.of(context).size.height < 500) {
+            return MeasurementGraph(height: MediaQuery.of(context).size.height,);
+          }
+          return Center(
+            child: Container(
+              padding: padding,
+              child: Column(
+                  children: [
+                    const MeasurementGraph(),
+                    Expanded(
+                        flex: 50,
+                        child: MeasurementList(context)
+                    ),
+                  ]
               ),
-            ]
-          ),
-        ),
+            ),
+          );
+        },
       ),
-      floatingActionButton:
-        SizedBox(
-          height: 150,
-          child: Column(
-            verticalDirection: VerticalDirection.up,
-            children: [
-              Ink(
-                decoration: ShapeDecoration(
-                    shape: const CircleBorder(),
-                    color: Theme.of(context).primaryColor
-                ),
-                child: IconButton(
-                  icon: const Icon(
-                    Icons.add,
-                    color: Colors.black,
+      floatingActionButton: OrientationBuilder(
+        builder: (context, orientation) {
+          if (orientation == Orientation.landscape) {
+            SystemChrome.setEnabledSystemUIMode(SystemUiMode.leanBack);
+            return const SizedBox.shrink();
+          }
+          SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values);
+          return SizedBox(
+            height: 150,
+            child: Column(
+              verticalDirection: VerticalDirection.up,
+              children: [
+                Ink(
+                  decoration: ShapeDecoration(
+                      shape: const CircleBorder(),
+                      color: Theme.of(context).primaryColor
+                  ),
+                  child: IconButton(
+                    icon: const Icon(
+                      Icons.add,
+                      color: Colors.black,
+                    ),
+                    onPressed: () {
+                      Navigator.push(
+                        context,
+                        MaterialPageRoute(builder: (context) => const AddMeasurementPage()),
+                      );
+                    },
                   ),
-                  onPressed: () {
-                    Navigator.push(
-                      context,
-                      MaterialPageRoute(builder: (context) => const AddMeasurementPage()),
-                    );
-                  },
-                ),
-              ),
-              const SizedBox(height: 10,),
-              Ink(
-                decoration: ShapeDecoration(
-                    shape: const CircleBorder(),
-                    color: Theme.of(context).unselectedWidgetColor
                 ),
-                child: IconButton(
-                  icon: const Icon(
-                      Icons.settings,
-                      color: Colors.black
+                const SizedBox(height: 10,),
+                Ink(
+                  decoration: ShapeDecoration(
+                      shape: const CircleBorder(),
+                      color: Theme.of(context).unselectedWidgetColor
+                  ),
+                  child: IconButton(
+                    icon: const Icon(
+                        Icons.settings,
+                        color: Colors.black
+                    ),
+                    onPressed: () {
+                      Navigator.push(
+                        context,
+                        MaterialPageRoute(builder: (context) => const SettingsPage()),
+                      );
+                    },
                   ),
-                  onPressed: () {
-                    Navigator.push(
-                      context,
-                      MaterialPageRoute(builder: (context) => const SettingsPage()),
-                    );
-                  },
                 ),
-              ),
 
-            ],
-          ),
-        )
+              ],
+            ),
+          );
+        })
     );
   }
 }
\ No newline at end of file