Advertisement
AnoTest

MySql.dart

Feb 28th, 2021
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 5.51 KB | None | 0 0
  1. //Made By Samir
  2.  
  3. import 'package:flutter/material.dart';
  4. import 'package:firebase_core/firebase_core.dart';
  5. import 'package:cloud_firestore/cloud_firestore.dart';
  6. import 'package:google_fonts/google_fonts.dart';
  7. import 'package:responsive_x/responsive_x.dart';
  8.  
  9. // ignore: must_be_immutable
  10. class SondageFireStore extends StatefulWidget {
  11.   SondageFireStore({Key key}) : super(key: key);
  12.  
  13.   @override
  14.   _SondageFireStoreState createState() => _SondageFireStoreState();
  15. }
  16.  
  17. class _SondageFireStoreState extends State<SondageFireStore> {
  18.   int selectedRadioTile;
  19.   int selectedRadio;
  20.  
  21.   @override
  22.   void initState() {
  23.     selectedRadio = 0;
  24.     selectedRadioTile = 0;
  25.     super.initState();
  26.     Firebase.initializeApp().whenComplete(() {
  27.       print("completed");
  28.       setState(() {});
  29.     });
  30.   }
  31.  
  32.   void setState(fn) {
  33.     FirebaseFirestore.instance;
  34.     super.setState(fn);
  35.   }
  36.  
  37.   setSelectedRadio(int val) {
  38.     selectedRadio = val;
  39.   }
  40.  
  41.   setSelectedRadioTile(int val) {
  42.     setState(() {
  43.       selectedRadioTile = val;
  44.     });
  45.   }
  46.  
  47.   @override
  48.   Widget build(BuildContext context) {
  49.     bool isChecked = false;
  50.     return StreamBuilder(
  51.       stream: FirebaseFirestore.instance.collection('Questions').snapshots(),
  52.       builder: (context, snapshot) {
  53.         if (!snapshot.hasData) {
  54.           return Text('Loading');
  55.         }
  56.         return ListView.builder(
  57.           itemCount: snapshot.data.docs.length,
  58.           itemBuilder: (BuildContext context, int index) {
  59.             final String itemTitle = snapshot.data.docs[index]['title'];
  60.             return Padding(
  61.               padding: const EdgeInsets.all(10.0),
  62.               child: Container(
  63.                 padding: EdgeInsets.only(top: 10),
  64.                 decoration: BoxDecoration(
  65.                   color: Colors.green,
  66.                   borderRadius: BorderRadius.all(
  67.                     Radius.circular(20),
  68.                   ),
  69.                 ),
  70.                 child: Column(
  71.                   children: [
  72.                     Text(
  73.                       itemTitle,
  74.                       textAlign: TextAlign.center,
  75.                       style: GoogleFonts.bebasNeue(
  76.                         fontSize: 25.fontSize,
  77.                         color: Colors.white,
  78.                       ),
  79.                     ),
  80.                     RadioListTile(
  81.                       value: 1,
  82.                       groupValue: selectedRadioTile,
  83.                       title: Text(
  84.                         "Oui",
  85.                         style: GoogleFonts.bebasNeue(
  86.                             fontSize: 25.fontSize, color: Colors.white),
  87.                       ),
  88.  
  89.                       // subtitle: Text("Radio 1 Subtitle"),
  90.                       onChanged: (val) {
  91.                         print("Radio Tile pressed $val");
  92.                         setSelectedRadioTile(val);
  93.                       },
  94.                       activeColor: Colors.blue,
  95.  
  96.                       //selected: true,
  97.                     ),
  98.                     RadioListTile(
  99.                       value: 2,
  100.                       groupValue: selectedRadioTile,
  101.                       title: Text(
  102.                         "Non",
  103.                         style: GoogleFonts.bebasNeue(
  104.                             fontSize: 25.fontSize, color: Colors.white),
  105.                       ),
  106.                       //subtitle: Text("Radio 2 Subtitle"),
  107.                       onChanged: (val) {
  108.                         print("Radio Tile pressed $val");
  109.                         setSelectedRadioTile(val);
  110.                       },
  111.                       //selected: false,
  112.                       activeColor: Colors.blue,
  113.                     ),
  114.                   ],
  115.                 ),
  116.               ),
  117.             );
  118.           },
  119.         );
  120.       },
  121.     );
  122.   }
  123. }
  124.  
  125. class TestOnPressed extends StatefulWidget {
  126.   TestOnPressed({Key key}) : super(key: key);
  127.  
  128.   @override
  129.   _TestOnPressedState createState() => _TestOnPressedState();
  130. }
  131.  
  132. class _TestOnPressedState extends State<TestOnPressed> {
  133.   @override
  134.   void initState() {
  135.     super.initState();
  136.     Firebase.initializeApp().whenComplete(() {
  137.       print("completed");
  138.       setState(() {});
  139.     });
  140.   }
  141.  
  142.   void setState(fn) {
  143.     FirebaseFirestore.instance;
  144.  
  145.     super.setState(fn);
  146.   }
  147.  
  148.   @override
  149.   Widget build(BuildContext context) {
  150.     return Scaffold(
  151.       appBar: AppBar(
  152.         title: Text(
  153.           'Sondage',
  154.           style: TextStyle(fontSize: 30.fontSize),
  155.         ),
  156.         centerTitle: true,
  157.       ),
  158.       body: Padding(
  159.         padding: const EdgeInsets.all(8.0),
  160.         child: Column(
  161.           children: [
  162.             Text(
  163.               'Partager votre Avis ',
  164.               style: GoogleFonts.bebasNeue(fontSize: 35.fontSize),
  165.             ),
  166.             Expanded(
  167.               child: Padding(
  168.                 padding: const EdgeInsets.only(top: 5),
  169.                 child: SondageFireStore(),
  170.               ),
  171.             ),
  172.             RaisedButton(
  173.               padding: EdgeInsets.symmetric(vertical: 8, horizontal: 30),
  174.               color: Colors.white,
  175.               shape: RoundedRectangleBorder(
  176.                 borderRadius: BorderRadius.all(
  177.                   Radius.circular(30),
  178.                 ),
  179.               ),
  180.               child: Text(
  181.                 'Valider',
  182.                 style: GoogleFonts.bebasNeue(fontSize: 30.fontSize),
  183.               ),
  184.               onPressed: () {},
  185.             )
  186.           ],
  187.         ),
  188.       ),
  189.     );
  190.   }
  191. }
  192.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement