Home > Back-end >  Flutter Sending SMS with URL_launcher with body text gat form dialog
Flutter Sending SMS with URL_launcher with body text gat form dialog

Time:06-15

I am trying to send sms to 31003 where my sms content will be "LS" space "user license number" but after update my plugin URL_launcher to 6.1.3 its showing some error.

    import 'package:flutter/material.dart';
    import 'package:get/get.dart';
    import 'package:url_launcher/url_launcher.dart';
    
    final Uri _url1 = Uri.parse('sms:31003?body=LC ');
    final textFieldController = TextEditingController();
    
    class SeeSms extends StatelessWidget {
      const SeeSms({Key? key}) : super(key: key);
      
    
      @override
      Widget build(BuildContext context) {
        return GridView.count(
          crossAxisCount: 2,
          primary: false,
          padding: const EdgeInsets.all(20),
          crossAxisSpacing: 5,
          mainAxisSpacing: 5,
          childAspectRatio: 1,
          children: <Widget>[
            InkWell(
              onTap: _launchURL1,
              child: Container(
                //padding: const EdgeInsets.all(10),
                padding: const EdgeInsets.only(top: 20),
                decoration: BoxDecoration(
                  image: const DecorationImage(
                    image: AssetImage('assets/images/ntc.png'),
                    fit: BoxFit.cover,
                  ),
                  borderRadius: BorderRadius.circular(10),
                  boxShadow: const [
                    BoxShadow(
                      color: Color(0x19000000),
                      blurRadius: 20,
                      offset: Offset(0, 1),
                    ),
                  ],
                ),
              ),
            ),
          ],
        );
      }
    
      _launchURL1() async {
        // get license number from user via dialog
        String licenseNumber = await Get.defaultDialog(
          radius: 3,
          titlePadding: const EdgeInsets.only(top: 20, bottom: 20),
          contentPadding: const EdgeInsets.only(left: 20, right: 20),
          title: 'Enter License Number',
          content: TextField(
            controller: textFieldController,
            autofocus: true,
            decoration: const InputDecoration(
              hintText: 'Example: 01-01-00012345',
            ),
          ),
          confirm: Padding(
            padding: const EdgeInsets.only(bottom: 20.0, top: 20.0),
            child: ElevatedButton(
              child: const Text('Send SMS '),
              onPressed: () {
                Get.back();
                launchUrl(_url1   textFieldController.text);
              },
            ),
          ),
        );
      }
    }

every this is fine but "The argument type 'String' can't be assigned to the parameter type 'Uri'" gating this error. this issue is on

CodePudding user response:

Are you sure that is the error you are getting? I would rather suspect this:

The argument type 'dynamic' can't be assigned to the parameter type 'Uri'.

Either way, since url_launcher version 6.1.0, the method launchUrl() takes a URI as parameter and not a String. So you have to pass e.g. _url1 to the method as launchUrl(_url1)

Furthermore, if I'm not mistaken, you cannot simple use the operator between a URI and a String as you do when you do _url1 textFieldController.text when you want to pass that to the launchUrl()-method

  • Related