Flutter 颤振-临时错误-图标按钮小部件需要材质小部件

Flutter 颤振-临时错误-图标按钮小部件需要材质小部件,flutter,flutter-layout,Flutter,Flutter Layout,我得到这个错误: IconButton小部件需要材质小部件祖先 大约一秒钟,然后它就消失了。它抱怨我的一个自定义小部件中有一个图标按钮。但是,自定义小部件放置在带有支架的页面中。因此,该错误不应该存在,因为自定义按钮位于Scaffoldmaterial小部件中。当我将按钮的用法包装在自己的微型支架中时,所有问题都解决了。为什么我会暂时得到这个错误?将自定义小部件包装在一个微小的脚手架中被认为是黑客修复还是实际修复?所有代码和完整错误如下: 错误: The following assertion

我得到这个错误:

IconButton小部件需要材质小部件祖先

大约一秒钟,然后它就消失了。它抱怨我的一个自定义小部件中有一个图标按钮。但是,自定义小部件放置在带有
支架的页面中。因此,该错误不应该存在,因为自定义按钮位于
Scaffold
material小部件中。当我将按钮的用法包装在自己的微型
支架中时,所有问题都解决了。为什么我会暂时得到这个错误?将自定义小部件包装在一个微小的
脚手架中
被认为是黑客修复还是实际修复?所有代码和完整错误如下:

错误:

The following assertion was thrown building IconButton(Icon, padding: EdgeInsets.zero, 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.zero
    dirty
The ancestors of this widget were
    VpBackButton
    Align
        alignment: centerLeft
        dependencies: [Directionality]
        renderObject: RenderPositionedBox#49b68 NEEDS-LAYOUT NEEDS-PAINT
    Expanded
        flex: 1
    Row
        direction: horizontal
        mainAxisAlignment: center
        crossAxisAlignment: center
        textBaseline: alphabetic
        dependencies: [Directionality]
        renderObject: RenderFlex#19d87 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
    GetMaterialApp
    App
    ...
The relevant error-causing widget was
IconButton
lib/…/back_button/back_button_widget.dart:18
When the exception was thrown, this was the stack
#0      debugCheckHasMaterial.<anonymous closure>
package:flutter/…/material/debug.dart:30
#1      debugCheckHasMaterial
package:flutter/…/material/debug.dart:52
#2      IconButton.build
package:flutter/…/material/icon_button.dart:330
#3      StatelessElement.build
package:flutter/…/widgets/framework.dart:4701
#4      ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4627
...
════════════════════════════════════════════════════════════════════════════════

由于您在
LoggedOutEmailView
中灵活地包装了
VpBackButton
,因此无法在
VpBackButton
中提供固定大小。逻辑错误。如果删除iconsize或expanded,则此问题已修复。

您看到的问题是一个涉及英雄动画的颤振

我看到在您的案例中,
VpBackButton
位于一个
Hero
下。如果删除
英雄
,您将看到错误消失。根据上面链接的bug,目前只有一个解决方法,您自己已经发现了,它是用
材质
小部件包装
英雄
,在您的例子中是
VpBackButton

child: Hero(
    tag: 'logoHero',
    child: Row( <--- wrap this with Material widget***************
        crossAxisAlignment:
            CrossAxisAlignment.center,
        mainAxisAlignment:
            MainAxisAlignment.center,
        children: [
        Expanded(
            flex: 1,
            child: Align(
                alignment: Alignment.centerLeft,
                child: VpBackButton())),
孩子:英雄(
标签:“logoHero”,

child:Row(这是否回答了您的问题?@hasankaraman否,不幸的是,它已经在
LoggedOutEmailView
小部件中的
Scaffold
中了,错误只出现了一秒钟。干杯
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:keyboard_avoider/keyboard_avoider.dart';
import 'package:reactive_forms/reactive_forms.dart';
import 'package:vepo/presentation/themes/home_theme.dart';
import 'package:vepo/presentation/widgets/display/buttons/back_button/back_button_widget.dart';
import 'package:vepo/presentation/widgets/display/buttons/elevated_buttons/elevated_submit_button_widget.dart';
import 'package:vepo/presentation/widgets/display/containers/gradient_container_widget.dart';
import 'package:vepo/presentation/widgets/display/text/subtitle_1_widget.dart';
import 'package:vepo/presentation/widgets/forms/text_field/text_field_widget.dart';
import 'package:vepo/presentation/widgets/pages/gradient_page_scaffold_widget.dart';

import '../../../../assets.gen.dart';
import 'logged_out_email_controller.dart';

class LoggedOutEmailView extends GetView<LoggedOutEmailController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        resizeToAvoidBottomPadding: false,
        body: ConstrainedBox(
            constraints: BoxConstraints.tightFor(
                height: MediaQuery.of(context).size.height),
            child: VpGradientContainer(
                beginColor: initialGradientColor,
                endColor: endGradientColor,
                child: SafeArea(
                    child: Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                      Expanded(
                          flex: 1,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.start,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Expanded(
                                flex: 1,
                                child: Hero(
                                  tag: 'logoHero',
                                  child: Row(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.center,
                                      mainAxisAlignment:
                                          MainAxisAlignment.center,
                                      children: [
                                        Expanded(
                                            flex: 1,
                                            child: Align(
                                                alignment: Alignment.centerLeft,
                                                child: VpBackButton())),
                                        Expanded(
                                            flex: 1,
                                            child: Assets.images.logo.image()),
                                        Expanded(flex: 1, child: Container()),
                                      ]),
                                ),
                              ),
                            ],
                          )),
child: Hero(
    tag: 'logoHero',
    child: Row( <--- wrap this with Material widget***************
        crossAxisAlignment:
            CrossAxisAlignment.center,
        mainAxisAlignment:
            MainAxisAlignment.center,
        children: [
        Expanded(
            flex: 1,
            child: Align(
                alignment: Alignment.centerLeft,
                child: VpBackButton())),