I am trying to pass a value from my homepage.dart to one of my other dart files with a class. however it doesn’t seem to be passing updating the value nor does it look like its entering the class – Homepage.dart
I tried thus far removing the underscore _ from one of the classnames but didn’t seem to work. Any help would be really appreciated!
onTap: () {
print('ive been clicked');
ListBuilder(
refreshCallback: refreshList,
collectiontype: 'Today',
);
},
— When homepage.dart is starting this automatically starts –
ListBuilder(
refreshCallback: refreshList,
collectiontype: 'All',
),
),
list_builder.dart file
class ListBuilder extends StatefulWidget {
final VoidCallback refreshCallback;
String collectiontype;
ListBuilder({required this.refreshCallback, required this.collectiontype});
@override
_ListBuilderState createState() => _ListBuilderState();
}
class _ListBuilderState extends State<ListBuilder> {
List<Map<String, dynamic>> tasks = [];
@override
void initState() {
super.initState();
_fetchTasks();
}
Future<void> _fetchTasks() async {
print('fetching tasks');
print(widget.collectiontype);
final database = await openMyDatabase();
if (widget.collectiontype == 'All') {
final List<Map<String, dynamic>> fetchedTasks =
await database.query('tasks');
print('detected all tasks');
print(tasks);
setState(() {
tasks = fetchedTasks;
});
} else if (widget.collectiontype == 'Today') {
print('detected today tasks');
await gettasksfortoday();
}
}
Debug Console –
Restarted application in 839ms.
I/flutter ( 5733): fetching tasks
I/flutter ( 5733): All
Debug Console when button is clicked –
D/EGL_emulation( 5733): app_time_stats: avg=69.84ms min=10.57ms max=2098.35ms count=39
I/flutter ( 5733): ive been clicked