找不到材料小部件在脚手架内找到哪个小部件

时间:2021-01-12 06:46:09

标签: flutter dart material-ui flutter-layout

构建 IconButton(Icon, padding: E​​dgeInsets.all(8.0),dirty) 时抛出以下断言: 未找到 Material 小部件。

但是你会从下面的代码中看到我们有一个 Material 小部件

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: Theme.of(context).platform == TargetPlatform.iOS
          ? CupertinoNavigationBar(
              actionsForegroundColor: Color.fromRGBO(135, 170, 20, 1),
              middle: Text('News Feed'),
              trailing: Wrap(
                // spacing: 12, // space between two icons
                children: <Widget>[
                  IconButton(
                    // padding: EdgeInsets.only(right: 28.0),
                    icon: Icon(CupertinoIcons.person_add_solid),
                    onPressed: () => Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (_) => SearchScreen(),
                      ),
                    ),
                  ),

异常错误

======== Exception caught by widgets library =======================================================
The following assertion was thrown building IconButton(Icon, padding: EdgeInsets.all(8.0), dirty):
No Material widget found.

IconButton widgets require a Material widget ancestor.
In material design, most widgets are conceptually "printed" on a sheet of material. In Flutter's material library, that material is represented by the Material widget. It is the Material widget that renders ink splashes, for instance. Because of this, many material library widgets require that there be a Material widget in the tree above them.

To introduce a Material widget, you can either directly include one, or use a widget that contains Material itself, such as a Card, Dialog, Drawer, or Scaffold.

The specific widget that could not find a Material ancestor was: IconButton
  Icon
  padding: EdgeInsets.all(8.0)
  dirty
The ancestors of this widget were: 
  : Wrap
    direction: horizontal
    alignment: start
    spacing: 0.0
    runAlignment: start
    runSpacing: 0.0
    crossAxisAlignment: 0.0
    dependencies: [Directionality]
    renderObject: RenderWrap#b32a3 NEEDS-LAYOUT NEEDS-PAINT
  : MaterialApp
    state: _MaterialAppState#8caca
  : ChangeNotifierProvider<UserData>
    state: _DelegateWidgetState#ba9bc
  : MyApp
  ...
The relevant error-causing widget was: 
  IconButton file:///Users/paulmcguane/Development/threetwoonego/lib/screens/activity/Feed.dart:108:19
When the exception was thrown, this was the stack: 
#0      debugCheckHasMaterial.<anonymous closure> (package:flutter/src/material/debug.dart:28:7)
#1      debugCheckHasMaterial (package:flutter/src/material/debug.dart:50:4)
#2      IconButton.build (package:flutter/src/material/icon_button.dart:328:12)
#3      StatelessElement.build (package:flutter/src/widgets/framework.dart:4755:28)
#4      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4681:15)
...
====================================================================================================

0 个答案:

没有答案