android – FlutterError : The important thing [LabeledGlobalKey] was utilized by a number of widgets

[ad_1]

I am getting an error whereas attempting to navigate to the menu_screen widget. I am fairly certain that the GlobalKey menuFormKey isn’t used inside one other widget however I do not perceive why I am getting this downside.

There’s the code of menu_screen :

import 'dart:async';

import 'package deal:flutter/materials.dart';

class MenuScreen extends StatefulWidget {
  bool darkish;
  Menu menu;
  MenuScreen({Key? key, required this.darkish, required this.menu})
      : tremendous(key: RIKeys.riKey3);

  @override
  State<MenuScreen> createState() => _MenuScreenState();
  static String id = "MenuScreen";
}

class _MenuScreenState extends State<MenuScreen> {
  last StreamController<Menu> _currentMenuStreamCtrl =
      StreamController<Menu>.broadcast();
  Stream<Menu> get onCurrentMenuChanged => _currentMenuStreamCtrl.stream;
  void updateCurrentMenuUI() => _currentMenuStreamCtrl.add(widget.menu);
  GlobalKey<FormState> menuformKey =
      GlobalKey<FormState>(debugLabel: "menu type Key");
  @override
  Widget construct(BuildContext context) {
    Measurement deviceSize = MediaQuery.of(context).dimension;
    Orientation deviceOrientation = MediaQuery.of(context).orientation;
    bool isPortrait = deviceOrientation == Orientation.portrait;
    double screenWidth = isPortrait ? deviceSize.width : deviceSize.peak;
    double screenHeight = isPortrait ? deviceSize.peak : deviceSize.width;
    return MaterialApp(
      residence: SafeArea(
        youngster: Scaffold(
          appBar: AppBar(
            main: IconButton(
              icon: Icon(Icons.arrow_back),
              onPressed: () {
                Navigator.pop(context);
              },
            ),
            title: Textual content(
              "Modify Menu",
              model: TextStyle(
                coloration: widget.darkish ? Colours.black : Colours.white,
              ),
            ),
            actions: [
              IconButton(
                onPressed: () {
                  if (menuformKey.currentState!.validate()) {
                    menuformKey.currentState!.save();
                    Navigator.pop(context);
                  }
                },
                icon: Icon(
                  Icons.done_outline,
                  color: widget.dark ? Colors.black : Colors.white,
                ),
              ),
            ],
            backgroundColor:
                !widget.darkish ? backgroundDarkColor : backgroundLightColor,
          ),
          physique: StreamBuilder(
            initialData: widget.menu,
            stream: onCurrentMenuChanged,
            builder: (context, AsyncSnapshot<Menu> snapshot) {
              late Widget builtWidget;
              if (snapshot.hasData) {
                builtWidget = ListView.builder(
                  itemCount: widget.menu.classes.size,
                  itemBuilder: (context, i) {
                    Class categoryItem = widget.menu.classes[i];
                    return Type(
                      key: menuformKey,
                      youngster: ListView(
                        shrinkWrap: true,
                        kids: [
                          Padding(
                            padding: EdgeInsets.symmetric(
                                horizontal: screenWidth * .1),
                            child: TextFormField(
                              initialValue: categoryItem.title,
                              onSaved: (value) {
                                categoryItem.setTitle = value!;
                              },
                            ),
                          ),
                          Expanded(
                            child: ListView.builder(
                              shrinkWrap: true,
                              itemCount: categoryItem.items.length,
                              itemBuilder: (context, j) {
                                Meal mealItem = categoryItem.items[j];
                                return Container(
                                  width: double.infinity,
                                  peak: screenHeight * .1,
                                  coloration: widget.darkish
                                      ? primaryDarkColor
                                      : primaryLightColor,
                                  youngster: ListTile(
                                    main: Stack(
                                      alignment: Alignment.topLeft,
                                      kids: [
                                        Container(
                                          width: screenWidth * .1,
                                          height: screenWidth * .2,
                                          decoration: BoxDecoration(
                                            image: DecorationImage(
                                                image: AssetImage(
                                                    mealItem.imgPath),
                                                fit: BoxFit.fill),
                                          ),
                                        ),
                                        IconButton(
                                          onPressed: () {
                                            /*Change Image Function*/
                                          },
                                          icon: Icon(
                                            Icons.edit,
                                            color: Colors.white,
                                          ),
                                        ),
                                      ],
                                    ),
                                    title: TextFormField(
                                      initialValue: mealItem.title,
                                      onSaved: (worth) {
                                        mealItem.setName = worth!;
                                      },
                                    ),
                                    subtitle: TextFormField(
                                      initialValue: "${mealItem.value}",
                                      onSaved: (worth) {
                                        mealItem.setPrice =
                                            double.parse(worth!);
                                      },
                                    ),
                                    trailing: IconButton(
                                      onPressed: () {
                                        categoryItem.objects.take away(mealItem);
                                      },
                                      icon: Icon(
                                        Icons.delete,
                                        coloration: Colours.crimson,
                                      ),
                                    ),
                                  ),
                                );
                              },
                            ),
                          ),
                        ],
                      ),
                    );
                  },
                );
              } else if (snapshot.error != null) {
                builtWidget = Textual content("error : ${snapshot.error}");
              } else if (!snapshot.hasData) {
                builtWidget = Textual content("No knowledge");
              } else if (snapshot.connectionState == ConnectionState.ready) {
                builtWidget = Textual content("Ready for Connection");
              }
              return builtWidget;
            },
          ),
        ),
      ),
    );
  }
}

And that is the total error description :

FlutterError (A number of widgets used the identical GlobalKey. The important thing
[LabeledGlobalKey#f9b7f menu form Key] was utilized by a number of widgets.
The dad and mom of these widgets had been:

  • RepaintBoundary(renderObject: RenderRepaintBoundary#522fa
    relayoutBoundary=up4 NEEDS-LAYOUT NEEDS-PAINT)
  • RepaintBoundary(renderObject: RenderRepaintBoundary#ef78c
    relayoutBoundary=up4) A GlobalKey can solely be specified on one widget
    at a time within the widget tree.)

[ad_2]

Leave a Reply