实际上我创建了一个包含表单小部件的页面
addInventoryPage
和 formkey(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),
leading: Icon(
Finals.menuIconMap[menu.menuCode],
size: 24,
color: Theme.of(context).primaryColor,
),
selected: menu.menuCode == selectedMenuId.value,
hoverColor: Theme.of(context).primaryColor,
title: Text(
menu.menuName,
style: menu.menuCode == selectedMenuId.value
? Theme.of(context).textTheme.headline4
: Theme.of(context).textTheme.headline3,
),
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,
page: () => InventoryBottomTabBar(),
binding:
BindingsBuilder.put(() => InventoryTabController()),
)
}
调试日志
<块引用>在完成小部件树时抛出以下断言: 在小部件树中检测到重复的 GlobalKey。
在小部件中多次指定了以下 GlobalKey 树。这将导致部分小部件树被截断 没想到,因为第二次看到一个键,之前的 实例移动到新位置。关键是: