Recommand · May 14, 2022 0

Method has automatic access to build context

Here is a method that is called within my application when a ‘save’ button is pressed. The method accesses a ChangeNotifier instance using the Provider object and updates the underlying model.

  /// Handle the user pressing the Submit button within the dialog.
  void _saveChanges() {

    // degree title
    Provider.of<AcademicController>(context, listen: false)

    // degree award
    Provider.of<AcademicController>(context, listen: false)


    // removing academic years to be removed
    Provider.of<AcademicController>(context, listen: false)

    // saving the changes made within to the academic year form rows
    for (AcademicYearFormRow academicYearFormRow in academicYearFormRows) {

I am confused because, in this method, I reference context, but I do not pass in a BuildContext as an argument to the function.

The method is not nested and occurs at the same level as the widget’s build method.

How does this method have access to a BuildContext without getting one as an argument?

You may also like…

amazon-web-services android angular api arrays c# css dart dataframe django docker excel express firebase flutter html ios java javascript jquery json kotlin laravel linux list mongodb mysql node.js pandas php postgresql python python-3.x r react-native reactjs regex spring spring-boot sql sql-server string swift typescript vue.js