Skip to content

When drawer is open, going to landscape orientation causes the the drawer to close and back button appears instead #34978

@kunibertgangnam

Description

@kunibertgangnam

Hi everybody,
my problem is the following:

My app is mainly built for tablets. I need to show some information based on the orientation of the device either in the drawer (portrait-mode) or in a row (landscape-mode).
In landscape-mode there is no drawer in the Scaffold.
If I rotate the device when the drawer is open (from portrait-mode with open drawer to landscape-mode) an error occurs.
The problem is that the button for opening the drawer becomes a non functional icon-button with a back_arrow icon. This button should only be there in portrait-mode.

The code below is sample code but produces the same error than my application.

Steps to reproduce:

  • copy the following code in IDE
  • start app and rotate to portrait-mode
  • open drawer and rotate to landscape-mode
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: OrientationBuilder(
        builder: (context, orientation){
          if (orientation == Orientation.landscape){
            return landscapeLayout();
          } else {
            return portraitLayout();
          }
        },
      ),
    );
  }

  Widget landscapeLayout(){
    return Scaffold(
      appBar: AppBar(),
      body: Row(
        children: <Widget>[
          Expanded(child: Container(color: Colors.yellow)),
          Expanded(child: Container(color: Colors.red)),
        ],
      ),
    );
  }

  Widget portraitLayout(){
    return Scaffold(
      appBar: AppBar(),
      drawer: Drawer(
        child: Container(color: Colors.yellow),
      ),
      body: Container(color: Colors.red),
    );
  }

}

Logs

[ +131 ms] I/flutter (13687): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
[  +16 ms] I/flutter (13687): The following assertion was thrown while finalizing the widget tree:
[   +1 ms] I/flutter (13687): setState() or markNeedsBuild() called when widget tree was locked.
[        ] I/flutter (13687): This Scaffold widget cannot be marked as needing to build because the framework is locked.
[        ] I/flutter (13687): The widget on which setState() or markNeedsBuild() was called was:
[        ] I/flutter (13687):   Scaffold(dependencies: [_LocalizationsScope-[GlobalKey#1bddb], Directionality, _InheritedTheme,
[        ] I/flutter (13687):   MediaQuery], state: ScaffoldState#0e546(tickers: tracking 1 ticker))
[        ] I/flutter (13687): 
[        ] I/flutter (13687): When the exception was thrown, this was the stack:
[  +10 ms] I/flutter (13687): #0      Element.markNeedsBuild.<anonymous closure> (package:flutter/src/widgets/framework.dart:3520:9)
[        ] I/flutter (13687): #1      Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:3529:6)
[        ] I/flutter (13687): #2      State.setState (package:flutter/src/widgets/framework.dart:1133:14)
[        ] I/flutter (13687): #3      ScaffoldState._drawerOpenedCallback (package:flutter/src/material/scaffold.dart:1283:5)
[        ] I/flutter (13687): #4      DrawerControllerState.close (package:flutter/src/material/drawer.dart:379:14)
[        ] I/flutter (13687): #5      DrawerControllerState._handleHistoryEntryRemoved (package:flutter/src/material/drawer.dart:284:5)
[        ] I/flutter (13687): #6      LocalHistoryEntry._notifyRemoved (package:flutter/src/widgets/routes.dart:339:7)
[        ] I/flutter (13687): #7      _ModalRoute&TransitionRoute&LocalHistoryRoute.removeLocalHistoryEntry (package:flutter/src/widgets/routes.dart:500:11)
[        ] I/flutter (13687): #8      LocalHistoryEntry.remove (package:flutter/src/widgets/routes.dart:333:12)
[        ] I/flutter (13687): #9      DrawerControllerState.dispose (package:flutter/src/material/drawer.dart:241:20)
[        ] I/flutter (13687): #10     StatefulElement.unmount (package:flutter/src/widgets/framework.dart:3916:12)
[        ] I/flutter (13687): #11     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1697:13)
[        ] I/flutter (13687): #12     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1695:7)
[        ] I/flutter (13687): #13     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3770:14)
[        ] I/flutter (13687): #14     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1693:13)
[        ] I/flutter (13687): #15     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1695:7)
[        ] I/flutter (13687): #16     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3770:14)
[        ] I/flutter (13687): #17     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1693:13)
[        ] I/flutter (13687): #18     ListIterable.forEach (dart:_internal/iterable.dart:39:13)
[        ] I/flutter (13687): #19     _InactiveElements._unmountAll (package:flutter/src/widgets/framework.dart:1706:25)
[        ] I/flutter (13687): #20     BuildOwner.finalizeTree.<anonymous closure> (package:flutter/src/widgets/framework.dart:2364:27)
[        ] I/flutter (13687): #21     BuildOwner.lockState (package:flutter/src/widgets/framework.dart:2196:15)
[        ] I/flutter (13687): #22     BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:2363:7)
[        ] I/flutter (13687): #23     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame
(package:flutter/src/widgets/binding.dart:702:18)
[        ] I/flutter (13687): #24     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback
(package:flutter/src/rendering/binding.dart:286:5)
[        ] I/flutter (13687): #25     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1012:15)
[        ] I/flutter (13687): #26     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:952:9)
[        ] I/flutter (13687): #27     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:864:5)
[        ] I/flutter (13687): #31     _invoke (dart:ui/hooks.dart:219:10)
[        ] I/flutter (13687): #32     _drawFrame (dart:ui/hooks.dart:178:3)
[        ] I/flutter (13687): (elided 3 frames from package dart:async)
[        ] I/flutter (13687): ════════════════════════════════════════════════════════════════════════════════════════════════════
[  +14 ms] I/flutter (13687): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3491 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true.
[  +11 ms] I/flutter (13687): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3491 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true.
[  +17 ms] I/flutter (13687): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3491 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true.
[  +17 ms] I/flutter (13687): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3491 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true.
[  +17 ms] I/flutter (13687): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3491 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true.
[  +17 ms] I/flutter (13687): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3491 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true.
[  +16 ms] I/flutter (13687): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3491 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true.
[  +16 ms] I/flutter (13687): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3491 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true.
[  +17 ms] I/flutter (13687): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3491 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true.


Analyzing bug_report...
No issues found! (ran in 1.9s)

[√] Flutter (Channel stable, v1.5.4-hotfix.2, on Microsoft Windows [Version 10.0.17134.829], locale de-DE)
    • Flutter version 1.5.4-hotfix.2 at C:\Arbeit\flutter
    • Framework revision 7a4c33425d (8 weeks ago), 2019-04-29 11:05:24 -0700
    • Engine revision 52c7a1e849
    • Dart version 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)


[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\Users\jmaisl\AppData\Local\Android\Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = C:\Users\jmaisl\AppData\Local\Android\Sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    • All Android licenses accepted.

[√] Android Studio (version 3.4)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 35.3.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[√] Connected device (1 available)
    • SM T813 • 19e3979901444c62 • android-arm64 • Android 7.0 (API 24)

• No issues found!

Metadata

Metadata

Labels

P2Important issues not at the top of the work lista: layoutSystemChrome and Framework's Layout Issuesf: material designflutter/packages/flutter/material repository.found in release: 1.22Found to occur in 1.22found in release: 1.26Found to occur in 1.26frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions