skip to Main Content

I created flutter app, it is using PostgreSQL as DB and opening external websites for product related info. This is working as expected in emulator. Created apk file with the command flutter build apk --build-name 1.0 --build-number 1 and installed in my mobile.

The app is not able to load data from database. Not sure I whether I missed any steps while creating the apk or other. Can someone help me?

2

Answers


  1. Chosen as BEST ANSWER

    This is the complete code,

    class Authorize extends StatefulWidget {
      const Authorize({super.key});
    
      @override
      State<Authorize> createState() => _AuthorizeState();
    }
    
    class _AuthorizeState extends State<Authorize> {
      late Future<List<dynamic>> _custList;
    
      @override
      void initState() {
        super.initState();
        //_futureList = fetchListData();
        _custList = ModelsPositions().getCust();
      }
    
      _launchURL(String url) async {
        final uri = Uri.parse(url);
        if (await canLaunchUrl(uri)) {
          await launchUrl(uri, mode: LaunchMode.externalApplication);
        } else {
          throw 'Could not launch $url';
        }
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            appBar: AppBar(
              title: const Text('sample orders'),
            ),
            //automaticallyImplyLeading: false),
            body: FutureBuilder<List<dynamic>>(
              future: _custList,
              builder: (context, snapshot) {
                if (snapshot.hasData) {
                  List<dynamic> custAPIs = snapshot.data ?? [];
                  return ListView.builder(
                      itemCount: custAPIs.length,
                      itemBuilder: (context, index) {
                        String custID = custAPIs[index][0];
                        return Card(
                          child: Row(
                            children: [
                              SizedBox(width: 50),
                              Expanded(
                                child: Text('custID: $custID'),
                              ),
                              SizedBox(width: 15),
                              Expanded(
                                child: ElevatedButton(
                                    child: const Text('check'),
                                    onPressed: () {
                                      String url =
                                          "https://www.amazon.in/";
                                      _launchURL(url);
                                    }),
                              ),
                            ],
                          ),
                        );
                      });
                } else if (snapshot.hasError) {
                  return const Center(
                      child: Text('Failed to fetch Positions Summary'));
                }
                return const Center(child: CircularProgressIndicator());
              },
            ));
      }
    }
    

    I'm installed apk file in mobile and trying to open from mobile.(When I tried in emulator working fine but after generating apk and installing in mobile it is not opening the webpage).


  2. try replacing your _launchURL with this :

      _launchURL(String url) async {
        final uri = Uri.parse(url);
          await launchUrl(uri, mode: LaunchMode.externalApplication); 
      }
    

    In your android/app/src/main/androidManifest.xml add this line before <application

    <uses-permission android:name="android.permission.INTERNET"/>
    

    Like this :

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search