Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

Is there a way to control when the GUI part of Flutter desktop runs?

(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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...