Skip to content

Commit c1ee517

Browse files
committed
survey widget
1 parent 7eafd41 commit c1ee517

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import 'package:cloud_firestore/cloud_firestore.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter_ui_challenges/core/data/firestore_service.dart';
4+
import 'package:flutter_ui_challenges/core/data/models/survey.dart';
5+
import 'package:flutter_ui_challenges/features/auth/data/model/user_repository.dart';
6+
import 'package:flutter_ui_challenges/features/auth/data/service/firestore_service.dart';
7+
import 'package:provider/provider.dart';
8+
9+
class SurveyWidget extends StatelessWidget {
10+
final SurveyItem survey;
11+
12+
const SurveyWidget({Key key, this.survey}) : super(key: key);
13+
@override
14+
Widget build(BuildContext context) {
15+
return Container(
16+
color: Theme.of(context).primaryColor,
17+
child: Card(
18+
margin: const EdgeInsets.all(8.0),
19+
child: Padding(
20+
padding: const EdgeInsets.all(16.0),
21+
child: Column(
22+
crossAxisAlignment: CrossAxisAlignment.start,
23+
children: <Widget>[
24+
Text(survey.message,style: TextStyle(
25+
fontSize: 20.0,
26+
fontWeight: FontWeight.w500,
27+
),),
28+
...survey.options.map((option) =>RadioListTile(
29+
groupValue: null,
30+
value: survey.optionKeys[survey.options.indexOf(option)],
31+
title: Text(option),
32+
onChanged: (val){
33+
FirestoreService().updateDocument('surveys', survey.id, {
34+
val: FieldValue.increment(1),
35+
});
36+
AuthFirestoreService().updateUserData(Provider.of<UserRepository>(context).user.uid, {"surveys": FieldValue.arrayUnion([survey.id])});
37+
Scaffold.of(context).showSnackBar(SnackBar(
38+
content: Text("Thank you for providing us feedback")
39+
));
40+
},
41+
))
42+
],
43+
),
44+
)
45+
),
46+
);
47+
}
48+
}

0 commit comments

Comments
 (0)