build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Describes the part of the user interface represented by this widget.

The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.

The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.

Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor and from the given BuildContext.

The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.

The implementation of this method must only depend on:

If a widget's build method is to depend on anything else, use a StatefulWidget instead.

See also:

  • StatelessWidget, which contains the discussion on performance considerations.

Implementation

@override
Widget build(BuildContext context) {
  var _deviceSize = MediaQuery.of(context).size;

  return _intGridSchedulePackage(
      title: title,
      schedule: schedule,
      gridDetail: gridDetail,
      widget: Scaffold(
        body: Align(
          alignment: Alignment.topCenter,
          child: SingleChildScrollView(
            scrollDirection: Axis.vertical,
            child: BlocBuilder<GridBloc, GridState>(
              builder: (context, state) {
                if (state is GridStateCreateSchedule) {
                  return Column(
                    children: <Widget>[
                      Container(
                        height: _deviceSize.height * 0.08,
                        child: Container(
                          margin:
                          EdgeInsets.only(left: _deviceSize.width * 0.05),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Align(
                                alignment: Alignment.centerLeft,
                                child: state.gridRepository.isToday
                                    ? IconButton(
                                    onPressed: null,
                                    icon: Icon(Icons.arrow_left))
                                    : Container(
                                  decoration: BoxDecoration(
                                    boxShadow: [
                                      BoxShadow(
                                        color: state.gridRepository
                                            .getGridDetails()
                                            .arrowButtonColor,
                                        spreadRadius: 2,
                                        blurRadius: 5,
                                        offset: const Offset(0, 3),
                                        // changes position of shadow
                                      ),
                                    ],
                                  ),
                                  child: IconButton(
                                    onPressed: () => context
                                        .read<GridBloc>()
                                        .add(GridEventClickBack(
                                        title: "",
                                        day: state.gridRepository
                                            .currentDay,
                                        schedule: schedule,
                                        gridDetail: gridDetail)),
                                    icon: const Icon(Icons.arrow_back),
                                  ),
                                ),
                              ),
                              SizedBox(
                                width: _deviceSize.width / 6,
                              ),
                              Column(
                                children: [
                                  Column(
                                    children: [
                                      Text(
                                        "${state.gridRepository.currentMonth}",
                                        style: TextStyle(
                                          fontSize: 12,
                                        ),
                                      ),
                                      Text(
                                        "${state.gridRepository.currentDay}",
                                        style: TextStyle(
                                          fontSize: 18,
                                          fontWeight: FontWeight.bold,
                                        ),
                                      ),
                                    ],
                                  ),
                                ],
                              ),
                              SizedBox(
                                width: _deviceSize.width / 6,
                              ),
                              Align(
                                alignment: Alignment.centerRight,
                                child: Container(
                                  decoration: BoxDecoration(
                                    boxShadow: [
                                      BoxShadow(
                                        color: state.gridRepository
                                            .getGridDetails()
                                            .arrowButtonColor,
                                        spreadRadius: 2,
                                        blurRadius: 5,
                                        offset: Offset(0, 3),
                                        // changes position of shadow
                                      ),
                                    ],
                                  ),
                                  child: IconButton(
                                    onPressed: () => context
                                        .read<GridBloc>()
                                        .add(GridEventClickNext(
                                        title: "",
                                        day: state
                                            .gridRepository.currentDay,
                                        schedule: schedule,
                                        gridDetail: gridDetail)),
                                    icon: const Icon(Icons.arrow_right),
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                      SizedBox(
                        height: _deviceSize.height * 0.01,
                      ),
                      FutureBuilder(
                        future: state.gridRepository.getSchedules(),
                        builder: (context, snapshot) {
                          if (snapshot.hasData) {
                            return SizedBox(
                              height: _deviceSize.height,
                              width: _deviceSize.width,
                              child: GridView.builder(
                                shrinkWrap: true,
                                itemCount: snapshot.data!.length,
                                gridDelegate:
                                SliverGridDelegateWithFixedCrossAxisCount(
                                  crossAxisCount: state.gridRepository
                                      .getGridDetails()
                                      .gridCount,
                                  crossAxisSpacing: 4.0,
                                  mainAxisSpacing: 4.0,
                                ),
                                itemBuilder:
                                    (BuildContext context, int index) {
                                  return Column(
                                    children: [
                                      GestureDetector(
                                        onTap: () {
                                          if (snapshot.data![index]
                                              .availability ==
                                              1) {
                                            snapshot.data![index]
                                                .onTapTimeAvailable(
                                                snapshot.data![index]);
                                            ;
                                          } else {
                                            snapshot.data![index]
                                                .onTapTimeUnavailable(
                                                snapshot.data![index]);
                                            ;
                                          }
                                        },
                                        child: Padding(
                                          padding: const EdgeInsets.all(8.0),
                                          child: Container(
                                            height: 100,
                                            decoration: BoxDecoration(
                                              border: Border.all(
                                                color: Color.fromARGB(
                                                    255, 199, 199, 199),
                                              ),
                                              borderRadius: BorderRadius.all(
                                                  Radius.circular(5)),
                                              color: snapshot.data![index]
                                                  .availability ==
                                                  1
                                                  ? state.gridRepository
                                                  .selectedIdx ==
                                                  index
                                                  ? snapshot.data![index]
                                                  .timeAvailableColor
                                                  : snapshot.data![index]
                                                  .timeUnavailableColor
                                                  : Color.fromARGB(
                                                  255, 236, 235, 235),
                                            ),
                                            child: Padding(
                                              padding:
                                              const EdgeInsets.all(8.0),
                                              child: Center(
                                                child: state.gridRepository
                                                    .selectedIdx ==
                                                    index &&
                                                    snapshot.data![index]
                                                        .availability ==
                                                        1
                                                    ? Text(
                                                  "${snapshot.data![index].time}",
                                                  style: TextStyle(
                                                    color: snapshot
                                                        .data![index]
                                                        .timeUnavailableTextColor,
                                                    fontSize:snapshot.data![index].timeAvailableTextSize
                                                  ),
                                                )
                                                    : Text(
                                                  "${snapshot.data![index].time}",
                                                  style: TextStyle(
                                                      color: snapshot
                                                          .data![index]
                                                          .timeUnavailableTextColor, fontSize:snapshot.data![index].timeUnavailableTextSize),
                                                ),
                                              ),
                                            ),
                                          ),
                                        ),
                                      ),
                                    ],
                                  );
                                },
                              ),
                            );
                          } else {
                            return Column(
                              mainAxisAlignment:
                              MainAxisAlignment.spaceBetween,
                              mainAxisSize: MainAxisSize.max,
                              children: [
                                CircularProgressIndicator(),
                              ],
                            );
                          }
                        },
                      ),
                    ],
                  );
                } else if (state is GridStateNextDay) {
                  return Column(
                    children: <Widget>[
                      Container(
                        height: _deviceSize.height * 0.08,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Align(
                              alignment: Alignment.centerLeft,
                              child: state.gridRepository.isToday
                                  ? IconButton(
                                  onPressed: null,
                                  icon: Icon(Icons.arrow_left))
                                  : Container(
                                decoration: BoxDecoration(
                                  boxShadow: [
                                    BoxShadow(
                                      color: state.gridRepository
                                          .getGridDetails()
                                          .arrowButtonColor,
                                      spreadRadius: 2,
                                      blurRadius: 5,
                                      offset: Offset(0, 3),
                                      // changes position of shadow
                                    ),
                                  ],
                                ),
                                child: IconButton(
                                  onPressed: () => context
                                      .read<GridBloc>()
                                      .add(GridEventClickBack(
                                      title: "",
                                      day: state.gridRepository
                                          .currentDay,
                                      schedule: schedule,
                                      gridDetail: gridDetail)),
                                  icon: const Icon(Icons.arrow_left),
                                ),
                              ),
                            ),
                            SizedBox(
                              width: _deviceSize.width / 6,
                            ),
                            Column(
                              children: [
                                Column(
                                  children: [
                                    Text(
                                      "${state.gridRepository.currentMonth}",
                                      style: TextStyle(
                                        fontSize: 12,
                                      ),
                                    ),
                                    Text(
                                      "${state.gridRepository.currentDay}",
                                      style: TextStyle(
                                        fontSize: 18,
                                        fontWeight: FontWeight.bold,
                                      ),
                                    ),
                                  ],
                                ),
                              ],
                            ),
                            SizedBox(
                              width: _deviceSize.width / 6,
                            ),
                            Align(
                              alignment: Alignment.centerRight,
                              child: Container(
                                decoration: BoxDecoration(
                                  boxShadow: [
                                    BoxShadow(
                                      color: state.gridRepository
                                          .getGridDetails()
                                          .arrowButtonColor,
                                      spreadRadius: 2,
                                      blurRadius: 5,
                                      offset: Offset(0, 3),
                                      // changes position of shadow
                                    ),
                                  ],
                                ),
                                child: IconButton(
                                  onPressed: () => {
                                    context.read<GridBloc>().add(
                                        GridEventClickNext(
                                            title: "",
                                            day: state
                                                .gridRepository.currentDay,
                                            schedule: schedule,
                                            gridDetail: gridDetail))
                                  },
                                  icon: Icon(Icons.arrow_right),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                      SizedBox(
                        height: _deviceSize.height * 0.01,
                      ),
                      FutureBuilder(
                        future: state.gridRepository.getSchedules(),
                        builder: (context, snapshot) {
                          if (snapshot.hasData) {
                            return SizedBox(
                              height: _deviceSize.height,
                              child: GridView.builder(
                                itemCount: snapshot.data!.length,
                                gridDelegate:
                                SliverGridDelegateWithFixedCrossAxisCount(
                                  crossAxisCount: state.gridRepository
                                      .getGridDetails()
                                      .gridCount,
                                  crossAxisSpacing: 4.0,
                                  mainAxisSpacing: 4.0,
                                ),
                                itemBuilder:
                                    (BuildContext context, int index) {
                                  return Column(
                                    children: [
                                      GestureDetector(
                                        onTap: () {
                                          if (snapshot.data![index]
                                              .availability ==
                                              1) {
                                            snapshot.data![index]
                                                .onTapTimeAvailable(
                                                snapshot.data![index]);
                                          } else {
                                            snapshot.data![index]
                                                .onTapTimeUnavailable(
                                                snapshot.data![index]);
                                          }
                                        },
                                        child: Container(
                                          width: _deviceSize.width,
                                          height: 100,
                                          decoration: BoxDecoration(
                                            border: Border.all(
                                              color: Color.fromARGB(
                                                  255, 199, 199, 199),
                                            ),
                                            borderRadius: BorderRadius.all(
                                                Radius.circular(5)),
                                            color: snapshot.data![index]
                                                .availability ==
                                                1
                                                ? state.gridRepository
                                                .selectedIdx ==
                                                index
                                                ? snapshot.data![index]
                                                .timeAvailableColor
                                                : snapshot.data![index]
                                                .timeUnavailableColor
                                                : Color.fromARGB(
                                                255, 236, 235, 235),
                                          ),
                                          child: Padding(
                                            padding:
                                            const EdgeInsets.all(8.0),
                                            child: Center(
                                              child: state.gridRepository
                                                  .selectedIdx ==
                                                  index &&
                                                  snapshot.data![index]
                                                      .availability ==
                                                      1
                                                  ? Text(
                                                "${snapshot.data![index].time}",
                                                style: TextStyle(
                                                  color: snapshot
                                                      .data![index]
                                                      .timeAvailableTextColor,
                                                    fontSize:snapshot.data![index].timeAvailableTextSize
                                                ),
                                              )
                                                  : Text(
                                                "${snapshot.data![index].time}",
                                                style: TextStyle(
                                                    color: snapshot
                                                        .data![index]
                                                        .timeUnavailableTextColor, fontSize:snapshot.data![index].timeUnavailableTextSize),
                                              ),
                                            ),
                                          ),
                                        ),
                                      ),
                                    ],
                                  );
                                },
                              ),
                            );
                          } else {
                            return Column(
                              mainAxisAlignment:
                              MainAxisAlignment.spaceBetween,
                              mainAxisSize: MainAxisSize.max,
                              children: [
                                CircularProgressIndicator(),
                              ],
                            );
                          }
                        },
                      ),
                    ],
                  );
                }
                return CircularProgressIndicator();
              },
            ),
          ),
        ),
      ));
}