string_plugin_test 0.0.2
string_plugin_test: ^0.0.2 copied to clipboard
A Flutter plugin for returning a string value from platform-specific code
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:string_plugin_test/string_plugin_test.dart';
import 'email_composer.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
final _stringPluginTestPlugin = StringPluginTest();
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion =
await _stringPluginTestPlugin.getPlatformVersion() ?? 'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Custom Email Plugin Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: EmailDemoPage(),
/*Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
Text('Running on: $_platformVersion\n'),
Text(StringPluginTest.getStringValue()),
],
),
),
),*/
);
}
}
class EmailDemoPage extends StatelessWidget {
const EmailDemoPage({Key? key}) : super(key: key);
void _openEmailWithSubject() async {
try {
await StringPluginTest.openEmailWithSubject('[email protected]');
} catch (e) {
debugPrint('Error: $e');
}
}
void _openBlankEmail() async {
try {
await StringPluginTest.openBlankEmail();
} catch (e) {
debugPrint('Error: $e');
}
}
void _shareEmailWithBody() async {
try {
await StringPluginTest.shareEmailWithBody('This is the body of the email.');
} catch (e) {
debugPrint('Error: $e');
}
}
/*void _sendEmail() async {
try {
final emailData = {
'to': '[email protected]',
'subject': 'Custom Subject',
'body': 'This is the email body.',
'cc': '[email protected]',
'bcc': '[email protected]',
};
await StringPluginTest.sendEmail(emailData);
} catch (e) {
debugPrint('Error: $e');
}
}*/
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Email Plugin Example'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ElevatedButton(
onPressed: _openEmailWithSubject,
child: const Text('Open Email with Specific Subject'),
),
ElevatedButton(
onPressed: _openBlankEmail,
child: const Text('Open Blank Email'),
),
ElevatedButton(
onPressed: _shareEmailWithBody,
child: const Text('Share Email with Body Only'),
),
/* ElevatedButton(
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder:(context)=>const EmailComposer()));
}*//*_sendEmail*//*,
child: const Text('Send Custom Email (In-App)'),
),*/
],
),
),
);
}
}