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) {
  int itemCount = starerChild?.length ?? starerDates?.length ?? events.length;

  // if (starerChild?.length != events.length || starerChild?.length != events.length) {
  //   // Dates and events should be equal
  //   throw Exception("Dates and Events length must be the same");
  // }

  return ListView.builder(
    physics: NeverScrollableScrollPhysics(),
    shrinkWrap: true,
    itemCount: itemCount,
    itemBuilder: (context, index) {
      // defining date, day and month
      String? date;
      String day = '';
      String month = '';

      // making a condition where if the starer dates is not null the make a split of date given by user

      if (starerDates != null && starerDates!.isNotEmpty) {
        date = starerDates![index];
        List<String> parts = date.split(' ');

        // spliting a dates into two parts

        if (parts.length >= 2) {
          // declaring dates first part as a day

          day = parts[0];

          // declaring dates second / last part as a month

          month = parts[1];
        }
      }

      Widget? childWidget;

      // building a starer child if the starer child list is not empty

      if (starerChild != null && starerChild!.isNotEmpty) {
        // if not so then terminate the process and show dates... checing either it is null or not

        childWidget = starerChild![index];
      }

      return IntrinsicHeight(
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          // mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            // checking whether the childWidget (starerChild) is null [Empty] or not

            if (childWidget != null)
              Column(
                crossAxisAlignment: CrossAxisAlignment.end,
                mainAxisAlignment: MainAxisAlignment.start,
                children: [childWidget],
              )

            // if [starerChild] is null then show the date

            else if (breakDate == true)

              // breakDate help breaking the dates by spliting them into two parts and make it looks more professional

              Padding(
                padding: EdgeInsets.only(
                  bottom: mainSpacing ?? 20,
                ),
                child: Column(
                  // crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    // first part of dates goes here

                    //
                    //
                    // Checking whether the day contain two letters or not --> if not then check the length and make the day of two integer

                    Text(
                      (day.length == 1) ? "0$day" : day,

                      // if day contain only one int then lets put 0 just front of it

                      style: dateStyle ??
                          TextStyle(
                            height: 0,
                            fontSize: 30,
                            letterSpacing: -2,
                            color: Colors.black,
                            fontWeight: FontWeight.w500,
                          ),
                    ),
                    Text(
                      month,
                      style: TextStyle(
                        height: 0,
                        fontSize: 16,
                        color: Colors.black,
                        fontWeight: FontWeight.w500,
                      ),
                    )
                  ],
                ),
              )
            else

              // else if the date is not breaked then show the date serially

              Text(
                // date ?? '', // if date is null then show the ui as empty

                // (date!.length == 1) ? '0$date' : date,

                // here i have made a condition that if the complete date that user insert in starerDate is like 2 Jan then 0 will be added in front of it and make the single integer into double otherwise it will be same if it contains two int

                (day.length == 1) ? '0$day $month' : '$day $month',

                style: dateStyle ??

                    // displaying a default textstyle if user TextStyle is null

                    TextStyle(
                      height: 0,
                      fontSize: 30,
                      letterSpacing: -2,
                      color: Colors.black,
                      fontWeight: FontWeight.w500,
                    ),
              ),
            SizedBox(
              width: crossSpacing ?? 16,
            ),
            Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                SizedBox(
                  height: 8,
                ),
                CircleAvatar(
                  backgroundColor: indicatorColor ?? colorConfig.defaultIndicatorColor,
                  radius: indicatorRadius ?? 6,
                ),
                Expanded(
                  child: Container(
                    width: indicatorWidth ?? 2,
                    color: indicatorColor ?? colorConfig.defaultIndicatorColor,
                  ),
                ),
              ],
            ),
            SizedBox(
              width: crossSpacing ?? 16,
            ),
            Expanded(
              child: Column(
                children: [
                  SizedBox(
                    height: mainSpacing ?? 16,
                  ),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [events[index]],
                  )
                ],
              ),
            ),
          ],
        ),
      );
    },
  );
}