Reputation: 3
I have this polls code using the flutter_polls.dart dependency but when I compile the code I don't get the icon button and the text on the bottom and this happened only on the last poll! I don't know why I got Incorrect use of ParentDataWidget error
[
]1 here is an image
` @override Widget build(BuildContext context) { return Stack(children: [ SingleChildScrollView( child: Provider.of(context).isLoading ? Center(child: CircularProgressIndicator()) : Column( children: [ Container( height: MediaQuery.of(context).size.height, padding: const EdgeInsets.all(20), child: Expanded( child: ListView.builder( itemCount: pollsList.length, itemBuilder: (BuildContext context, int index) { //final Map<String, dynamic> poll = pollsList[index]; var polaI = pollsList[index];
bool voted = hasVotedFunc(polaI);
votedTo = getHasVotedTo(polaI);
/* final int days = DateTime(
)
.difference(DateTime(
DateTime.now().year,
DateTime.now().month,
DateTime.now().day,
))
.inDays;
*/
return Provider.of<PollsProvider>(context).isLoading
? Center(child: CircularProgressIndicator())
: Container(
margin: const EdgeInsets.only(bottom: 20),
child: Stack(
children: [
FlutterPolls(
// loadingWidget : ,
pollId: polaI.id.toString(),
hasVoted: voted,
userVotedOptionId:
votedTo, //userVotedOptionId.value,
onVoted: (PollOption pollOption,
int newTotalVotes) async {
polaI.options[pollOption.id].votes =
polaI.options[pollOption.id]
.votes +
1;
// await Future.delayed(const Duration(seconds: 1));
polaI.options[pollOption.id].voters
.add(Provider.of<AuthService>(
context,
listen: false)
.currentUser
?.email);
await Provider.of<PollsProvider>(
context,
listen: false)
.updatePoll(polaI);
return true;
},
// pollEnded: days < 0,
pollTitle: Align(
alignment: Alignment.centerLeft,
child: Text(
polaI.question,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
),
pollOptions: List<PollOption>.from(
polaI.options.map((option) {
var a = PollOption(
id: option.id,
title: Text(
option.title,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
votes: option.votes,
);
return a;
})),
votedPercentageTextStyle:
const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
),
metaWidget: Row(
children: [
const SizedBox(width: 6),
const Text('•'),
const SizedBox(
width: 6,
),
IconButton(
icon: Icon(Icons.replay_outlined),
onPressed: () {
DeleteVote(polaI);
},
),
const SizedBox(
width: 6,
),
],
),
),
Align(
alignment: Alignment.topRight,
child: PopupMenuButton(
itemBuilder: (context) {
return [
PopupMenuItem(
value: 'Update',
child: Text('Update'),
),
PopupMenuItem(
value: 'Delete',
child: Text('Delete'),
)
];
},
onSelected: (String value) {
actionPopUpItemSelected(
value, polaI);
},
child: Icon(Icons.more_vert),
),
),
],
),
);
},
),
),
),
],
),
),
Positioned(
bottom: 20,
right: 20,
child: FloatingActionButton(
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (_) => AddPollPage()));
},
child: Icon(Icons.add),
),
),
]);
} } `
Upvotes: 0
Views: 140
Reputation: 78
I believe the error is coming from the Expanded
widget being wrapped around a ListView
. Try that and see if it works
Upvotes: 0