NoSuchMethodError was thrown while handling a gesture

  android, dart, flutter, frontend

I am pretty new to the dart language and flutter framework. Thank you and any help will be highly appreciated

Basically when I click the remove buttton in the image attached below it gives me this exception. ════════ Exception caught by gesture ═══════════════════════════════════════════ The following NoSuchMethodError was thrown while handling a gesture: The method ‘call’ was called on null. Receiver: null Tried calling: call()

this where the modal is being created.

class ExtraItem extends StatefulWidget {
  bool isLast = false;
  final VoidCallback onExtraAdded;
  final Function onExtraRemoved;
  final VoidCallback onNameChanged;
  final VoidCallback onPriceChanged;
  String name;
  int price;
  int index;
  ExtraItem(
      {this.isLast,
      this.onExtraAdded,
      this.onExtraRemoved,
      this.index,
      this.onNameChanged,
      this.onPriceChanged});
  @override
  _ExtraItemState createState() => _ExtraItemState();
}
class _ExtraItemState extends State<ExtraItem> {
  String type;
  TextEditingController nameController = TextEditingController();
  TextEditingController priceController = TextEditingController();
  @override
  void dispose() {
    nameController.dispose();
    priceController.dispose();
    super.dispose();
  }
  _showExtrasDialog() async {
    await showDialog<String>(
      context: this.context,
      child: new _SystemPadding(
        child: new AlertDialog(
          title: Text(
            'Modify Extras ',
            style: TextStyle(fontFamily: "Montserrat Medium", fontSize: 15),
          ),
          contentPadding: const EdgeInsets.all(16.0),
          content: new Row(
            children: <Widget>[],
          ),
          actions: <Widget>[
            new FlatButton(
                child: const Text('CANCEL'),
                onPressed: () {
                  Navigator.pop(this.context);
                }),
            new FlatButton(
                child: const Text('ADD EXTRA'),
                onPressed: () {
                  setState(() {
                    widget.onExtraAdded();
                  });
                  Navigator.pop(this.context);
                }),
            new FlatButton(
                child: const Text('REMOVE'),
                onPressed: () {
                  setState(() {
                    print(widget.index);
                    // print()
                    widget.onExtraRemoved();
                  });
                  Navigator.pop(this.context);
                })
          ],
        ),
      ),
    );
  }

this is the class that does the manipulation for the deliting.

class ThirdPage extends StatefulWidget {
  Function(List<ExtraItem>) onExtrasChanged;
  Function(List<ExtraItem>) onDrinksChanged;
  Function(List<ExtraItem>) onSidesChanged;
  Function(int) onExtrasRemoved;
  ThirdPage(
      {this.onExtrasChanged,
      this.onDrinksChanged,
      this.onSidesChanged,
      this.onExtrasRemoved});
  @override
  _ThirdPageState createState() => _ThirdPageState();
}
class _ThirdPageState extends State<ThirdPage> {
  List<ExtraItem> extras = [];
  List<ExtraItem> drinks = [];
  List<ExtraItem> sides = [];
  int index;
  void removeExtraItem() {
    print("This is my current index");
    setState(() {
      extras.remove(ExtraItem(
        onExtraRemoved: (int i) {
          this.index = i;
          extras.removeAt(this.index);
          removeExtraItem();
        },
        onNameChanged: () {
          widget.onExtrasRemoved(this.index);
        },
        onPriceChanged: () {
          widget.onExtrasRemoved(this.index);
        },
        // isLast: true,
        // index: extras.length - 1,
      ));
    });
  }

void addExtraItem() {
    setState(() {
      extras.add(ExtraItem(
        onExtraAdded: () {
          addExtraItem();
        },
        onNameChanged: () {
          widget.onExtrasChanged(extras);
        },
        onPriceChanged: () {
          widget.onExtrasChanged(extras);
          printExtraValues();
        },
        isLast: true,
        index: extras.length,
      ));
    });
  }



ThirdPage(onExtrasChanged: (list) {
                          this.extras = list;
                        }, onSidesChanged: (sides) {
                          this.sides = sides;
                        }, onDrinksChanged: (drinks) {
                          this.drinks = drinks;
                        }, onExtrasRemoved: (int value) {
                          extrasIndex = value;
                          this.extras.removeAt(extrasIndex);
                        }),

Image link

modal

UI

Source: Android Questions

LEAVE A COMMENT