Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@ import UIKit
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
GeneratedPluginRegistrant.register(with: self)
// Get root FlutterViewController
guard let controller = window?.rootViewController as? FlutterViewController else {
fatalError("rootViewController is not FlutterViewController")
}

// Create a MethodChannel named "launch_arguments"
let channel = FlutterMethodChannel(name: "launch_arguments", binaryMessenger: controller.binaryMessenger)

// Get launch arguments from native iOS
let arguments = ProcessInfo.processInfo.arguments

// Handle method calls from Flutter
channel.setMethodCallHandler { call, result in
if call.method == "getLaunchArguments" {
result(arguments)
} else {
result(FlutterMethodNotImplemented)
}
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
40 changes: 40 additions & 0 deletions lib/launch_arguments_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class LaunchArgumentsScreen extends StatefulWidget {
const LaunchArgumentsScreen({Key? key}) : super(key: key);

@override
State<LaunchArgumentsScreen> createState() => _LaunchArgumentsScreenState();
}

class _LaunchArgumentsScreenState extends State<LaunchArgumentsScreen> {
List<String> _arguments = [];

@override
void initState() {
super.initState();
_fetchArguments();
}

Future<void> _fetchArguments() async {
const platform = MethodChannel('launch_arguments');
final args = await platform.invokeMethod<List<dynamic>>('getLaunchArguments');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the logic here in the way we expect in docs:

https://docs.maestro.dev/api-reference/commands/launchapp#receiving-arguments-in-flutter

I dont think we consume in same way here

setState(() {
_arguments = args?.map((e) => e.toString()).toList() ?? [];
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Launch Arguments")),
body: ListView.builder(
itemCount: _arguments.length,
itemBuilder: (context, index) {
return ListTile(title: Text(_arguments[index]));
},
),
);
}
}
11 changes: 10 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:demo_app/swiping_screen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:demo_app/launch_arguments_screen.dart';

class HackyDrawPointersBinding extends IntegrationTestWidgetsFlutterBinding {
HackyDrawPointersBinding() {
Expand All @@ -17,7 +18,7 @@ class HackyDrawPointersBinding extends IntegrationTestWidgetsFlutterBinding {
HackyDrawPointersBinding().framePolicy =
LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
assert(
WidgetsBinding.instance is HackyDrawPointersBinding,
WidgetsBinding.instance is HackyDrawPointersBinding,
);
return WidgetsBinding.instance;
}
Expand Down Expand Up @@ -116,6 +117,14 @@ class _MyHomePageState extends State<MyHomePage> {
},
child: const Text('Input Test'),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => const LaunchArgumentsScreen()),
);
},
child: const Text('Launch Argument Test'),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
Expand Down