receive_intent_android34/example/lib/main.dart
Harsh Bhikadia ed77c100f0 initial working functionality
- `pupsec`: added `>=2.12.0` constraints to `environment.sdk`
- `ReceivedIntent`: added
- `ReceiveIntent`: `getInitialIntent`, `receivedIntentStream` and `giveResult` added
- `example`: simple working example added
- `ReceiveIntentPlugin`: handling `getInitialIntent` and `giveResult` methods and sending "newIntent" events
2021-04-23 14:06:07 +05:30

73 lines
1.8 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:receive_intent/receive_intent.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
ReceivedIntent _initialIntent;
@override
void initState() {
super.initState();
_init();
}
Future<void> _init() async {
final receivedIntent = await ReceiveIntent.getInitialIntent();
if (!mounted) return;
setState(() {
_initialIntent = receivedIntent;
});
}
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}")
],
),
);
}
@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),
StreamBuilder<ReceivedIntent>(
stream: ReceiveIntent.receivedIntentStream,
builder: (context, snapshot) =>
_buildFromIntent("STREAMED", snapshot.data),
)
],
),
),
),
);
}
}