简体   繁体   中英

flutter using URL launcher plugin does not activate dialer when number tapped

if i prefill the string url with a number like "12345678" when tapped it gets directed to phone dialer no problem but when i use "directory.phone" nothing happens even though print log in terminal shows the different numbers i tap.

                  InkWell(
                      onTap: () {
                        String url = 'tel:' + directory.phone;
                        launch(url);
                        print(directory.phone);
                      },
                      child: Text(
                        directory.phone,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                          fontSize: 12,
                          color: Theme.of(context)
                              .textTheme
                              .bodyText1
                              .color
                              .withAlpha(150),
                        ),
                      ))
                ],

You can check String that returned from API.if it contains spaces remove it. ex:

 String pho=" 555 ".trim();

Update: those that might have the same issue make sure to remove white spaces from the middle of the numbers if any exist which was in my case. (123) 456-7890 is converted to (123)456-7890 allowing Url launcher to work as expected in flutter.

InkWell(
  onTap: () {
   String url = 'tel:' + directory.phone.replaceAll(' ','');
   launch(url);
   print(url);
 },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM