(It would be interesting if this was possible for mobile as well, however at the moment I specifically want to achieve this on Linux/Windows)
I would like to be able delay the creation of the GUI / window to a time of my choosing.
Flutter seems to create the window regardless of the dart code - if I comment out RunApp it still creates a blank window.
// Creates an empty window.
void main() {
// runApp(MyApp());
}
RunApp seems to load the content of the window.
// Creates an empty window. After 5 seconds the app content appears in that window.
void main() {
Future.delayed(Duration(seconds: 5)).then((value) => runApp(MyApp()));
}
Ideally I would be able to do work before the window tries to load, or parse command-line arguments.
Example of what I am trying to achieve:
import 'package:flutter/material.dart';
import 'package:args/args.dart';
class Config {
static bool simple = false;
}
void main(List<String> args) {
var parser = ArgParser();
parser.addFlag(
'simple',
abbr: 's',
defaultsTo: false,
callback: (simple) {
if (simple) {
Config.simple = true;
}
},
);
parser.parse(args);
if (Config.simple) {
// --simple flag received.
// No GUI, simple background work.
} else {
// No --simple flag, load GUI.
runApp(MyApp());
}
}
class MyApp extends StatelessWidget { ...
question from:
https://stackoverflow.com/questions/66050680/is-there-a-way-to-control-when-the-gui-part-of-flutter-desktop-runs 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…