Skip to content

Instantly share code, notes, and snippets.

@Andrious
Created March 23, 2020 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andrious/321a81f2c1c7b0af521f29315b3ae52c to your computer and use it in GitHub Desktop.
Save Andrious/321a81f2c1c7b0af521f29315b3ae52c to your computer and use it in GitHub Desktop.
MyApp Class for the 'Write Your First App' example.
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