Skip to content

Instantly share code, notes, and snippets.

@ScottS2017
Created September 23, 2018 21:23
Show Gist options
  • Save ScottS2017/9cb8ed6284441df564e67730aef8c868 to your computer and use it in GitHub Desktop.
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)
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