launch_args 1.0.0 copy "launch_args: ^1.0.0" to clipboard
launch_args: ^1.0.0 copied to clipboard

outdated

A new flutter plugin project.

example/lib/main.dart

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

Future<void> main(List<String> args) async {
  WidgetsFlutterBinding.ensureInitialized();
  args = args?.isNotEmpty == true ? args : (await LaunchArgs.args);

  runApp(MyApp(args: args));
}

class MyApp extends StatelessWidget {
  MyApp({this.args});

  final List<String> args;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Launch Args'),
        ),
        body: ListView(
          children: [
            for (var arg in args ?? <String>['n/a'])
              ListTile(
                title: Text(arg),
              ),
          ],
        ),
      ),
    );
  }
}