颤振中两条不同路线的相同表单小部件

问题描述

实际上我创建了一个包含表单小部件的页面 addInventoryPageformkey(GlobalKey<FormState>()) 并且有一些业务要求使用不同路由的相同页面 (routes1:/inventory,routes2:/openingInventory) 带有一些额外的参数。

但是当我从 /inventory 路由切换到 /openingInventory 路由时,我得到的 fromKey 为 null

这里是addInventoryPage的代码

class StateCommonPage extends StatelessWidget {
  InventoryTabController _inventoryTabController = Get.find();
  VariationController _variationController = Get.find();

  CommonWidget _commonWidget = CommonWidget();
  ValidationMethods _validationMethods = ValidationMethods();
  final description = TextEditingController();
  final quantity = TextEditingController();
  GlobalKey<FormState> formKey=GlobalKey<FormState>(debugLabel: 'STATE COMMON');

  final States titleText;
  double width;
  double height;

  StateCommonPage({this.titleText});

  @override
  Widget build(BuildContext context) {
    width = Get.width * 0.95;
    height = Get.height;

    return Scaffold(
      body: Center(
        child: Container(
          height: height * 0.6,child: Form(
            key:formKey,child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,children: [
                Text(
                  'Fill Details of ${titleText.toString().split('.').last.capitalizefirst} '
                  'Process',style: Theme.of(context).textTheme.headline2,),..........

用于在路由之间切换 Get.offNamed('inventory');

这是我的自定义抽屉

    class CustomDrawer extends StatelessWidget {
 Widget buildMenuListTile(BuildContext context,Menus menu) {
        return Obx(
          () => menu.menuCode == 'INVENTORY'
              ? custom.ExpansionTile(
                  initiallyExpanded: true,children: buildSubMenuTile(context,menu.menuCode),leading: Icon(
                    Finals.menuIconMap[menu.menuCode],size: 24,color: Theme.of(context).primaryColor,title: Text(
                    menu.menuName,style: menu.menuCode == selectedMenuId.value
                        ? Theme.of(context).textTheme.headline4
                        : Theme.of(context).textTheme.headline3,)
              : ListTile(
                  selectedTileColor: Theme.of(context).accentColor.withOpacity(0.3),selected: menu.menuCode == selectedMenuId.value,hoverColor: Theme.of(context).primaryColor,onTap: () {
                    Get.offNamed(menu.relativePath);
                  }),);
      }

          }

这是我的路线

class Routes {
 
  static const INVENTORY = '/inventory';
 
  static const opening_INVENTORY = '/openingInventory';

  Map<String,WidgetBuilder> test;

  static final routes = [
   
    GetPage(
      name: INVENTORY,page: () => InventoryBottomTabBar(),binding: BindingsBuilder.put(() => InventoryTabController()),GetPage(
      name: opening_INVENTORY,binding:
          BindingsBuilder.put(() => InventoryTabController()),)
}

调试日志

在完成小部件树时抛出以下断言: 在小部件树中检测到重复的 GlobalKey。

在小部件中多次指定了以下 GlobalKey 树。这将导致部分小部件树被截断 没想到,因为第二次看到一个键,之前的 实例移动到新位置。关键是:

  • [LabeledGlobalKey#0db7f] 这是通过注意到在将具有上述全局键的小部件移出其 前一个父级,前一个父级在此帧期间从未更新, 这意味着它要么根本没有更新,要么在更新之前更新 小部件被移动,在任何一种情况下都意味着它仍然认为它 应该有一个拥有该全局密钥的孩子。这样做的特定父母 由于以下原因强行移除一个或多个孩子后不更新 GlobalKey 重新父级是:
  • ConstrainedBox(BoxConstraints(0.0

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...