Bootstrap a Flutter app
■ Create project
■ App name
■ Basic permissions in Android
■ macOS entitlements
■ macOS persist window location and size
■ macOS floating window
■ Blank slate Flutter app
■ Version control
This is an interactive post to bootstrap a Flutter project and do basic changes to setup the project. These configurations are highly opinionated.
Create project
flutter create helloworld --platforms android,ios
App name
For Android, change in android/app/src/main/AndroidManifest.xml
:
<application android:label="Hello World"
For iOS, change in ios/Runner/Info.plist
:
<key>CFBundleName</key> <string>Hello World</string>
For Linux, change in linux/my_application.cc
:
if (use_header_bar) { GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); gtk_widget_show(GTK_WIDGET(header_bar)); gtk_header_bar_set_title(header_bar, "Hello World"); gtk_header_bar_set_show_close_button(header_bar, TRUE); gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); } else { gtk_window_set_title(window, "Hello World"); }
For macOS, change in macos/Runner/Configs/AppInfo.xcconfig
:
PRODUCT_NAME = Hello World
For Windows, change in windows/runner/main.cpp
:
if (!window.CreateAndShow(L"Hello World", origin, size)) { return EXIT_FAILURE; }
Basic permissions in Android
Edit android/app/src/main/AndroidManifest.xml
:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
macOS entitlements
This is for non-appstore publishing. For app store you will need to enable sandbox and disable jit.
Edit macos/Runner/DebugProfile.entitlements
and macos/Runner/Release.entitlements
:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.security.app-sandbox</key> <false/> <key>com.apple.security.cs.allow-jit</key> <true/> <key>com.apple.security.network.server</key> <true/> <key>com.apple.security.network.client</key> <true/> </dict> </plist>
macOS persist window location and size
Edit macos/Runner/MainFlutterWindow.swift
:
override func awakeFromNib() { self.setFrameAutosaveName("MainWindow")
macOS floating window
This keeps the window always on top of all windows. I find it useful while debugging.
Edit macos/Runner/MainFlutterWindow.swift
:
override func awakeFromNib() { self.level = .floating
Blank slate Flutter app
import 'package:flutter/material.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); runApp(App()); } class App extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'App', debugShowCheckedModeBanner: false, theme: ThemeData( primarySwatch: Colors.blue, ), home: Home(), ); } } class Home extends StatefulWidget { @override _HomeState createState() => _HomeState(); } class _HomeState extends State<Home> { @override Widget build(BuildContext context) { return Scaffold( body: Column( children: [], ), ); } }
Version control
git init .
git add .
git commit -m "init"