Skip to content

CupertinoNavigationBar animation flickering #42988

Description

@antekone

Steps to Reproduce

After updating Flutter to v1.9.1+hotfix.4, I'm getting a weird flickering in CupertinoNavigationBar when changing pages. Here's a video that demonstrates the issue, please look at NavigationBar during changing screens:

https://youtu.be/MmUaFUVVtyo

Sometimes it's flickering, sometimes it's not, but most of the time it is flickering. If a button exists in the trailing property, this button sometimes is rendered below the navigation bar for a few frames, and it goes back into proper position. It looks very ugly.

I'm using very simple method for creation of the page:

import 'package:flutter/cupertino.dart';

class AddNewDuePage extends StatefulWidget {
  @override
  _AddNewDuePageState createState() => _AddNewDuePageState();
}

class _AddNewDuePageState extends State<AddNewDuePage> {
  Widget buildBody() {
    return Text("OK");
  }

  @override
  Widget build(BuildContext context) {
    var _navigationBar = CupertinoNavigationBar(
      middle: Text("Nowa składka"), // TODO: I18N
    );

    return CupertinoPageScaffold(
      navigationBar: _navigationBar,
      child: SafeArea(child: buildBody()),
    );
  }
}

Is this a problem with my Flutter installation, or is it a regression?

The problem exists in Debug compilations on Emulator & real hardware, as well as in Release compilations in real hardware (can't run release compilation in emulator).

Target Platform: Linux (emulator) + Android
Target OS version/browser: 9
Devices: Android Emulator, also Sony Xperia XZ Premium

Flutter doctor

$ flutter doctor -v
[✓] Flutter (Channel stable, v1.9.1+hotfix.4, on Linux, locale en_US.UTF-8)
    • Flutter version 1.9.1+hotfix.4 at /home/antek/dev/android/flutter
    • Framework revision cc949a8e8b (3 weeks ago), 2019-09-27 15:04:59 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0

[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /home/antek/Android/Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /home/antek/Android/Sdk
    • Java binary at: /home/antek/dev/android/android-studio/jre/bin/java
    • Java version openjdk version "1.8.0_152-release"
    ✗ Android license status unknown.
      Try re-installing or updating your Android SDK Manager.
      See https://developer.android.com/studio/#downloads or visit https://flutter.dev/setup/#android-setup
      for detailed instructions.

[✓] Android Studio (version 3.4)
    • Android Studio at /home/antek/dev/android/android-studio
    • Flutter plugin version 35.3.1
    • Dart plugin version 183.6270
    • Java version openjdk version "1.8.0_152-release"

[!] IntelliJ IDEA Community Edition (version 2019.2-old)
    • IntelliJ at /home/antek/data/apps/idea/idea-IC-192.5728.98
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.dev/intellij-setup/#installing-the-plugins

[✓] Connected device (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

! Doctor found issues in 2 categories.

Not sure why doctor didn't detect flutter/dart plugins for IDEA, because I'm using Idea with those plugins. Also everything is working with my Android toolchain, also not sure why doctor has issues with licenses.

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Oct 18, 2019
  2. HansMuller commented on Oct 18, 2019

    @HansMuller
    Contributor
  3. justinmc commented on Oct 18, 2019

    @justinmc
    Contributor

    I was able to reproduce this with a very simple app, so it seems to be a regression bug in Flutter! Thanks for reporting.

    import 'package:flutter/cupertino.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return CupertinoApp(
          title: 'Flutter Demo',
          home: MyHomePage(title: 'First Page'),
          routes: {
            '/second': (BuildContext context) => MyHomePage(title: 'Second Page'),
          },
        );
      }
    }
    
    class MyHomePage extends StatelessWidget {
      MyHomePage({Key key, this.title}) : super(key: key);
    
      final String title;
    
      @override
      Widget build(BuildContext context) {
        return CupertinoPageScaffold(
          navigationBar: CupertinoNavigationBar(
            middle: Text(title),
          ),
          child: Center(
            child: CupertinoButton(
              child: Text('Go'),
              onPressed: () {
                Navigator.pushNamed(context, '/second');
              },
            ),
          ),
        );
      }
    }
  4. justinmc commented on Oct 18, 2019

    @justinmc
    Contributor

    It seems to have been caused by #31614 based on me trying old versions.

  5. justinmc commented on Oct 18, 2019

    @justinmc
    Contributor

    @gspencergoog Do you have any idea why that PR may have caused the text in CupertinoNavigationBar to flicker between routes? Nothing jumps out as super obvious to me.

  6. justinmc commented on Oct 18, 2019

    @justinmc
    Contributor

    Some details:

    I confirmed that #31614 is the first change that has the bug in it. Checking out its merge commit, 7775c23, exhibits the bug, but checking out the commit directly before it, fdd554f, does not.

    That PR is a re-land of #30040. If I check out the merge commit from that original PR, 4218c0b, then I do not see the bug.

  7. LongCatIsLooong commented on Oct 20, 2019

    @LongCatIsLooong
    Contributor

    There's a different issue reported here that looks related, video: http://treefortress.com/shared/2019-10-20_09-49-24.mp4.

    I can manually size the container to get rid of it, but these containers are variable width, depending on the size of their text, so that's not ideal.

    Could there be a problem with text sizing? From the description it feels like we're not giving the Text widget the width it needs.

    Doesn't seem to be a typography problem. During the Hero transition the Rect's size is sometimes off by a small number (e.g. 34 -> 33.9999999999997).

  8. esDotDev commented on Oct 21, 2019

    @esDotDev

    Here's a minimal code example that should reproduce the problem. Click the text to trigger the transition, you should see it flicker intermittently:
    http://treefortress.com/shared/2019-10-21_00-40-24.mp4

    It seems related to horizontal movement. If I change alignments so it animates vertically, (TopLeft > BottomLeft), it doesn't flicker at all.

    Wrapping the Text() in a Row(mainAxisSize: MainAxisSize.min) seems to prevent the flicker.

    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(home: Page1());
      }
    }
    
    class Page1 extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: GestureDetector(
            child: Container(
              child: HeroContent(),
              alignment: Alignment.centerLeft,
            ),
            onTap: () {
              Navigator.of(context).push(PageRouteBuilder(
                pageBuilder: (_, __, ___) => Page2(),
                transitionDuration: Duration(seconds: 2),
              ));
            },
          ),
        );
      }
    }
    
    class Page2 extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Container(
            alignment: Alignment.centerRight,
            child: HeroContent(),
          ),
        );
      }
    }
    
    class HeroContent extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Hero(
          tag: "hero",
          child: Material(
            child: Container(
              child: Text(
                "FooBar",
                overflow: TextOverflow.visible,
                style: TextStyle(fontSize: 42 ),
              ),
            ),
          ),
        );
      }
    }
    
  9. esDotDev commented on Oct 21, 2019

    @esDotDev

    Small update, using Row() does not completely get rid of the issues. When using Row() + MaterialRectArcTween, I get overflow errors in extremely small values:

    The following assertion was thrown during layout:
    A RenderFlex overflowed by 0.000895 pixels on the right.

    The most robust fix I've found so far is to just wrap the text in spaces " FooBar ".

  10. antekone commented on Oct 28, 2019

    @antekone
    Author

    Surrounding text with spaces indeed helps with flickering, but doesn't help when sometimes the "trailing" widget in CupertinoNavigationBar is displayed in the wrong place for few frames.

    I'll try downgrading Flutter to previous version, it was much more stable than now.

  11. antekone commented on Dec 15, 2019

    @antekone
    Author

    Unfortunately this issue still exists in 1.12.13+hotfix.5

  12. justinmc commented on Dec 16, 2019

    @justinmc
    Contributor

    @antekone Can you try it on master? I just tried my example app above on my iPhone 7 and I couldn't reproduce the problem.

  13. antekone commented on Dec 18, 2019

    @antekone
    Author

    Do you mean channel master?

    When testing your example app on version 1.13.3-pre.60 / channel master on an Android phone (Xperia G8141), as well as on Android emulator, the problem still exists.

    Flutter 1.13.3-pre.60 • channel master • https://github.com/flutter/flutter.git
    Framework • revision ceef460a64 (6 hours ago) • 2019-12-18 00:23:02 -0800
    Engine • revision 500f9cedf6
    Tools • Dart 2.8.0 (build 2.8.0-dev.0.0 2d332ee1d3)
    

    I don't own a Mac, so I can't check it on an iPhone.

  14. 6 remaining items

  15. added
    a: qualityA truly polished experience
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    on Mar 30, 2020
  16. LevinGermann commented on Apr 28, 2020

    @LevinGermann

    I experience the same issue, it really seems to be related to horizontal movement. Interesting though is that only the last part flickers, see reference here:

    https://youtu.be/uO5BjCTElY8

  17. antekone commented on Jun 7, 2020

    @antekone
    Author

    Still there in this version:

    Flutter 1.17.3 • channel stable • https://github.com/flutter/flutter.git
    Framework • revision b041144f83 (3 days ago) • 2020-06-04 09:26:11 -0700
    Engine • revision ee76268252
    Tools • Dart 2.8.4
    
  18. rakeshh025 commented on Jul 1, 2020

    @rakeshh025

    Any updates or workaround?

  19. moodstubos commented on Feb 2, 2021

    @moodstubos

    still there on 1.22.6

  20. nt4f04uNd commented on May 19, 2021

    @nt4f04uNd
    Member

    This is caused by RelativeRect in used in transitions may produce a small overflow from floating point subtraction. The fix is quite simple - just add precisionErrorTolerance to them. I'm wondering how many else places in the framework may contain something unobvious like this

  21. added
    r: fixedIssue is closed as already fixed in a newer version
    on Sep 1, 2021
  22. github-actions commented on Sep 15, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  23. locked as resolved and limited conversation to collaborators on Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: animationAnimation APIsa: qualityA truly polished experiencec: regressionIt was better in the past than it is nowfound in release: 1.21Found to occur in 1.21frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: cupertino_uicupertino_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions