Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Made By Samir
- import 'package:flutter/material.dart';
- import 'package:firebase_core/firebase_core.dart';
- import 'package:cloud_firestore/cloud_firestore.dart';
- import 'package:google_fonts/google_fonts.dart';
- import 'package:responsive_x/responsive_x.dart';
- // ignore: must_be_immutable
- class SondageFireStore extends StatefulWidget {
- SondageFireStore({Key key}) : super(key: key);
- @override
- _SondageFireStoreState createState() => _SondageFireStoreState();
- }
- class _SondageFireStoreState extends State<SondageFireStore> {
- int selectedRadioTile;
- int selectedRadio;
- @override
- void initState() {
- selectedRadio = 0;
- selectedRadioTile = 0;
- super.initState();
- Firebase.initializeApp().whenComplete(() {
- print("completed");
- setState(() {});
- });
- }
- void setState(fn) {
- FirebaseFirestore.instance;
- super.setState(fn);
- }
- setSelectedRadio(int val) {
- selectedRadio = val;
- }
- setSelectedRadioTile(int val) {
- setState(() {
- selectedRadioTile = val;
- });
- }
- @override
- Widget build(BuildContext context) {
- bool isChecked = false;
- return StreamBuilder(
- stream: FirebaseFirestore.instance.collection('Questions').snapshots(),
- builder: (context, snapshot) {
- if (!snapshot.hasData) {
- return Text('Loading');
- }
- return ListView.builder(
- itemCount: snapshot.data.docs.length,
- itemBuilder: (BuildContext context, int index) {
- final String itemTitle = snapshot.data.docs[index]['title'];
- return Padding(
- padding: const EdgeInsets.all(10.0),
- child: Container(
- padding: EdgeInsets.only(top: 10),
- decoration: BoxDecoration(
- color: Colors.green,
- borderRadius: BorderRadius.all(
- Radius.circular(20),
- ),
- ),
- child: Column(
- children: [
- Text(
- itemTitle,
- textAlign: TextAlign.center,
- style: GoogleFonts.bebasNeue(
- fontSize: 25.fontSize,
- color: Colors.white,
- ),
- ),
- RadioListTile(
- value: 1,
- groupValue: selectedRadioTile,
- title: Text(
- "Oui",
- style: GoogleFonts.bebasNeue(
- fontSize: 25.fontSize, color: Colors.white),
- ),
- // subtitle: Text("Radio 1 Subtitle"),
- onChanged: (val) {
- print("Radio Tile pressed $val");
- setSelectedRadioTile(val);
- },
- activeColor: Colors.blue,
- //selected: true,
- ),
- RadioListTile(
- value: 2,
- groupValue: selectedRadioTile,
- title: Text(
- "Non",
- style: GoogleFonts.bebasNeue(
- fontSize: 25.fontSize, color: Colors.white),
- ),
- //subtitle: Text("Radio 2 Subtitle"),
- onChanged: (val) {
- print("Radio Tile pressed $val");
- setSelectedRadioTile(val);
- },
- //selected: false,
- activeColor: Colors.blue,
- ),
- ],
- ),
- ),
- );
- },
- );
- },
- );
- }
- }
- class TestOnPressed extends StatefulWidget {
- TestOnPressed({Key key}) : super(key: key);
- @override
- _TestOnPressedState createState() => _TestOnPressedState();
- }
- class _TestOnPressedState extends State<TestOnPressed> {
- @override
- void initState() {
- super.initState();
- Firebase.initializeApp().whenComplete(() {
- print("completed");
- setState(() {});
- });
- }
- void setState(fn) {
- FirebaseFirestore.instance;
- super.setState(fn);
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text(
- 'Sondage',
- style: TextStyle(fontSize: 30.fontSize),
- ),
- centerTitle: true,
- ),
- body: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Column(
- children: [
- Text(
- 'Partager votre Avis ',
- style: GoogleFonts.bebasNeue(fontSize: 35.fontSize),
- ),
- Expanded(
- child: Padding(
- padding: const EdgeInsets.only(top: 5),
- child: SondageFireStore(),
- ),
- ),
- RaisedButton(
- padding: EdgeInsets.symmetric(vertical: 8, horizontal: 30),
- color: Colors.white,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.all(
- Radius.circular(30),
- ),
- ),
- child: Text(
- 'Valider',
- style: GoogleFonts.bebasNeue(fontSize: 30.fontSize),
- ),
- onPressed: () {},
- )
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement