最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

flutter - Widget shows fragmented after task switching on Android - Stack Overflow

programmeradmin0浏览0评论

I am a beginner in working with Flutter and ran into the following issue.

A Widget is built like below:

class WeatherMainPage extends StatefulWidget {
  WeatherMainPage({super.key, required this.sensor});

  final BMESensor sensor;

  @override
  _WeatherMainPageState createState() => _WeatherMainPageState();
}

class _WeatherMainPageState extends State<WeatherMainPage> {
  MyAppState? appState;
@override
  Widget build(BuildContext context) {
    return Consumer<MyAppState>(builder: (context, appstate, child) => contentBuilder(context, appstate, child));
  }

  Future<bool> _initAsync() async {
    await widget.sensor.acquireCurrentWeather();
    await widget.sensor.acquireWeathreForecast();
    return true;
  }

  Widget contentBuilder(BuildContext context, MyAppState state, Widget? child) {
    appState = state;

    return FutureBuilder<bool>(
      future: _initAsync(),
      builder: (context, snapshot) {
        return Scaffold(
          appBar: AppBar(title: Text("Weather details"), centerTitle: true),
          body: Center(
            child: Padding(
              padding: EdgeInsets.all(8.0),
              child:
                  snapshot.hasData
                      ? ListView(
                        //physics: const BouncingScrollPhysics(),
                        children: [
                          CurrentWeather(sensor: widget.sensor),
                          BasicWeatherData(sensor: widget.sensor),
                          Sunrise(sensor: widget.sensor),
                          //HourlyData(),
                          DailyData(sensor: widget.sensor),
                        ],
                      )
                      : Center(child: Stack(children: [Text("Loading data"), CircularProgressIndicator()])),
            ),
          ),
        );
      },
    );
  }

I run the app on Android and I realized that when I switch to a different application on the phone and then switch back, the app screen is not refreshed and gets fragmented like shown on this screenshot:

The Children widgets listed are all Stateful widgets simply presentig data of the passed sensor object

Where shall I search for the root of the problem ?

I am a beginner in working with Flutter and ran into the following issue.

A Widget is built like below:

class WeatherMainPage extends StatefulWidget {
  WeatherMainPage({super.key, required this.sensor});

  final BMESensor sensor;

  @override
  _WeatherMainPageState createState() => _WeatherMainPageState();
}

class _WeatherMainPageState extends State<WeatherMainPage> {
  MyAppState? appState;
@override
  Widget build(BuildContext context) {
    return Consumer<MyAppState>(builder: (context, appstate, child) => contentBuilder(context, appstate, child));
  }

  Future<bool> _initAsync() async {
    await widget.sensor.acquireCurrentWeather();
    await widget.sensor.acquireWeathreForecast();
    return true;
  }

  Widget contentBuilder(BuildContext context, MyAppState state, Widget? child) {
    appState = state;

    return FutureBuilder<bool>(
      future: _initAsync(),
      builder: (context, snapshot) {
        return Scaffold(
          appBar: AppBar(title: Text("Weather details"), centerTitle: true),
          body: Center(
            child: Padding(
              padding: EdgeInsets.all(8.0),
              child:
                  snapshot.hasData
                      ? ListView(
                        //physics: const BouncingScrollPhysics(),
                        children: [
                          CurrentWeather(sensor: widget.sensor),
                          BasicWeatherData(sensor: widget.sensor),
                          Sunrise(sensor: widget.sensor),
                          //HourlyData(),
                          DailyData(sensor: widget.sensor),
                        ],
                      )
                      : Center(child: Stack(children: [Text("Loading data"), CircularProgressIndicator()])),
            ),
          ),
        );
      },
    );
  }

I run the app on Android and I realized that when I switch to a different application on the phone and then switch back, the app screen is not refreshed and gets fragmented like shown on this screenshot:

The Children widgets listed are all Stateful widgets simply presentig data of the passed sensor object

Where shall I search for the root of the problem ?

Share Improve this question asked Mar 19 at 8:01 László FrankLászló Frank 911 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

This was a bug that's been fixed in Flutter 3.29.1. Updating to this or newer Flutter version should do the trick.

[CP][Impeller] Fix text glitch when returning to foreground.

发布评论

评论列表(0)

  1. 暂无评论