I want to use email
and I use these two packages:
url_launcher: ^6.0.20
mailto: ^2.0.0
and I use this code :
launchMailto() async {
final mailtoLink = Mailto(
to: ['to#example.com'],
cc: ['cc1#example.com', 'cc2#example.com'],
subject: 'mailto example subject',
body: 'mailto example body',
);
await launch('$mailtoLink');
}
but it not work
can anyone help me please how can I use mailto in my project?
and by the way when I change my android manifest, my grade can't run and my project destroy
Try below code
sendMail() async {
const url = 'mailto:youremailid.com';
launchUrl(
Uri.parse(url),
),
}
Your Widget:
ElevatedButton (
child: Text(
' Send Mail',
style: TextStyle(fontSize: 15, color: Colors.blue),
),
onPressed: sendMail,
),
Related
ElevatedButton(
onPressed:() {
launchWhatsapp(phoneNum,message);
},
child: Text("Message the Buyer",
style: TextStyle(
fontWeight: FontWeight.w400
),
),
),
So this is my button code
launchWhatsapp(String number,String text) async{
String url = "https://wa.me/${number}";
if(await canLaunchUrlString(url)){
await launchUrlString(url);
}
and this is my function method. I used url_laucher to make it work but it will redirect to the browser and show this
Image Error but when I try to copy the same link to the browser it works but when trying to open from my app it will show the error as shown in the picture.
Try below code
Your function:
whatsApp() {
return launchUrl(
Uri.parse(
//'https://wa.me/1234567890' //you use this url also
'whatsapp://send?phone=1234567890',//put your number here
),
);
}
Your Widget:
ElevatedButton(
onPressed: () {
whatsApp();
},
child: Text(
"Message the Buyer",
style: TextStyle(fontWeight: FontWeight.w400),
),
),
set internet permission to your AndroidManifest.xml file path = project_name/android/app/src/main/AndroidManifest.xml add below line above of application tag
<uses-permission android:name="android.permission.INTERNET"/>
I am trying to create an android notification channel with flutter_local_notifications: ^5.0.0+4
Put it looks like it does not work as should be.
I wrote a code using getNotificationChannels to verify if the channel was created successfully
Please take a look to my code
Future<void> _getNotificationChannels() async {
await flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()?.createNotificationChannel(AndroidNotificationChannel(
'high_importance_channel', // id
'High Importance Notifications', // title
'This channel is used for important notifications', // description
importance: Importance.max,
));
final Widget notificationChannelsDialogContent =
await _getNotificationChannelsDialogContent();
await showDialog<void>(
context: context,
builder: (BuildContext context) => AlertDialog(
content: notificationChannelsDialogContent,
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('OK'),
),
],
),
);
}
Future<Widget> _getNotificationChannelsDialogContent() async {
try {
final List<AndroidNotificationChannel>? channels =
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()!
.getNotificationChannels();
return Container(
width: double.maxFinite,
child: ListView(
children: <Widget>[
const Text(
'Notifications Channels',
style: TextStyle(fontWeight: FontWeight.bold),
),
const Divider(color: Colors.black),
if (channels?.isEmpty ?? true)
const Text('No notification channels')
else
for (AndroidNotificationChannel channel in channels!)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('id: ${channel.id}\n'
'name: ${channel.name}\n'
'description: ${channel.description}\n'
'groupId: ${channel.groupId}\n'
'importance: ${channel.importance.value}\n'
'playSound: ${channel.playSound}\n'
'sound: ${channel.sound?.sound}\n'
'enableVibration: ${channel.enableVibration}\n'
'vibrationPattern: ${channel.vibrationPattern}\n'
'showBadge: ${channel.showBadge}\n'
'enableLights: ${channel.enableLights}\n'
'ledColor: ${channel.ledColor}\n'),
const Divider(color: Colors.black),
],
),
],
),
);
} on PlatformException catch (error) {
return Text(
'Error calling "getNotificationChannels"\n'
'code: ${error.code}\n'
'message: ${error.message}',
);
}
}
As you can see I am using createNotificationChannel to create a notifications channel then I am using getNotificationChannels to see if the channel was created successfully.
I am getting always "No notification channels" as a result in the dialog.
I do not know what is wrong with my code,
Thanks for your help
The problem was the Android version that I am using for testing,
Notification channels is a concept that is specific Android 8 or newer, which is why the API docs state that the method to create channels is only for those versions of Android
I am trying to show a webpage in webview via html content. in android and ios flutter_html working good, but in flutter web this library not working.
I also tried this code but got no answer :
IFrameElement iframeElement = IFrameElement()
..src = 'url'
..style.border = 'none'
..onLoad.listen((event) {
// perform you logic here.
});
ui.platformViewRegistry.registerViewFactory(
'webpage',
(int viewId) => iframeElement,
);
return Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: SizedBox(
width: double.infinity,
height: double.infinity,
child: HtmlElementView(viewType: 'webpage'),
),
),
);
Is there any another way to show the html content in the flutter web application?
I am now using flutter html to render the html content page in my app, this is the library address: https://pub.dev/packages/flutter_html. The code I am using look like this:
if (item.content != "")
Html(
data: item.content,
style: {
"body": Style(
fontSize: FontSize(19.0),
),
},
onLinkTap: (String? url, RenderContext context, Map<String, String> attributes, dom.Element? element){
CommonUtils.launchUrl(url);
}),
the item.content is my html web page source code, hope this help for you.
I'm working with flutter test. I want to test something after tap a widget but I don't know how to find the button. Because I custom it rather than use Icon or iconButton. Also, I can't find it according to its text because another widget has the same name. And also two InkWell widget as you can see. My basic test code is here.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:grpc/grpc.dart';
import 'package:project/page/login.dart';
void main() {
testWidgets('login page test', (WidgetTester tester) async {
// Build our app and trigger a frame
await tester.pumpWidget(Login());
expect(find.text('login'), findsNWidgets(2));
expect(find.text('ID'), findsOneWidget);
expect(find.text('password'), findsOneWidget);
expect(find.text('end'), findsOneWidget);
// how to find my custom button
await tester.tap((find.byElementType(InkWell))); <- my question here
// test other things after tapping the button.
});
}
InkWell(
key: const Key("btnLogin"),
child: ElevatedButton(
onPressed: () {
_decrementCounter();
},
child: const Text(
" Login ",
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white),
),
),
),
Like this also we can do
await tester.tap(find.byKey(const Key('btnLogin')));
await tester.pump();
Instead of find.byElementType() use find.byType().
So your code will be like this:
await tester.tap((find.byType(InkWell)));
Like this you have to mention key (key: const Key("btnLogin"),)
ElevatedButton(
key: const Key("btnLogin"),
onPressed: () {
_decrementCounter();
},
child: const Text(
" Login ",
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white),
),
),
in Widget test
await tester.tap(find.byKey(const Key('btnLogin')));
await tester.pump();
give a key name to your inkwell button like this.
- in your login screen.
InkWell(
key: const Key("login"),
child: ElevatedButton(
onPressed: () {
},
child: const Text(
" Login ",
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white),
),
),
),
**- in your testing file**
var loginButton = find.byKey(const Key('login'));
await tester.tap(login);
I have a CheckboxListTile and a widget in the title tag. How can I create a html text (text + url) to this widget?
My text is: 'Hello Click here!'
I tried this: flutter_html: ^0.10.4
with no luck
Thanks
Edit:
You can try link: ^1.1.0
import 'package:link/link.dart';
...
Link(
child: Text('This is a link to Flutter', style: TextStyle(
decoration: TextDecoration.underline, // add add underline in text
),),
url: 'https://google.com',
onError: _showErrorSnackBar,
),
void _showErrorSnackBar() {
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text('Oops... the URL couldn\'t be opened!'),
),
);
}
...
Output:
Have you tried url_launcher,
RaisedButton(
onPressed: _launchURL,
child: Text('Text'),
),
_launchURL() async {
const url = 'https://flutter.dev';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
You can also try linkify
linkify("Made by https://cretezy.com");
You could try flutter_linkify.
You need to replace Text with Linkify widget.
With this plugin you code might look like this:
Linkify(
onOpen: (link) => print("Clicked ${link.url}!"),
text: "Made by https://cretezy.com",
);