Closed opensourcegps closed 5 years ago
To follow up, in case IconButton added 1 sec after initState to the same place, no errors displayed.
That's probably because you are not using MaterialApp
which provides a Material
widget.
If you don't want to use MaterialApp
you can use
return new Scaffold(
appBar: new CupertinoNavigationBar(
middle: new Text('test'),
trailing: Material(child: IconButton(icon: Icon(Icons.settings))),
),
body: Text('test'),
);
There are several Material widgets that depend on having a Material
widget as parent.
I'm using MaterialApp in main.dart. There is some bug, because it blinks the error on the screen, and fixes it itself. Without MaterialApp, it would just stay in error state.
Thanks for Material(), it helps to resolve this without using delays.
Might be my mistake that Material
is still required.
Glad to hear you could make it work.
I assume this can be closed then.
Please consider asking support questions in one of the other channels listed at http://flutter.io/support .
@zoechi this is a bug, because with Scaffold Material() should not be required. Material() just provides a workaround.
This code should not generate that error, because Scaffold
already provides Material support.
return new Scaffold(
appBar: new CupertinoNavigationBar(
middle: new Text('test'),
trailing: IconButton(icon: Icon(Icons.settings)),
),
body: Text('test'),
);
Scaffold
wraps the body
in a Material
AppBar
also wraps its content in a Material
CupertinoNavigationBar
does not, obviously.
Then why if you put IconButton there after 1 sec, everything is fine. It would also display error, because no Material present. Anyway, not going to fight to keep it open.
if you put IconButton there after 1 sec, everything is fine
not sure what you mean with that.
It's not about fighting. I'm happy to reopen when I think there is something that should be changed. To me it seems we should be able to find a common understanding here. This issue doesn't look too complicated 😄
I have the same problem. In my test, this works:
Future
But this doesn't produces the error above:
Future
I have the same problem, the error blink and it's gone after a few secs. Using Scaffold
and AppBar
as a parent.
Fixed it like this:
Material(
color: Colors.transparent,
child:_popup_menu
),
I have the same problem, the error blinks. I was checking my app and I could notice that if I unwrap my widget from the Hero widget (commenting it, because my problematic widget is wrapper in a Hero) the error disappear. I think the error occur during the transition generated by the Hero widget.
Blinking material error feels like a bug, but please open a new issue and possibly provide some video demo as this report is closed and will not be reviewed by flutter team.
you should CupertinoScaffold the if you're using CupertinoNavigationBar, CupertinoScaffold provides all the Cupertino widget
Scaffold
wraps thebody
in aMaterial
AppBar
also wraps its content in aMaterial
CupertinoNavigationBar
does not, obviously.
This is incorrect. CupertinoNavigationBar is somehow removing any transitive material ancestor. This breaks the definition of ancestor. I have the CupertinoNavigationBar inside the Material Scaffold body but it still has the same issue.
I also think this is a bug and should be re-opened. I came across the same behaviour when routing from one screen to another, where both screens have Scaffolds as the root widget, and both contain the same sub-widget wrapped in a Hero. Like @agallardol, I also find the error disappears if I get rid of the Hero, so I'm pretty sure this is where the problem lies.
Here's a minimal reproducible example. You start on a screen with an edit icon. If you press the button labelled "Navigate", it will route to a second screen which has the same widget containg the icon. The icon is wrapped in a Hero. When navigating, it will throw the same error as reported in the original post, briefly show an error on the device screen, then it seems to sort itself out after a second. It complains about no Material, even though there is a Scaffold as an ancestor. If you remove the Hero, the problem goes away.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material bug',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
MyWidget(),
RaisedButton(
child: Text("Navigate"),
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (_) => MySecondPage(),
));
},
)
],
),
);
}
}
class MySecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: MyWidget()
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Hero(
tag: "my_hero_tag",
child: IconButton(icon: Icon(Icons.edit), onPressed: () {},),
)
);
}
}
Having the same error even after making a minimal reproducible sample.
The official flutter docs use an InkWell widget for the onTap: function
https://flutter.dev/docs/development/ui/animations/hero-animations#standard-hero-animation-code
I was able to get the expected result by changing to a GestureDetector Widget instead. I am unsure why it would work differently and the documentation talks about using an Inkwell widget.
I had a same issue but after changing
runApp(
child: MaterialApp(
title: '-----',
debugShowCheckedModeBanner: false,
theme: -----.theme,
home: Splash(),
onGenerateRoute: router.generateRoute,
)
)
to
runApp(new Material (
child: MaterialApp(
title: '----',
debugShowCheckedModeBanner: false,
theme: ----.theme,
home: Splash(),
onGenerateRoute: router.generateRoute,
)
)
)
Its Working fine.
Could anyone tell me why it is not supposed to work? and throws the same error I tried this here
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Navigation Basics',
home: FirstRoute(),
));
}
class FirstRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Route'),
),
body: Center(
child: RaisedButton(
child: Text('Open route'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
},
),
),
);
}
}
class SecondRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Second Route"),
),
body: Center(
child: RaisedButton(
onPressed: () {
showBottomSheet(
context: context,
builder: (context) => Container(color:Colors.red),
);
},
child: Text('Go back!'),
),
),
);
}
}
`` ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════ The following assertion was thrown while handling a gesture: No Scaffold widget found. SecondRoute widgets require a Scaffold widget ancestor. The specific widget that could not find a Scaffold ancestor was: SecondRoute The ancestors of this widget were: ... Semantics Builder RepaintBoundary-[GlobalKey#b7d7b] IgnorePointer AnimatedBuilder ... Typically, the Scaffold widget is introduced by the MaterialApp or WidgetsApp widget at the top of your application widget tree.
When the exception was thrown, this was the stack:
Error: No Scaffold widget found.
SecondRoute widgets require a Scaffold widget ancestor.
The specific widget that could not find a Scaffold ancestor was:
SecondRoute
The ancestors of this widget were:
Semantics
Builder
RepaintBoundary-[GlobalKey#b7d7b]
IgnorePointer
AnimatedBuilder
FadeTransition
FractionalTranslation
SlideTransition
_FadeUpwardsPageTransition
AnimatedBuilder
RepaintBoundary
_FocusMarker
Semantics
FocusScope
PageStorage
Offstage
_ModalScopeStatus
_ModalScope
Handler: "onTap" Recognizer: TapGestureRecognizer#6fb4a ════════════════════════════════════════════════════════════════════════════════════════════════════ ``
I had a same issue but after changing
runApp( child: MaterialApp( title: '-----', debugShowCheckedModeBanner: false, theme: -----.theme, home: Splash(), onGenerateRoute: router.generateRoute, ) )
to
runApp(new Material ( child: MaterialApp( title: '----', debugShowCheckedModeBanner: false, theme: ----.theme, home: Splash(), onGenerateRoute: router.generateRoute, ) ) )
Its Working fine.
"This is the absoloute solution for the problem . Thank you very much bro"
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.
Steps to Reproduce
Following code will blink the error (red box) on the screen for 0.5 sec and then everything becomes normal:
Logs