Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Made By Samir
- import 'package:TestFirebaseApp/OtherTests/TestCharts.dart';
- import 'package:firebase_core/firebase_core.dart';
- import 'package:firebase_database/firebase_database.dart';
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:cloud_firestore/cloud_firestore.dart';
- import 'package:google_fonts/google_fonts.dart';
- class TestDatabase extends StatefulWidget {
- final FirebaseApp app;
- TestDatabase({Key key, this.app}) : super(key: key);
- @override
- _TestDatabaseState createState() => _TestDatabaseState();
- }
- class _TestDatabaseState extends State<TestDatabase> {
- final referenceDatabase = FirebaseDatabase.instance;
- int selectedRadio;
- int selectedRadioTile;
- @override
- void initState() {
- selectedRadio = 0;
- selectedRadioTile = 0;
- super.initState();
- Firebase.initializeApp().whenComplete(() {
- print("completed");
- setState(() {});
- });
- }
- setSelectedRadio(int val) {
- setState(() {
- selectedRadio = val;
- });
- }
- setSelectedRadioTile(int val) {
- setState(() {
- selectedRadioTile = val;
- });
- }
- void addQuestion1(selectedRadioTile) {
- if (selectedRadioTile == 1) {
- FirebaseFirestore.instance
- .collection("Questions")
- .doc('Question_1')
- .update({'oui': FieldValue.increment(1)});
- }
- if (selectedRadioTile == 2) {
- FirebaseFirestore.instance
- .collection("Questions")
- .doc('Question_2')
- .update({'non': FieldValue.increment(1)});
- /*FirebaseFirestore.instance
- .collection("Questions1")
- .doc('Question_1')
- .update({'Femme': vard});*/
- }
- }
- void addQuestion2() {
- if (selectedRadioTile == 3) {
- FirebaseFirestore.instance
- .collection("Questions")
- .doc('Question_1')
- .update({'oui': FieldValue.increment(1)});
- }
- if (selectedRadioTile == 4) {
- FirebaseFirestore.instance
- .collection("Questions")
- .doc('Question_2')
- .update({'non': FieldValue.increment(1)});
- /*FirebaseFirestore.instance
- .collection("Questions1")
- .doc('Question_1')
- .update({'Femme': vard});*/
- }
- }
- //final TestController = TextEditingController();
- @override
- Widget build(BuildContext context) {
- //final ref = referenceDatabase.reference();
- //Firebase.initializeApp();
- //FirebaseFirestore.instance.collection('Questions').snapshots();
- return Scaffold(
- body: SingleChildScrollView(
- child: Padding(
- padding: const EdgeInsets.all(15.0),
- child: new Container(
- child: StreamBuilder(
- stream: FirebaseFirestore.instance
- .collection('Questions')
- .snapshots(),
- builder: (BuildContext context, snapshot) {
- if (!snapshot.hasData) return Text('Loading.....');
- return Column(
- children: [
- Padding(
- padding: const EdgeInsets.only(
- bottom: 15,
- ),
- child: Text(
- 'Partager Votre Avis ',
- style: GoogleFonts.bebasNeue(
- fontSize: 25,
- ),
- ),
- ),
- Container(
- padding: EdgeInsets.only(top: 10),
- decoration: BoxDecoration(
- color: Colors.lightBlue.shade600,
- borderRadius: BorderRadius.all(
- Radius.circular(20),
- ),
- ),
- child: Column(
- children: [
- Text(
- snapshot.data.docs[0]['title'],
- style: GoogleFonts.bebasNeue(
- fontSize: 24,
- color: Colors.white,
- ),
- ),
- RadioListTile(
- value: 1,
- groupValue: selectedRadioTile,
- title: Text(
- "Oui",
- style: GoogleFonts.bebasNeue(
- fontSize: 20, color: Colors.white),
- ),
- // subtitle: Text("Radio 1 Subtitle"),
- onChanged: (val) {
- print("Radio Tile pressed $val");
- setSelectedRadioTile(val);
- },
- activeColor: Colors.black,
- //selected: true,
- ),
- RadioListTile(
- value: 2,
- groupValue: selectedRadioTile,
- title: Text(
- "Non",
- style: GoogleFonts.bebasNeue(
- fontSize: 20, color: Colors.white),
- ),
- //subtitle: Text("Radio 2 Subtitle"),
- onChanged: (val) {
- print("Radio Tile pressed $val");
- setSelectedRadioTile(val);
- },
- activeColor: Colors.black,
- selected: false,
- ),
- ],
- ),
- ),
- RaisedButton(
- color: Colors.lightBlue,
- child: Text(
- 'Valider',
- style: GoogleFonts.bebasNeue(
- fontSize: 20,
- color: Colors.white,
- ),
- ),
- onPressed: () {
- addQuestion1(selectedRadioTile);
- },
- ),
- Container(
- //child: TestStreamBuilder(),
- ),
- ],
- );
- }),
- ),
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement