Created
September 23, 2018 21:23
-
-
Save ScottS2017/9cb8ed6284441df564e67730aef8c868 to your computer and use it in GitHub Desktop.
New default main.dart Live Template that can handle desktop embedding (IntelliJ Live Template)
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'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/foundation.dart' | |
show debugDefaultTargetPlatformOverride; | |
void main() { | |
debugDefaultTargetPlatformOverride = TargetPlatform.android; | |
_setTargetPlatformForDesktop(); | |
runApp($MyApp$()); | |
} | |
void _setTargetPlatformForDesktop() { | |
TargetPlatform targetPlatform; | |
if (Platform.isMacOS) { | |
targetPlatform = TargetPlatform.iOS; | |
} else if (Platform.isLinux || Platform.isWindows) { | |
targetPlatform = TargetPlatform.android; | |
} | |
if (targetPlatform != null) { | |
debugDefaultTargetPlatformOverride = targetPlatform; | |
} | |
} | |
class $MyApp$ extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: "$TitleDisplayedInRecentAppsList$", | |
theme: ThemeData( | |
primarySwatch: Colors.$Color$, | |
), | |
home: $HomePage$(title: "$TitleDisplayedInTheAppBar$"), | |
); | |
} | |
} | |
class $HomePage$ extends StatelessWidget { | |
String title; | |
HomePage({ | |
@required this.title, | |
}) : | |
assert(title != null); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(title), | |
), | |
body: $END$, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment