Open the stopwatch.dart file and dive right into the ListView code:
- Let's replace ListView with one of its variants, ListView.builder. Replace the existing implementation of _buildLapDisplay with this one:
Widget _buildLapDisplay() {
return ListView.builder(
itemCount: laps.length,
itemBuilder: (context, index) {
final milliseconds = laps[index];
return ListTile(
contentPadding: EdgeInsets.symmetric(horizontal: 50),
title: Text('Lap ${index + 1}'),
trailing: Text(_secondsText(milliseconds)),
);
},
);
}
- ScrollViews can get too big, so it's usually a good idea to show the user their position in the list. Wrap ListView in a Scrollbar widget. There aren't any special properties to enter since this widget is entirely context aware:
return Scrollbar(
child: ListView.builder(
itemCount: laps.length,
- Finally, add a quick new feature for...