busList method

  1. @override
dynamic busList (
  1. int idx,
  2. Function _containsFilter,
  3. Function _jumpMap
)

Builds the buslist widget which contains all the stops and useful user information like the next arrival.

Implementation

@override
Widget busList(int idx, Function _containsFilter, Function _jumpMap) {
  /// Returns the scrollable list for our bus stops to be contained in.
  return ScrollablePositionedList.builder(
    itemCount: busStopLists[idx].length,
    itemBuilder: (context, index) {
      /// Contains the current stops for the busses.
      var curStopList = busStopLists[idx];

      /// Contains our Expansion Tile to control how the user views each bus stop.
      return CustomExpansionTile(
        title: Text(curStopList[index % curStopList.length][0]),
        subtitle: Text('Next Arrival: ' +
            busTimeLists[idx][_getTimeIndex(busTimeLists[idx])]),
        tilePadding: EdgeInsets.symmetric(vertical: 11.0, horizontal: 16.0),

        /// Controls the leading circle icon in front of each bus stop.
        leading: CustomPaint(
            painter: FillPainter(
                circleColor: Theme.of(context).buttonColor,
                lineColor: Theme.of(context).primaryColorLight,
                first: index == 0,
                last: index == curStopList.length - 1),
            child: Container(
              height: 50,
              width: 45,
            )),
        trailing: isExpandedList[index % curStopList.length]
            ? Text('Hide Arrivals -')
            : Text('Show Arrivals +'),
        onExpansionChanged: (value) {
          setState(() {
            isExpandedList[index % curStopList.length] = value;
          });
        },

        /// Contains everything below the ExpansionTile when it is expanded.
        children: [
          CustomPaint(
            painter: StrokePainter(
              circleColor: Theme.of(context).buttonColor,
              lineColor: Theme.of(context).primaryColorLight,
              last: index == curStopList.length - 1,
            ),

            /// A list item for every arrival time for the selected bus stop.
            child: ListTile(
                contentPadding: EdgeInsets.zero,
                leading: Container(
                  margin: const EdgeInsets.only(left: 34.5),
                  constraints: BoxConstraints.expand(width: 8),
                ),
                title: Container(
                  child: RefreshIndicator(
                    onRefresh: () =>
                        Future.delayed(const Duration(seconds: 1), () => "1"),
                    displacement: 1,

                    /// A list of the upcoming bus stop arrivals.
                    child: ListView.builder(
                      shrinkWrap: true,
                      itemCount: 5,
                      itemExtent: 50,
                      itemBuilder: (BuildContext context, int timeIndex) {
                        /// The container in which the bus stop arrival times are displayed.
                        return ListTile(
                          dense: true,
                          leading: Icon(Icons.access_time, size: 20),
                          title: Text(
                            '${busTimeLists[idx][timeIndex]}',
                            style: TextStyle(fontSize: 15),
                          ),
                          subtitle: Text('In 11 minutes'),
                          trailing: PopupMenuButton<String>(
                              onSelected: null,
                              itemBuilder: (BuildContext context) => choices
                                  .map((choice) => PopupMenuItem<String>(
                                      value: choice, child: Text(choice)))
                                  .toList()),
                        );
                      },
                    ),
                  ),
                )),
          ),
        ],
      );
    },
  );
}