Browse Source

added orientation handling

Eray Sönmez 9 months ago
parent
commit
d751fe4249
1 changed files with 15 additions and 8 deletions
  1. 15 8
      lib/startseite.dart

+ 15 - 8
lib/startseite.dart

@@ -1,5 +1,6 @@
1 1
 import 'dart:async';
2 2
 import 'dart:convert';
3
+import 'package:flutter/services.dart';
3 4
 import 'package:http/http.dart' as http;
4 5
 import 'package:flutter/material.dart';
5 6
 import 'package:my_first_app/router.dart';
@@ -27,6 +28,7 @@ class _StartSeiteState extends State<StartSeite> {
27 28
 
28 29
   @override
29 30
   void initState() {
31
+    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
30 32
     super.initState();
31 33
     printPreferences();
32 34
     Network.registerSubscription(updateUI);
@@ -55,6 +57,9 @@ class _StartSeiteState extends State<StartSeite> {
55 57
 
56 58
   @override
57 59
   Widget build(BuildContext context) {
60
+    print(MediaQuery.of(context).orientation == Orientation.portrait);
61
+    bool portrait = MediaQuery.of(context).orientation == Orientation.portrait;
62
+
58 63
     return Scaffold(
59 64
         key: scaffoldKey,
60 65
         body: Center(
@@ -80,7 +85,7 @@ class _StartSeiteState extends State<StartSeite> {
80 85
                     },
81 86
                   )),
82 87
             ),
83
-            Center(child: Container(child: Image.asset("assets/images/drake.jpg"))),
88
+            //Center(child: Container(child: Image.asset("assets/images/drake.jpg"))),
84 89
             Center(
85 90
                 child: RaisedButton(
86 91
                     color: Colors.black,
@@ -158,13 +163,15 @@ class _StartSeiteState extends State<StartSeite> {
158 163
                     child: Text("Gib mir einen Namen!", style: TextStyle(color: Colors.white)))),
159 164
             Center(
160 165
               child: RaisedButton(
161
-                  onPressed: () async {
162
-                    SharedPreferences prefs = await _prefs;
163
-                    setState(() {
164
-                      generatedPersons.clear();
165
-                      prefs.setStringList("Personenliste", List<String>());
166
-                    });
167
-                  },
166
+                  onPressed: !portrait
167
+                      ? null
168
+                      : () async {
169
+                          SharedPreferences prefs = await _prefs;
170
+                          setState(() {
171
+                            generatedPersons.clear();
172
+                            prefs.setStringList("Personenliste", List<String>());
173
+                          });
174
+                        },
168 175
                   child: Text("Liste leeren")),
169 176
             ),
170 177
             Center(