Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 7.95 KB | None | 0 0
  1. @override
  2.   void initState() {
  3.     super.initState();
  4.     idroom = "${widget.idroom}";
  5.     roomName = "${widget.namaroom}";
  6.     tglroom = "${widget.tgl}";
  7.     roomPass = "${widget.pass}";
  8.     status_member = "${widget.status_member}";
  9.     tipe = int.parse("${widget.tiperoom}");
  10.     roomOpen = "${widget.roomOpen}" == "true" ? true : false;
  11.     QuerySnapshot querySnapshot;
  12.     MenuPage.status_member = status_member;
  13.  
  14.     getAllChatRoom().then((results) {
  15.        showDialog(
  16.           context: context,
  17.           builder: (BuildContext context){
  18.             return Center(
  19.                   child: CircularProgressIndicator(
  20.                     valueColor: AlwaysStoppedAnimation<Color>(Colors.black),
  21.                     strokeWidth: 5.0,
  22.                     backgroundColor: Colors.transparent,
  23.                   ),
  24.                 );
  25.           }
  26.       );
  27.       setState(() {
  28.         querySnapshot = results;
  29.         urutan = querySnapshot.documents.length-1;
  30.          for(var i = 0; i < querySnapshot.documents.length ; i++)
  31.           {
  32.             RoomChatPage message = new RoomChatPage(mode : querySnapshot.documents[i].data['mode'],text: querySnapshot.documents[i].data['message'], iduser : querySnapshot.documents[i].data['id'], username : querySnapshot.documents[i].data['name'], ppicture : querySnapshot.documents[i].data['ppicture'],idlagu : querySnapshot.documents[i].data['idlagu']);
  33.  
  34.             setState(() {
  35.               _messages.insert(0, message);
  36.             });
  37.           }
  38.           Navigator.of(context).pop();
  39.       });
  40.     });
  41.   }
  42.  
  43.   getAllChatRoom() async {
  44.     return await  Firestore.instance
  45.         .document('chat/' + idroom)
  46.         .collection('messages').orderBy("urutan")
  47.         .getDocuments();
  48.   }
  49.      
  50.   void _handleSubmit(String text) {
  51.     _chatController.clear();
  52.  
  53.     if(modeChat == "lagu")
  54.     {
  55.       idlagu = text.split("|")[0];
  56.       text = text.split("|")[1];
  57.     }
  58.     else
  59.     {
  60.       idlagu = "";
  61.       text = text;
  62.     }
  63.     RoomChatPage message = new RoomChatPage(mode:modeChat,text: text, iduser : LoginPage.iduser, username : LoginPage.username, ppicture : LoginPage.ppicture,idlagu:idlagu);
  64.  
  65.     setState(() {
  66.       _messages.insert(0, message);
  67.       Firestore.instance
  68.           .document('chat/' + idroom)
  69.           .collection('messages')
  70.           .document()
  71.           .setData({'mode': modeChat,'urutan':urutan,'id': LoginPage.iduser,'name': LoginPage.username, 'message': text, 'ppicture': LoginPage.ppicture, 'idlagu' : idlagu});
  72.       });
  73.       urutan++;
  74.   }
  75.  
  76.   Widget _chatEnvironment() {
  77.     return IconTheme(
  78.       data: new IconThemeData(color: Colors.blue),
  79.       child: new Container(
  80.         child: new Row(
  81.           children: <Widget>[
  82.              new IconButton(
  83.                 icon: new Icon(
  84.                   Icons.queue_music,
  85.                   color: Colors.black,
  86.                 ),
  87.                 tooltip: 'Add Music to Chat',
  88.                 onPressed: (){
  89.                    showDialog(
  90.                       context: context,
  91.                       builder: (BuildContext context){
  92.                       return AlertDialog(
  93.                         contentPadding: MediaQuery.of(context).viewInsets,
  94.                         content: ListView(
  95.                               children: <Widget>[
  96.                                   AppBar(
  97.                                         automaticallyImplyLeading: false,
  98.                                         backgroundColor: Colors.black,
  99.                                         title: new Text("Find Music"),
  100.                                         actions: <Widget>[
  101.                                           new IconButton(
  102.                                             onPressed: () {
  103.                                               _showMaterialSearch(context);
  104.                                             },
  105.                                             tooltip: 'Search',
  106.                                             icon: new Icon(Icons.search),
  107.                                           ),
  108.                                         ],
  109.                                   ),
  110.                                   SizedBox(
  111.                                     height: MediaQuery.of(context).size.height,
  112.                                     child:
  113.                                         ListView.builder
  114.                                         (
  115.                                           itemCount: _musicData.length,
  116.                                           itemBuilder: (BuildContext ctxt, int index) {
  117.                                           return new  ListTile(
  118.                                                         title:Row(
  119.                                                               children: <Widget>[
  120.                                                                 Image(image: NetworkImage('http://groovey.xyz/music/'+_data["result"][index]["thumbnail_link"]),width: 60.0,),
  121.                                                                 Expanded(
  122.                                                                       child:
  123.                                                                         new Container(
  124.                                                                           child:Column(
  125.                                                                             crossAxisAlignment: CrossAxisAlignment.start,
  126.                                                                             children: <Widget>[
  127.                                                                                   Text(" "+_data["result"][index]["title"], style: TextStyle(fontSize:18.0),overflow: TextOverflow.ellipsis,),
  128.                                                                                   Text(" "+_data["result"][index]["artist"],style: TextStyle(fontSize:11.0), overflow: TextOverflow.ellipsis,),
  129.                                                                                 ]
  130.                                                                             ),
  131.                                                                         ),
  132.                                                                 ),
  133.                                                                 Icon(Icons.add)
  134.                                                               ],
  135.                                                         ),  
  136.                                                         onTap: (){
  137.                                                           modeChat="lagu";
  138.                                                           String textLagu =_data["result"][index]["ID"]+"|"+ _data["result"][index]["title"]+"\n "+_data["result"][index]["artist"];
  139.                                                           _handleSubmit(textLagu);
  140.                                                           Navigator.pop(context);
  141.                                                         },
  142.                                                       );
  143.                                           }
  144.                                         ),
  145.                                   ),
  146.                                
  147.                               ],
  148.                             ),
  149.                         );
  150.                       }
  151.                     );
  152.                 }
  153.               ),
  154.             new Flexible(
  155.               child: new TextField(
  156.                 decoration:
  157.                     new InputDecoration.collapsed(hintText: "Start typing ..."),
  158.                 controller: _chatController,
  159.                 onSubmitted: _handleSubmit,
  160.               ),
  161.             ),
  162.             new IconButton(
  163.                 icon: new Icon(
  164.                   Icons.send,
  165.                   color: Colors.black,
  166.                 ),
  167.                 onPressed: () {
  168.                   modeChat="biasa";
  169.                   _handleSubmit(_chatController.text);
  170.                 }
  171.               ),
  172.            
  173.            
  174.           ],
  175.         ),
  176.       ),
  177.     );
  178.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement