Advertisement
AnoTest

TestDatabase.dart

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