Created
March 23, 2020 16:28
-
-
Save Andrious/321a81f2c1c7b0af521f29315b3ae52c to your computer and use it in GitHub Desktop.
MyApp Class for the 'Write Your First App' example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io' show Platform; | |
import 'package:flutter/foundation.dart' show kIsWeb; | |
import 'package:flutter/cupertino.dart' | |
show BuildContext, CupertinoApp, Key, StatelessWidget, Widget; | |
import 'package:flutter/material.dart' show MaterialApp; | |
import '../view/home/home.dart' show RandomWords; | |
class MyApp extends StatelessWidget { | |
MyApp({ | |
this.key, | |
this.android = false, | |
this.iOS = false, | |
this.switchUI = false, | |
}) { | |
_useMaterial = android; | |
_useCupertino = iOS; | |
_switchUI = switchUI; | |
} | |
final Key key; | |
final bool android; | |
final bool iOS; | |
final bool switchUI; | |
static bool _useMaterial; | |
static bool _useCupertino; | |
static bool _switchUI; | |
@override | |
Widget build(BuildContext context) { | |
String title = 'Startup Name Generator'; | |
Widget home = RandomWords(key: key); | |
if (useCupertino) { | |
return CupertinoApp( | |
title: title, | |
home: home, | |
); | |
} else { | |
return MaterialApp( | |
title: title, | |
home: home, | |
); | |
} | |
} | |
// Use Material UI when explicitly specified or even when running in iOS | |
static bool get useMaterial => | |
kIsWeb || | |
(_useMaterial && !_useCupertino) || | |
(Platform.isAndroid && !_switchUI && !_useCupertino) || | |
(Platform.isIOS && _switchUI); | |
// Use Cupertino UI when explicitly specified or even when running in Android | |
static bool get useCupertino => | |
(_useCupertino && !_useMaterial) || | |
(Platform.isIOS && !_switchUI && !_useMaterial) || | |
(Platform.isAndroid && _switchUI); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment