I have a horizontal listviewbuilder as shown in the picture on the top:
Is there a way to autocorrect the current position so that the widget on the right corner fits perfectly to his full width? (here number 27)Because if you stop scrolling, it doesn't look nice if it is cut out like the number 27 in the picture. So is it possible to stop only on the fullest itemwidget so that the current position will not be like in the picture?
Here is my code for the listview builder:
import './date_widget.dart';
import 'package:date_picker_timeline/gestures/tap.dart';
import 'package:flutter/material.dart';
import 'package:intl/date_symbol_data_local.dart';
class MyDatePickerTimeline extends StatefulWidget {
DateTime currentDate;
DateChangeListener onDateChange;
String locale;
// Creates the DatePickerTimeline Widget
MyDatePickerTimeline(
this.currentDate, {
Key key,
this.onDateChange,
this.locale = "de",
}) : super(key: key);
@override
State<StatefulWidget> createState() => new _MyDatePickerTimelineState();
}
class _MyDatePickerTimelineState extends State<MyDatePickerTimeline> {
@override void initState() {
super.initState();
initializeDateFormatting(widget.locale, null);
}
@override
Widget build(BuildContext context) {
return Container(
// padding: EdgeInsets.only(bottom: 600),
width: MediaQuery.of(context).size.width ,
height: 200,
child: ListView.builder(
reverse: true,
itemCount: 5000,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
// Return the Date Widget
DateTime _date = DateTime.now().subtract(Duration(days: index));
DateTime date = new DateTime(_date.year, _date.month, _date.day);
bool isSelected = compareDate(date, widget.currentDate);
return MyDateWidget(
date: date,
locale: widget.locale,
selectionColor:
isSelected ? Colors.black12 : Colors.transparent,
onDateSelected: (selectedDate) {
// A date is selected
if (widget.onDateChange != null) {
widget.onDateChange(selectedDate);
}
setState(() {
widget.currentDate = selectedDate;
});
},
);
},
),
);
}
bool compareDate(DateTime date1, DateTime date2) {
return date1.day == date2.day &&
date1.month == date2.month &&
date1.year == date2.year;
}
}
Or is it possible to set a fixed width that you can scroll?