2021-04-23 07:15:26 +02:00
|
|
|
import 'dart:async';
|
|
|
|
|
2021-04-23 10:36:07 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2021-04-23 07:15:26 +02:00
|
|
|
import 'package:receive_intent/receive_intent.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
runApp(MyApp());
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_MyAppState createState() => _MyAppState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MyAppState extends State<MyApp> {
|
2021-04-23 10:36:07 +02:00
|
|
|
ReceivedIntent _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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-23 10:36:07 +02:00
|
|
|
Widget _buildFromIntent(String label, ReceivedIntent intent) {
|
|
|
|
return Center(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Text(label),
|
|
|
|
Text(
|
|
|
|
"fromPackage: ${intent?.fromPackageName}\nfromSignatures: ${_initialIntent?.fromSignatures}"),
|
|
|
|
Text(
|
|
|
|
'action: ${_initialIntent?.action}\ndata: ${_initialIntent?.data}\ncategories: ${_initialIntent?.categories}'),
|
|
|
|
Text("extras: ${_initialIntent?.extra}")
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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),
|
|
|
|
StreamBuilder<ReceivedIntent>(
|
|
|
|
stream: ReceiveIntent.receivedIntentStream,
|
|
|
|
builder: (context, snapshot) =>
|
|
|
|
_buildFromIntent("STREAMED", snapshot.data),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2021-04-23 07:15:26 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|