AppBar 中的搜索功能导致异常

Search feature in AppBar causes Exception

我正在尝试在我的应用栏中实现搜索功能,但一直收到此异常。我不知道这里出了什么问题。如果我删除 TextFormField 或使用任何其他小部件 excpe TextFormField 或 TextField,一切都会正常进行。例如,如果我使用另一个 Text 小部件而不是 TextFormField 那么它就可以正常工作。问题仅出在 TextField 上。 我该怎么办?

异常:

我要归档的内容:

我的代码:

  import 'package:flutter/material.dart';
    import 'package:get/get.dart';
    import 'package:votefun/Menu/main_menu_shop.dart';
    import 'package:votefun/Menu/main_menu_user.dart';
    import 'package:votefun/Menu/main_menu_visiter.dart';
    import 'package:votefun/Utils/app_pages.dart';
    
    class MyAppBar extends StatelessWidget with PreferredSizeWidget {
      @override
      final Size preferredSize;
      final String title;
      final bool drawer;
      final int drawerNumber;
      final bool search;
      final String hint;
    
      MyAppBar(
          {Key? key,
          required this.title,
          required this.drawer,
          required this.drawerNumber,
          required this.search,
          required this.hint})
          : preferredSize = const Size.fromHeight(50.0),
            super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return SafeArea(
          child: ClipPath(
            clipper: MyClipper(),
            child: Container(
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              //width: double.infinity,
              height: 55,
              child: Material(
                elevation: 20,
                child: Row(
                  children: [
                    const SizedBox(
                      width: 8.0,
                    ),
                    Visibility(
                      visible: (drawer == true) ? false : true,
                      child: IconButton(
                          onPressed: () {
                            Navigator.pop(context);
                          },
                          icon: const Icon(Icons.arrow_back_ios)),
                    ),
                    Visibility(
                      visible: (drawer == true) ? true : false,
                      child: IconButton(
                          onPressed: () {
                            if (drawerNumber == 1)
                              (Navigator.of(context).push(PageRouteBuilder(
                                opaque: false,
                                  pageBuilder: (BuildContext context, _, __) =>
                                      MainMenuUser())));
                            else if (drawerNumber == 2)
                              (Navigator.of(context).push(PageRouteBuilder(
                                opaque: false,
                                  pageBuilder: (BuildContext context, _, __) =>
                                      MainMenuShop())));
                            else {
                              Navigator.of(context).push(PageRouteBuilder(
                                opaque: false,
                                  pageBuilder: (BuildContext context, _, __) =>
                                      MainMenuVisiter()));
                            }
                          },
                          icon: const Icon(Icons.menu)),
                    ),
                    Visibility(visible: (search == true) ? false : true,
                      child: Expanded(
                        child: Text(
                          title,
                          style: const TextStyle(
                              fontSize: 17, fontWeight: FontWeight.bold),
                        ),
                      ),
                    ),
                    Visibility(visible: (search == true) ? true : false,
                      child: 
                      TextFormField(decoration: InputDecoration(hintText: 'hint'),
                      maxLines: 1,
                      minLines: 1,),
                      ),
                    Container(
                        padding: const EdgeInsets.only(right: 5),
                        child: IconButton(
                            onPressed: () {
                              Get.offAllNamed(Routes.SignIn);
                            },
                            icon: Image.asset('images/homeicon.png')))
                  ],
                ),
              ),
            ),
          ),
        );
      }
    }
    
    class MyClipper extends CustomClipper<Path> {
      @override
      Path getClip(Size size) {
        var path = Path();
        path.lineTo(0.0, size.height);
        path.lineTo(size.width, size.height / 1.18);
        path.lineTo(size.width, 0.0);
        path.close();
        return path;
      }
    
      @override
      bool shouldReclip(covariant CustomClipper<Path> oldClipper) {
        return false;
      }
    }

知道了,异常原因是TextField的宽度不限