mardi 13 octobre 2020

use chip and send data from list view to another page using chip (Flutter)

I am learning Flutter and I have an issue with one of my page. I have created a view with an icon. When I click on this icon, I am getting a list view with Datas coming from Firebase. This part is working. I am trying to implement a simple but complex feature. When the list view is displayed, I am trying to get a checkbox beside each line. I would like to be able by Tap to get the checkbox checked. Then, by pressing a Save button, the idea is to go back to destroy the list view and come back to the previous view. In this previous view, I will show in a chip each data selected previously in the list view. I hope it is clear. Many thanks in advance for your help. It is appreciated.

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:gtd_official_sharped_focused/Const.dart';

import 'package:gtd_official_sharped_focused/Reusable Widget/myDrawer_Widget.dart';

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';



var TimeDisplay;
bool isOn = true;


class Engage extends StatefulWidget {
  Engage ({Key key}) : super(key:key);

  @override
  _EngageState createState() => _EngageState();
}

class _EngageState extends State<Engage> {



  @override
  Widget build(BuildContext context) {
    return Scaffold(
        drawer:  new MyMenu(),
        appBar: new AppBar(
          title: new Text('Subjects'),),

        body: MyEngage(),//Center(child: new Text("Subject")),
      

    );
    throw UnimplementedError();
  }
}

class MyEngage extends StatefulWidget {
  @override
  _MyEngageState createState() => _MyEngageState();
}

class _MyEngageState extends State<MyEngage> {
  int selectedSubject = 0;

  @override
  Widget build(BuildContext context) {
    return Container(
        padding: const EdgeInsets.all(10.0),
        decoration: BoxDecoration(
            border: Border.all(color: Colors.grey[350])),
        child: Column(
          children: [
            Padding(
              padding: const EdgeInsets.all(3.0),
              child: Container(
                padding: const EdgeInsets.all(10.0),
                decoration: BoxDecoration(
                    border: Border.all(color: Colors.grey[350])
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [

                    GestureDetector(
                      child: Column(
                        children: [
                          IconButton(
                              splashColor: Colors.lightGreenAccent,
                              icon: Image.asset('assets/icons/subject.png',
                                height: iconHeighEngage,),
                              onPressed: () {
                                showDialog(
                                  context: context,
                                  builder: (BuildContext context) {
                                    return StatefulBuilder(
                                        builder: (context, setState){
                                          return AlertDialog(
                                            title: Text('Subject'),
                                            content: Container(

                                              height: 450,
                                              width: 350,
                                              child: Column(
                                                children: <Widget>[
                                                  //SizedBox(
                                                  // height: 30,
                                                  //),
                                                  Container(
                                                    height: 425,

                                                    child: StreamBuilder(
                                                        stream: FirebaseFirestore.instance
                                                            .collection('Users')
                                                            .doc(FirebaseAuth.instance.currentUser.uid)
                                                            .collection('subjet')
                                                            .snapshots(),
                                                        builder: (BuildContext context,
                                                            AsyncSnapshot<QuerySnapshot> snapshot) {
                                                          if (!snapshot.hasData) {
                                                            return Center(
                                                              child: CircularProgressIndicator(),
                                                            );
                                                          }


                                                          return ListView(
                                                            children: snapshot.data.docs.map((document) {
                                                              return CheckboxListTile(
                                                                  title: Text(document.data()['subject_name'],),
                                                                  value: false,
                                                                  onChanged: (bool value) {

                                                                  }
                                                              );
                                                            }
                                                            ).toList(),
                                                          );

                                                        }),
                                                  ),

                                                ],
                                              ),
                                            ),
                                            actions: <Widget>[
                                              FlatButton(
                                                  child: Text("Cancel",
                                                      style: TextStyle(
                                                        color: Colors.grey,)),
                                                  onPressed: () {
                                                    selectedContext=0;
                                                    Navigator.of(context).pop();
                                                  },
                                                  shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))

                                              ),

                                              FlatButton(
                                                child: Text("OK",
                                                    style: TextStyle(
                                                      color: Colors.blue,)),
                                                onPressed: () {
                                                  Navigator.of(context).pop();
                                                },
                                              ),
                                            ],
                                          );
                                        });
                                  },
                                );
                              }
                          ),

                          Text('Subject')],
                      ),
                    ),

                  ],
                ),
              ),
              ),


            // Energy
            Card(
              child: Row(
                children: [
                  Padding(
                    padding: const EdgeInsets.fromLTRB(16.0,12.0,0.0,0.0),
                    child: Align(alignment: Alignment.centerLeft,
                      child: Container(
                        //color: Colors.grey,
                          child:  ConstrainedBox (
                            constraints: BoxConstraints(
                            minWidth:  35,
                            minHeight:  35,
                            maxWidth:  35,
                            maxHeight:  35,
                            ),
                            child: Image.asset('assets/icons/subject.png', fit: BoxFit.cover),
                        ),
                      ),
                    ),
                    ),

                  Padding(
                    padding: const EdgeInsets.fromLTRB(10.0,12.0,10.0,0.0),
                    child: Align(alignment: Alignment.centerLeft,
                      child: Container(
                        //color: Colors.grey,
                        child: Text(
                          "subject", style: TextStyle(color: Colors.black),
                        ),
                      ),
                    ),
                  ),

                  Padding(
                    padding: const EdgeInsets.fromLTRB(27.0,12.0,10.0,0.0),
                    child: Align(alignment: Alignment.centerLeft,
                      child: Container(
                        //color: Colors.grey,
                        child: Text(
                          '$selectedSubject', style: TextStyle(color: Colors.black),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),



            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Container(
                width: 390,

                child: Column(

                  
                  crossAxisAlignment: CrossAxisAlignment.start,

                  children: [

                   



    ],
                ),
              ),
            ),
          ]
        ),
    );

}
}




Aucun commentaire:

Enregistrer un commentaire