Blank White screen after opening Flutter app

4,466

You need to call the function below after the imports in your root route or main page

void main() => runApp(LoadingScreen());
Share:
4,466
Akash Pinnaka
Author by

Akash Pinnaka

Updated on December 15, 2022

Comments

  • Akash Pinnaka
    Akash Pinnaka over 1 year

    I am pretty new to flutter and I recently created a weather app with the help of an online course . The app runs and works fine on the android emulator and when I run it on my phone. But I wanted to share the app so i created a release apk using flutter build apk --split-per-abi but after installing the app on their mobiles the first screen loads and immediately a blank white screen appears and nothing happens. Such error doesn't arise when i run the app in android studio

    My first loading screen page

    import 'package:flutter/material.dart';
    import 'package:flutter_spinkit/flutter_spinkit.dart';
    import '../services/weather.dart';
    import 'location_screen.dart';
    import 'package:location_permissions/location_permissions.dart';
    
    class LoadingScreen extends StatefulWidget {
      @override
      _LoadingScreenState createState() => _LoadingScreenState();
    }
    
    class _LoadingScreenState extends State<LoadingScreen> {
    
      @override
      void initState() {
        getWeatherData();
        super.initState();
      }
    
      void getWeatherData () async {
        PermissionStatus permission = await LocationPermissions().requestPermissions();
        var weatherData =  await WeatherModel().getWeather();
        Navigator.push(context, MaterialPageRoute(builder: (context){
          return LocationScreen(weatherData: weatherData);
        }));
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: SpinKitFoldingCube(
            color: Colors.blueAccent,
            size: 100,
            ),
        )
        );
        }
      }
    

    My second Weather location screen

    import 'package:clima/services/weather.dart';
    import 'package:flutter/material.dart';
    import 'package:clima/utilities/constants.dart';
    import 'city_screen.dart';
    import '../services/weather.dart';
    
    class LocationScreen extends StatefulWidget {
      final weatherData;
      LocationScreen({this.weatherData});
      @override
      _LocationScreenState createState() => _LocationScreenState();
    }
    
    class _LocationScreenState extends State<LocationScreen> {
      int temperature;
      String icon;
      String message;
      String cityName;
      String summary;
    
      TimeOfDay t = TimeOfDay.now();
      @override
      void initState() {
        super.initState();
        updateScreen(widget.weatherData);
      }
    
      AssetImage setBackground(){
        print(t.hour);
        if(t.hour >18 || t.hour < 6)
          return AssetImage("images/night.png");
        else
          return AssetImage('images/after_noon.png');
      }
      void updateScreen(dynamic weatherData) {
        setState(() {
          if (weatherData == null) {
            temperature = 0;
            icon = 'error';
            message = 'Sorry Coudnt load Weather ';
            cityName = '';
            summary='';
          } else {
            double temp = (weatherData['main']['temp']);
            temperature = temp.toInt();
            icon = WeatherModel().getWeatherIcon(weatherData['weather'][0]['id']);
            message = WeatherModel().getMessage(temperature);
            cityName = weatherData['name'];
            summary=weatherData['weather'][0]['description'];
          }
        });
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: setBackground(),
                fit: BoxFit.cover,
                colorFilter: ColorFilter.mode(
                    Colors.white.withOpacity(0.8), BlendMode.dstATop),
              ),
            ),
            constraints: BoxConstraints.expand(),
            child: SafeArea(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      FlatButton(
                        onPressed: () async {
                          updateScreen(WeatherModel().getWeather());
                        },
                        child: Icon(
                          Icons.near_me,
                          size: 50.0,
                        ),
                      ),
                      FlatButton(
                        onPressed: () async{
                          var cityName = await Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (context) {
                                return CityScreen();
                              },
                            ),
                          );
    
                          if(cityName != null)
                            {
                              var weatherData = await WeatherModel().getCityWeather(cityName);
                              updateScreen(weatherData);
                            }
                        },
                        child: Icon(
                          Icons.location_city,
                          size: 50.0,
                        ),
                      ),
                    ],
                  ),
                  Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Padding(
                        padding: EdgeInsets.only(left: 15.0),
                        child: Row(
                          children: <Widget>[
                            Text(
                              '$temperature',
                              style: kTempTextStyle,
                            ),
                            Text(
                              '$icon',
                              style: kConditionTextStyle,
                            ),
                          ],
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.only(left: 15.0),
                        child: Text(
                          "$summary",
                          style: TextStyle(
                            fontSize: 30,
                            fontFamily: 'Spartan MB',
                            fontStyle: FontStyle.italic,
                          ),
                        ),
                      ),
                    ],
                  ),
                  Padding(
                    padding: EdgeInsets.only(right: 15.0),
                    child: Text(
                      "$message in $cityName",
                      textAlign: TextAlign.right,
                      style: kMessageTextStyle,
                    ),
                  ),
                ],
              ),
            ),
          ),
        );
      }
    }
    
  • Akash Pinnaka
    Akash Pinnaka about 4 years
    I am calling the runApp in a different file called main.dart and am also making sure loading screen works . The problem is that after the loading screen loads and fetches data it doesn't route to the second page and a blank screen comes up.