string_plugin_test 0.0.3
string_plugin_test: ^0.0.3 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';
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 _openEmailApp() async {
try {
await StringPluginTest.openEmailApp();
} catch (e) {
debugPrint('Error: $e');
}
}
void _openEmailWithSubject() async {
try {
await StringPluginTest.openEmailWithForSingleReceiverWithSubject('ruchita.bhaskar@gmail.com',"Test Subject");
} catch (e) {
debugPrint('Error: $e');
}
}
void _openEmailWithForSingleReceiverOnly() async {
try {
await StringPluginTest.openEmailWithForSingleReceiverOnly("ruchita.bhaskar@gmail.com");
} catch (e) {
debugPrint('Error: $e');
}
}
void _openEmailWithForMultipleReceiverOnly() async {
try {
await StringPluginTest.openEmailWithForMultipleReceiverOnly(["ruchita.bhaskar@gmail.com","ruchitab@fermion.in"]);
} catch (e) {
debugPrint('Error: $e');
}
}
void _openEmailWithForMultipleReceiverWithSubject() async {
try {
await StringPluginTest.openEmailWithForMultipleReceiverWithSubject(["ruchita.bhaskar@gmail.com","ruchitab@fermion.in"],"Multiple receiver subject");
} catch (e) {
debugPrint('Error: $e');
}
}
void _shareEmailWithBody() async {
try {
await StringPluginTest.openEmailWithBodyOnly('This is the body of the email.');
} catch (e) {
debugPrint('Error: $e');
}
}
/*void _sendEmail() async {
try {
final emailData = {
'to': 'recipient@example.com',
'subject': 'Custom Subject',
'body': 'This is the email body.',
'cc': 'cc@example.com',
'bcc': 'bcc@example.com',
};
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: _openEmailApp,
child: const Text('Open Email App'),
),
ElevatedButton(
onPressed: _openEmailWithSubject,
child: const Text('Open Email with Specific Subject'),
),
ElevatedButton(
onPressed: _openEmailWithForSingleReceiverOnly,
child: const Text('Open Email with single receiver'),
),
ElevatedButton(
onPressed: _openEmailWithForMultipleReceiverOnly,
child: const Text('Open Email with multiple receiver'),
),
ElevatedButton(
onPressed: _openEmailWithForMultipleReceiverWithSubject,
child: const Text('Open Email with multiple receiver with subject'),
),
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)'),
),*/
],
),
),
);
}
}