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",
);
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"/>
This question already has answers here:
Flutter (Dart) How to add copy to clipboard on tap to a app?
(5 answers)
Closed 8 months ago.
I have to copy data of a certian field to the clipboard when the textbutton.icon is pressed.How can I do that?
Try below code, refer setData and ClipboardData or you can be use clipboard package
import below library/package in your code
import 'package:flutter/services.dart';
Your Widget:
InkWell(
onTap: () {
Clipboard.setData(
ClipboardData(
text: "Your Copy text",
),
);
},
child: Text("Your Copy text"),
),
Have you tried googling?
First google result:
import 'package:flutter/services.dart';
onTap: () {
Clipboard.setData(ClipboardData(text: "your text"));
},
source: https://www.codegrepper.com/code-examples/dart/how+to+copy+text+to+clipboard+flutter
Please try below code
Using ClipBoard
// copy to clipboard
Future<void> _copyToClipboard() async {
await Clipboard.setData(ClipboardData(text: "Text to be copied"));
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Copied to clipboard'),
));
}
IconButton(
icon: const Icon(Icons.copy),
onPressed: _copyToClipboard,
),
// Get Data From System Clipboard
String _textValue = '';
void _getClipboard() async {
ClipboardData data = await Clipboard.getData(Clipboard.kTextPlain);
setState(() {
_textValue = data.text;
});
}
// or You can replace Clipboard.kTextPlain with text/plain to getData // from Clipboard.
ClipboardData data = await Clipboard.getData('text/plain');
Using Selectable Text
SelectableText(
"text to be copied" ?? "",
style: TextStyle(color: Colors.blue, fontWeight: FontWeight.bold, fontSize: 48),
textAlign: TextAlign.center,
toolbarOptions: ToolbarOptions(copy: true, selectAll: true),
),
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,
),
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);
This project can be found here:https://github.com/Santos-Enoque/flutter_blog_app
So far I have this connected to firebase realtime database and it works well. I'm trying to add a like button to the Home page(lib/screens/home.dart) where all the posts are listed.
The Homepage displays the blog results using a Card with a ListTile. The trailing property of the ListTile card is already used so I'd like to use the leading property of the ListTile card to display a favourite icon which would increment a counter++ when tapped and also save the results to Firebase. Just like Facebook's like button.
Here's the code below:
child: Card(
child: ListTile(
title: ListTile(
onTap: (){
_incrementCounter();
},
leading: FittedBox(
fit: BoxFit.fitWidth,
child: Row(
children: <Widget>[
Icon(Icons.favorite),
Text(postsList[index].counter.toString()
),
],
),
),
title: Text(
postsList[index].title,
style: TextStyle(
fontSize: 16.0, fontWeight: FontWeight.bold),
),
trailing: Text(
timeago.format(DateTime.fromMillisecondsSinceEpoch(postsList[index].date)),
style: TextStyle(fontSize: 12.0, color: Colors.grey),
),
),
subtitle: Padding(
padding: const EdgeInsets.only(bottom: 14.0),
child: Text(postsList[index].body, style: TextStyle(fontSize: 14.0),),
),
),
),
Here's the _increment counter code:
try {
var ref = FirebaseDatabase.instance.reference().child('posts/{postId}/counter');
await ref.once().then((data) async => {
await ref.set(data.value + 1),
});
} catch (e) {
print(e.message);
}
}
![Home page of blog]https://photos.google.com/share/AF1QipMK6C-Wx2vZHHbE2jDMQsfYNnwl9OWK_5W8OKOfiIChcXt-gnWnCH7ba_EpyRnRAA?key=cGxkRkVSSk9PQTdtTXB0MzZBRDNHNUVzSGxlcDVB
The blog posts are displayed as cards as in the image ... I'm trying to add an icon on the left side of the card(leading) plus an incrementing value everytime someone taps the icon. Something like the like button on facebook. And also save the data to firebase realtime database.
Any help is much appreciated ... Thank you all!
I think what you may want to do is add this function to your onPressed. You will also need to set the text of the next to the icon equal to the new value read.
void like() async {
try {
var ref = FirebaseDatabase.instance.reference().child('path to likes for a post');
await ref.once().then((data) async => {
await ref.set(data.value + 1);
});
} catch (e) {
print(e.message);
}
}
Hope this helps.
P.S.- You may find this video of use: https://www.youtube.com/watch?v=l8_7RTRRmHo
Thanks to everyone who helped with this:
Code for UI:
leading: FittedBox(
fit: BoxFit.fitWidth,
child: Row(
children: <Widget>[
Icon(Icons.favorite),
Text(postsList[index].counter.toString()
),
],
),
),
Code for Function:
onTap: (){
_incrementCounter(postsList[index].key);
}
...
void _incrementCounter(key) async {
try {
var ref = FirebaseDatabase.instance.reference().child('posts/'+ key +'/counter');
await ref.once().then((data) async => {
await ref.set(data.value + 1),
});
} catch (e) {
print(e.message);
}
}
}