commandline_or_gui_windows 1.1.1 copy "commandline_or_gui_windows: ^1.1.1" to clipboard
commandline_or_gui_windows: ^1.1.1 copied to clipboard

outdated

Allows your app to run as either commandline or gui. Windows only.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:commandline_or_gui_windows/commandline_or_gui_windows.dart';

// not part of plugin, added to add commandline input
import 'package:args/args.dart';

void main(List<String> args) async {
  /*
   not part of plugin, added to add commandline input
   ref:
   https://pub.dev/packages/args
   if run from shell:
   .\commandline_or_gui_windows_example.exe -a
   it will run in commandline mode
   if run from shell:
   .\commandline_or_gui_windows_example.exe
   it will run in gui mode
  */
  ArgParser parser = ArgParser();
  parser.addFlag(
    "automation",
    abbr: "a",
  );

  bool errors = false;
  bool commandlineMode = false;
  try {
    ArgResults results = parser.parse(args);
    commandlineMode = results["automation"];
  } catch (err) {
    /* ignore parsing errors, and load in gui mode */
    errors = true;
  }

  // part of plugin, main entry. This runciton runs runApp
  await CommandlineOrGuiWindows.runAppCommandlineOrGUI(
    // if you want to run in gui or commandline mode
    commandline: commandlineMode, // parsed option from above

    // code you want to run if in commandline mode
    afterLoaded: () async {
      // await CommandlineOrGuiWindows.syncStdOutAndStdErrWithConsole();
      await CommandlineOrGuiWindows.stdout("Hello World");
      await CommandlineOrGuiWindows.stderr("I broke nooooooo");
    },

    // gui of the app
    gui: MaterialApp(
      home: Scaffold(
        body: Center(
          child: Text("This is the gui of the app. Error detected: $errors"),
        ),
      ),
    ),
  );
}
8
likes
0
pub points
33%
popularity

Publisher

unverified uploader

Allows your app to run as either commandline or gui. Windows only.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on commandline_or_gui_windows