title: How to get data from a widget to the model in flutter?
body: <p>I am new to flutter. I am working on a simple application where you select a date from the calendar and below you see the information of what happened on that day.</p>
  <p>I only have one screen:</p>
  <ul>
  <li>Above is a widget containing a DateRangePicker (<a href="https://pub.dev/packages/syncfusion_flutter_datepicker" rel="nofollow noreferrer">https://pub.dev/packages/syncfusion_flutter_datepicker</a>).</li>
  <li>Below is another widget called Details, which contains some buttons and a card with the day's information.</li>
  </ul>
  <p>I'm currently using provider, but I'm having trouble getting the widgets to communicate with each other. For example, I would like clicking a button on the details widget to cause the calendar widget to send some information to the model's main class.</p>
  <p>Is there any way that when activating the button the model calls the calendar so that it extracts the necessary information from it?</p>
  <p>As additional information, I have the calendar as a consumer of the main class of the model, because the model modifies the calendar from time to time.</p>
  <p>This is my model class:</p>
  <pre><code>class ShiftSystem extends ChangeNotifier {
    DateTime _currentDay = DateTime(
        DateTime.now().year, DateTime.now().month, DateTime.now().day);
    Map&lt;DateTime, Shift&gt;? shifts;
    bool _copyMode = false;
    List&lt;DateTime&gt; selectedDaysToPaste = [];
  }
  </code></pre>
  <p>This is the calendar:</p>
  <pre><code>class Calendar extends StatefulWidget {
    const Calendar({Key? key}) : super(key: key);
  
    @override
    State&lt;Calendar&gt; createState() =&gt; _CalendarState();
  }
  
  class _CalendarState extends State&lt;Calendar&gt; {
    final DateRangePickerController _controller = DateRangePickerController();
    CalendarFormat format = CalendarFormat.month;
    TimeOfDay enter = const TimeOfDay(hour: 7, minute: 0);
    TimeOfDay exit = const TimeOfDay(hour: 17, minute: 30);
  
    @override
    initState() {
      _controller.selectedDate = DateTime.now();
      _controller.selectedDates = [];
      super.initState();
    }
  
    @override
    Widget build(BuildContext context) {
      ShiftSystem backend = context.watch&lt;ShiftSystem&gt;();
        return SfDateRangePicker(
          onSelectionChanged: (DateRangePickerSelectionChangedArgs args) {
            backend.currentDay = _controller.selectedDate!;
            if (backend.copyMode) {
              backend.selectedDaysToPaste = args.value;
            }
          },
          headerStyle: const DateRangePickerHeaderStyle(
            textAlign: TextAlign.left,
          ),
          showNavigationArrow: true,
          monthViewSettings: const DateRangePickerMonthViewSettings(
            firstDayOfWeek: 1,
          ),
          selectionMode: backend.copyMode
              ? DateRangePickerSelectionMode.multiple
              : DateRangePickerSelectionMode.single,
          initialSelectedDates: const &lt;DateTime&gt;[],
          initialSelectedRange: PickerDateRange(
              DateTime.now().subtract(const Duration(days: 4)),
              DateTime.now().add(const Duration(days: 3))),
          controller: _controller,
      );
    }
  }
  </code></pre>
  <p>Changing the day in the calendar updates the value of currentDay in the model. Something similar happens with the selected range of days.</p>
  <p>I use both single and multiple mode because I have a &quot;copy mode&quot; so that information can be copied from one day to another.</p>
  <p>The widget that contains the provider:</p>
  <pre><code>class StartPage extends StatelessWidget {
    const StartPage({Key? key}) : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      final backend = Provider.of&lt;ShiftSystem&gt;(context, listen: false);
      return Scaffold(
        resizeToAvoidBottomInset: false,
        //backgroundColor: const Color(0xff23242a),
        appBar: AppBar(
          toolbarHeight: 65,
          leadingWidth: 75,
          leading:
              IconButton(onPressed: () =&gt; {}, icon: const Icon(Icons.settings)),
          elevation: 0,
          //backgroundColor: const Color(0x00ffffff),
        ),
        body: const MainView(),
      );
    }
  }
  </code></pre>