简体   繁体   中英

Flutter app runs perfectly on android studio emulator but doesn't go past the loading screen on physical device

I've created a simple flutter app to tell me the weather using a weather API and the HTTP package. The app runs as intended on my emulated device and for testing, on a physical device, I built a fat apk using `flutter build ask. Unfortunately, the app doesn't go past the loading screen on physical devices(I've tested it on multiple devices).

android manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.appbrewery.clima">

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

loading screen

import 'package:clima/services/weather.dart';
import 'package:flutter/material.dart';
import 'location_screen.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

class LoadingScreen extends StatefulWidget {
  @override
  _LoadingScreenState createState() => _LoadingScreenState();
}

class _LoadingScreenState extends State<LoadingScreen> {
  @override
  void initState() {
    super.initState();
    getlocationdata();
  }

  void getlocationdata() async {
    WeatherModel weatherModel = WeatherModel();
    var weatherdata = await weatherModel.getlocationweather();
    Navigator.push(context, MaterialPageRoute(builder: (context) {
      return LocationScreen(
        locationweather: weatherdata,
      );
    }));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SpinKitChasingDots(
          color: Colors.white,
          size: 50,
        ),
      ),
    );
  }
}

What's going wrong? I'm stuck. Any help would be appreciated!

You can process like that:

Comment the line with getlocationdata(); Then run with flutter run

If it work, look in debug mode why that doesn't work. If it still not work, so try to replace the SpinKitChasingDots by Text("test") .

Good luck

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