receive_intent_android34/example/lib/main.dart

78 lines
1.9 KiB
Dart
Raw Normal View History

import 'dart:async';
import 'package:flutter/material.dart' hide Intent;
import 'package:receive_intent/receive_intent.dart';
void main() {
runApp(const MyApp());
}
2022-07-21 08:12:34 +02:00
/// Example app widget for the plugin.
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);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
2023-05-20 18:42:40 +02:00
Intent? _initialIntent;
@override
void initState() {
super.initState();
_init();
}
Future<void> _init() async {
final receivedIntent = await ReceiveIntent.getInitialIntent();
if (!mounted) return;
setState(() {
_initialIntent = receivedIntent;
});
}
2023-05-20 18:42:40 +02:00
Widget _buildFromIntent(String label, Intent? intent) {
return Center(
child: Column(
children: [
Text(label),
Text(
"fromPackage: ${intent?.fromPackageName}\nfromSignatures: ${intent?.fromSignatures}"),
Text(
'action: ${intent?.action}\ndata: ${intent?.data}\ncategories: ${intent?.categories}'),
Text("extras: ${intent?.extra}")
],
),
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
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?>(
stream: ReceiveIntent.receivedIntentStream,
builder: (context, snapshot) =>
_buildFromIntent("STREAMED", snapshot.data),
)
],
),
),
),
);
}
}