how to use url launcher?

505 views
Skip to first unread message

Error Place

unread,
Jun 8, 2020, 9:29:20 AM6/8/20
to Flutter Development (flutter-dev)
hi guys.
my users fill a form with information such as cellphone number , email and website address as Strings. witch are shown in a contact me page. i am trying to use the Url launcher packge to launch them but unsuccessfull, this is my code for launching the  website address!


void _launchUrl(String Url)async{
if(await canLaunch(Url)){
await launch(Url);
}
else{
throw 'can not open Url';
}
}


the users webAddress is Google.com 
FlatButton(
onPressed: () {
_launchUrl(user.webAddress);
},


Suzuki Tomohiro

unread,
Jun 8, 2020, 9:31:24 AM6/8/20
to Error Place, Flutter Development (flutter-dev)
What’s the behavior of the code? Can you elaborate more than “unsuccessful”?

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/9a345999-eab1-4757-aa37-1ef6c1cb8b80o%40googlegroups.com.

Error Place

unread,
Jun 8, 2020, 9:35:32 AM6/8/20
to Flutter Development (flutter-dev)

Error Place

unread,
Jun 8, 2020, 9:36:05 AM6/8/20
to Flutter Development (flutter-dev)
this is what i am getting

[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: can not open Url
#0      _ProfileScreenState._launchUrl (package:/screen/profile_screen.dart:57:7)
<asynchronous suspension>
#1      _ProfileScreenState._displayButton.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:/screen/profile_screen.dart:448:37)
#2      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:779:19)
#3      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:862:36)
#4      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#5      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11)
#6      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:282:5)
#7      BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:254:7)
#8      GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
#9      GestureBinding.handleEvent <…>

Den måndag 8 juni 2020 kl. 15:29:20 UTC+2 skrev Error Place:

Suzuki Tomohiro

unread,
Jun 8, 2020, 9:38:28 AM6/8/20
to Error Place, Flutter Development (flutter-dev)
Good. From the error, I can tell that “await canLaunch” is returning false. Would you try adding “https://“ before the value?


--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.

Suzuki Tomohiro

unread,
Jun 8, 2020, 9:44:04 AM6/8/20
to Error Place, Flutter Development (flutter-dev)
Glad to hear it worked.

On Mon, Jun 8, 2020 at 09:40 Error Place <reza7....@gmail.com> wrote:
You are the king Suzuki. Thank you and thank you🙏🙏🙏

Error Place

unread,
Jun 8, 2020, 10:01:30 AM6/8/20
to Flutter Development (flutter-dev)
now i am getting stuck setting it up for calls. the thing is that users phone numbers get saved as string so i think something is wrong?
can you help me with this one as well?
this is the code for phone calls!
the same solution did not work
void _launchcaller(String number)async{

if(await canLaunch(number)){
await launch(number);
}else
{
throw 'can not place call';
}

}
FlatButton(
onPressed: () {
_launchcaller('tel:' + user.tel);
},

Den måndag 8 juni 2020 kl. 15:29:20 UTC+2 skrev Error Place:

Suzuki Tomohiro

unread,
Jun 8, 2020, 11:20:25 AM6/8/20
to Error Place, Flutter Development (flutter-dev)
Can you give me the URL of the plugin documentation that says “tel:” should work?

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.

Error Place

unread,
Jun 8, 2020, 11:22:58 AM6/8/20
to Flutter Development (flutter-dev)
https://pub.dev/packages/url_launcher

i am not sure if i used it the wrong way!! should i use call instead of tell?


Den måndag 8 juni 2020 kl. 15:29:20 UTC+2 skrev Error Place:

Error Place

unread,
Jun 8, 2020, 11:31:52 AM6/8/20
to Flutter Development (flutter-dev)
this is how i get the phone number from the user

String _tel =  '';

TextFormField(
initialValue: _tel,
style: TextStyle(fontSize: 18.0),
decoration: InputDecoration(
icon: Icon(
Icons.phone,
size: 30.0,
),
labelText: 'Telefonnummer',
),
validator: (input) => input.trim().length > 100
? 'Please enter a valid name'
: null,
onSaved: (input) => _tel = input,
),
so it gets saved as a string ? i am not sure if i have to convert it to integer before try to make the Call Launch?

Den måndag 8 juni 2020 kl. 15:29:20 UTC+2 skrev Error Place:

Suzuki Tomohiro

unread,
Jun 8, 2020, 11:35:34 AM6/8/20
to Error Place, Flutter Development (flutter-dev)
Does this value work?

tel:+1 555 010 999

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.

Suzuki Tomohiro

unread,
Jun 8, 2020, 12:52:41 PM6/8/20
to Error Place, Flutter Development (flutter-dev)
You’re welcome. I didn’t know an Android emulator crashes when it tries to make a call.

On Mon, Jun 8, 2020 at 12:29 Error Place <reza7....@gmail.com> wrote:
I need to thank you Suzuki once again. Everything worked well, I was just stupid enough to not realize that I can’t make a call with the simulator 😅
I ran the app in physical device and everything worked .
Thanks again

mån 8 juni 2020 kl. 17:42 skrev Error Place <reza7....@gmail.com>:
The app crashes and Android studio loses connection with the device😥
Reply all
Reply to author
Forward
0 new messages