2021-04-23 07:15:26 +02:00
|
|
|
import 'dart:async';
|
|
|
|
|
2021-06-20 09:23:12 +02:00
|
|
|
import 'package:flutter/material.dart' hide Intent;
|
2021-04-23 07:15:26 +02:00
|
|
|
import 'package:receive_intent/receive_intent.dart';
|
|
|
|
|
|
|
|
void main() {
|
2022-07-20 08:05:17 +02:00
|
|
|
runApp(const MyApp());
|
2021-04-23 07:15:26 +02:00
|
|
|
}
|
|
|
|
|
2022-07-21 08:12:34 +02:00
|
|
|
/// Example app widget for the plugin.
|
2021-04-23 07:15:26 +02:00
|
|
|
class MyApp extends StatefulWidget {
|
2022-07-21 08:12:34 +02:00
|
|
|
/// Constructor of MyApp widget.
|
2023-05-20 18:42:40 +02:00
|
|
|
const MyApp({Key? key}) : super(key: key);
|
2022-07-20 08:05:17 +02:00
|
|
|
|
2021-04-23 07:15:26 +02:00
|
|
|
@override
|
2022-07-20 08:05:17 +02:00
|
|
|
State<MyApp> createState() => _MyAppState();
|
2021-04-23 07:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class _MyAppState extends State<MyApp> {
|
2023-05-20 18:42:40 +02:00
|
|
|
Intent? _initialIntent;
|
2021-04-23 07:15:26 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2021-04-23 10:36:07 +02:00
|
|
|
_init();
|
2021-04-23 07:15:26 +02:00
|
|
|
}
|
|
|
|
|
2021-04-23 10:36:07 +02:00
|
|
|
Future<void> _init() async {
|
|
|
|
final receivedIntent = await ReceiveIntent.getInitialIntent();
|
|
|
|
|
2021-04-23 07:15:26 +02:00
|
|
|
if (!mounted) return;
|
|
|
|
|
|
|
|
setState(() {
|
2021-04-23 10:36:07 +02:00
|
|
|
_initialIntent = receivedIntent;
|
2021-04-23 07:15:26 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-05-20 18:42:40 +02:00
|
|
|
Widget _buildFromIntent(String label, Intent? intent) {
|
2021-04-23 10:36:07 +02:00
|
|
|
return Center(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Text(label),
|
|
|
|
Text(
|
2022-02-04 12:23:00 +01:00
|
|
|
"fromPackage: ${intent?.fromPackageName}\nfromSignatures: ${intent?.fromSignatures}"),
|
2021-04-23 10:36:07 +02:00
|
|
|
Text(
|
2022-02-04 12:23:00 +01:00
|
|
|
'action: ${intent?.action}\ndata: ${intent?.data}\ncategories: ${intent?.categories}'),
|
|
|
|
Text("extras: ${intent?.extra}")
|
2021-04-23 10:36:07 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-23 07:15:26 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: const Text('Plugin example app'),
|
|
|
|
),
|
2021-04-23 10:36:07 +02:00
|
|
|
body: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 20),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
children: [
|
|
|
|
_buildFromIntent("INITIAL", _initialIntent),
|
2023-05-20 18:42:40 +02:00
|
|
|
StreamBuilder<Intent?>(
|
2021-04-23 10:36:07 +02:00
|
|
|
stream: ReceiveIntent.receivedIntentStream,
|
|
|
|
builder: (context, snapshot) =>
|
|
|
|
_buildFromIntent("STREAMED", snapshot.data),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2021-04-23 07:15:26 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|