class _AppointmentListViewState extends State<AppointmentListView> {
int numOfInitialAppointmentsLoaded = 2;
int numOfAppointmentsToFetch = 2;
@override
Widget build(BuildContext context) {
List appointmentData = [
...widget.appointmentList.map(
(appointmentData) => AppointmentModal(appointment: appointmentData))
];
int totalNumberOfAppointments = appointmentData.length;
void loadMoreAppointments() {
if (numOfInitialAppointmentsLoaded >= totalNumberOfAppointments) {
// may need to add a msg to the user
} else {
setState(() {
if (totalNumberOfAppointments - numOfInitialAppointmentsLoaded <
numOfAppointmentsToFetch) {
numOfInitialAppointmentsLoaded +=
totalNumberOfAppointments - numOfInitialAppointmentsLoaded;
} else {
numOfInitialAppointmentsLoaded += numOfAppointmentsToFetch;
}
});
}
}
return Column(
children: [
SizedBox(
height: MediaQuery.of(context).size.height / 1.5,
child: ListView.builder(
// shrinkWrap: true,
itemCount: numOfInitialAppointmentsLoaded,
itemBuilder: (BuildContext context, int index) {
return appointmentData[index];
}),
),
TextButton(
style: TextButton.styleFrom(
foregroundColor: cocoGypsy,
textStyle:
const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
onPressed: loadMoreAppointments,
child: const Text("See more appointments"))
],
);
}
}
Currently I have a list of appointments and a text button that loads more appointments. The list is generated by the Listview builder and the button is always at the bottom of the screen. How can I make the button move dynamically with the list items so that it gets pushed down as more items are loaded?
I tried removing the sized box and just have my listview and button widgets wrapped in a column, but then my appointments weren’t loading at all.
2
Answers
you can try this
or you can try bottom navigation bar like this
Here you go. You can copy this source code & paste it into the
main.dart
file and run it. Don’t forget to look at the attached output below the source code.Output: