Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 22.24 KB | None | 0 0
  1. ```import 'dart:async';
  2.  
  3. import 'package:cached_network_image/cached_network_image.dart';
  4. import 'package:cloud_firestore/cloud_firestore.dart';
  5. import 'package:firebase_auth/firebase_auth.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:fluttertoast/fluttertoast.dart';
  8. import 'package:mailer/mailer.dart';
  9. import 'package:mailer/smtp_server.dart';
  10. import 'package:photo_view/photo_view.dart';
  11. import 'package:travel_world/chat/chat.dart';
  12. import 'package:travel_world/const.dart';
  13. import 'package:travel_world/full_screen_image.dart';
  14. import 'package:travel_world/messages/messages.dart';
  15. import 'package:travel_world/navigation/navigation.dart';
  16. import 'package:travel_world/profile/profile.dart';
  17.  
  18. class Meetup extends StatefulWidget {
  19.   @override
  20.   State createState() => MeetupState();
  21. }
  22.  
  23. class MeetupState extends State<Meetup> {
  24.   FirebaseAuth firebaseAuth = FirebaseAuth.instance;
  25.   StreamSubscription<QuerySnapshot> _subscription;
  26.   List<DocumentSnapshot> _sameCountryUsersDocumentSnapshotList;
  27.   final CollectionReference _usersCollectionReference =
  28.       Firestore.instance.collection("users");
  29.  
  30.   @override
  31.   void initState() {
  32.     super.initState();
  33.     _getSameCountryUsers();
  34.     searchController.addListener(() {
  35.       setState(() {
  36.         filter = searchController.text;
  37.       });
  38.     });
  39.   }
  40.  
  41.   TextEditingController searchController = new TextEditingController();
  42.   String filter;
  43.  
  44.   Future<List<DocumentSnapshot>> getDocumentSnapshotListOfSameCountryUsers(
  45.       {@required String country}) async {
  46.     QuerySnapshot querySnapshot = await _usersCollectionReference
  47.         .where('country', isEqualTo: country)
  48.         .getDocuments();
  49.  
  50.     return querySnapshot.documents;
  51.   }
  52.  
  53.   Future<void> _getSameCountryUsers() async {
  54.     final FirebaseUser user = await firebaseAuth.currentUser();
  55.     final uid = user.uid;
  56.  
  57.     DocumentSnapshot userProfileInfo =
  58.         await _usersCollectionReference.document(uid).get();
  59.  
  60.     String country = userProfileInfo.data['country'];
  61.  
  62.     List<DocumentSnapshot> usersList =
  63.         await getDocumentSnapshotListOfSameCountryUsers(country: country);
  64.  
  65.     setState(() {
  66.       _sameCountryUsersDocumentSnapshotList = usersList;
  67.     });
  68.   }
  69.  
  70.   @override
  71.   void dispose() {
  72.     searchController.dispose();
  73.     super.dispose();
  74.     _subscription.cancel();
  75.   }
  76.  
  77.   @override
  78.   Widget build(BuildContext context) {
  79.     return Scaffold(
  80.       backgroundColor: Colors.black,
  81.       body: Column(
  82.         crossAxisAlignment: CrossAxisAlignment.center,
  83.         children: <Widget>[
  84.           _buildAppBar(),
  85.           _buildSearchBar(),
  86.           Expanded(
  87.             child: _sameCountryUsersDocumentSnapshotList != null
  88.                 ? _buildUsersList()
  89.                 : Center(
  90.                     child: CircularProgressIndicator(
  91.                       valueColor:
  92.                           AlwaysStoppedAnimation<Color>(Color(0xffc67608)),
  93.                     ),
  94.                   ),
  95.           ),
  96.         ],
  97.       ),
  98.       bottomNavigationBar: BottomNavigationBar(
  99.         type: BottomNavigationBarType.fixed,
  100.         backgroundColor: Colors.black,
  101.         items: <BottomNavigationBarItem>[
  102.           BottomNavigationBarItem(
  103.             backgroundColor: Colors.black,
  104.             title: Text(''),
  105.             icon: IconButton(
  106.               icon: Icon(
  107.                 Icons.home,
  108.                 color: Colors.grey,
  109.               ),
  110.               onPressed: () {
  111.                 Navigator.push(
  112.                   context,
  113.                   MaterialPageRoute(builder: (context) => Navigation()),
  114.                 );
  115.               },
  116.             ),
  117.           ),
  118.           BottomNavigationBarItem(
  119.             icon: IconButton(
  120.               icon: Icon(
  121.                 Icons.vpn_lock,
  122.                 color: Color(0xffc67608),
  123.               ),
  124.               onPressed: () {},
  125.             ),
  126.             title: Text(''),
  127.           ),
  128.           BottomNavigationBarItem(
  129.             icon: IconButton(
  130.               icon: Icon(
  131.                 Icons.comment,
  132.                 color: Colors.grey,
  133.               ),
  134.               onPressed: () {
  135.                 Navigator.push(
  136.                   context,
  137.                   MaterialPageRoute(builder: (context) => Messages()),
  138.                 );
  139.               },
  140.             ),
  141.             title: Text(''),
  142.           ),
  143.           BottomNavigationBarItem(
  144.             icon: IconButton(
  145.               icon: Icon(
  146.                 Icons.perm_identity,
  147.                 color: Colors.grey,
  148.               ),
  149.               onPressed: () {
  150.                 Navigator.push(
  151.                   context,
  152.                   MaterialPageRoute(builder: (context) => Profile()),
  153.                 );
  154.               },
  155.             ),
  156.             title: Text(''),
  157.           ),
  158.         ],
  159.       ),
  160.     );
  161.   }
  162.  
  163.   Widget _buildUsersList() {
  164.     return Padding(
  165.       padding: const EdgeInsets.all(15.0),
  166.       child: ListView.builder(
  167.         shrinkWrap: true,
  168.         itemCount: _sameCountryUsersDocumentSnapshotList.length,
  169.         itemBuilder: ((context, index) {
  170.           return filter == null || filter == ""
  171.               ? _buildUserListTile(
  172.                   userDataMap:
  173.                       _sameCountryUsersDocumentSnapshotList[index].data,
  174.                   context: context)
  175.               : _sameCountryUsersDocumentSnapshotList[index]
  176.                       .data['name']
  177.                       .toLowerCase()
  178.                       .contains(filter.toLowerCase())
  179.                   ? _buildUserListTile(
  180.                       userDataMap:
  181.                           _sameCountryUsersDocumentSnapshotList[index].data,
  182.                       context: context)
  183.                   : SizedBox.shrink();
  184.         }),
  185.       ),
  186.     );
  187.   }
  188.  
  189.   Widget _buildUserListTile(
  190.       {@required Map userDataMap, @required BuildContext context}) {
  191.     return ListTile(
  192.       leading: Container(
  193.         padding: const EdgeInsets.all(3.0),
  194.         decoration: new BoxDecoration(
  195.           color: Color(0xffc67608), // border color
  196.           shape: BoxShape.circle,
  197.         ),
  198.         child: CircleAvatar(
  199.           backgroundColor: Colors.black,
  200.           backgroundImage: NetworkImage(userDataMap['photoUrl']),
  201.         ),
  202.       ),
  203.       title: Text(userDataMap['name'],
  204.           style: TextStyle(
  205.             color: Colors.white,
  206.           )),
  207.       subtitle: Text(userDataMap['country'],
  208.           style: TextStyle(
  209.             color: Colors.white70,
  210.             fontSize: 17,
  211.           )),
  212.       trailing: RaisedButton(
  213.         color: Colors.transparent,
  214.         shape: RoundedRectangleBorder(
  215.           side: BorderSide(
  216.             style: BorderStyle.solid,
  217.             color: Color(0xffc67608),
  218.           ),
  219.           borderRadius: BorderRadius.all(
  220.             Radius.circular(16.0),
  221.           ),
  222.         ),
  223.         child: Text(
  224.           "Message",
  225.           style: TextStyle(
  226.             fontSize: 14,
  227.           ),
  228.         ),
  229.         textColor: Color(0xffc67608),
  230.         onPressed: () {
  231.           Navigator.push(
  232.               context,
  233.               new MaterialPageRoute(
  234.                   builder: (context) => ChatScreen(
  235.                         name: userDataMap['name'],
  236.                         photoUrl: userDataMap['photoUrl'],
  237.                         receiverUid: userDataMap['uid'],
  238.                         country: userDataMap['country'],
  239.                       )));
  240.         },
  241.       ),
  242.       onTap: (() {
  243.         Navigator.push(
  244.             context,
  245.             new MaterialPageRoute(
  246.                 builder: (context) => ViewProfile(
  247.                     name: userDataMap['name'],
  248.                     email: userDataMap['email'],
  249.                     profession: userDataMap['profession'],
  250.                     country: userDataMap['country'],
  251.                     aboutMe: userDataMap['aboutMe'],
  252.                     gender: userDataMap['gender'],
  253.                     photoUrl: userDataMap['photoUrl'],
  254.                     images: userDataMap['images'],
  255.                     uid: userDataMap['uid'])));
  256.       }),
  257.     );
  258.   }
  259.  
  260.   Widget _buildSearchBar() {
  261.     return Column(
  262.       crossAxisAlignment: CrossAxisAlignment.center,
  263.       children: <Widget>[
  264.         SizedBox(
  265.           height: 20.0,
  266.         ),
  267.         Container(
  268.           width: 330,
  269.           height: 50,
  270.           child: TextField(
  271.             controller: searchController,
  272.             decoration: InputDecoration(
  273.                 filled: true,
  274.                 fillColor: Colors.white,
  275.                 hintText: "Search",
  276.                 prefixIcon: Icon(Icons.search),
  277.                 border: OutlineInputBorder(
  278.                     borderRadius: BorderRadius.all(Radius.circular(10.0)))),
  279.           ),
  280.         ),
  281.         SizedBox(
  282.           height: 15,
  283.         ),
  284.         Text(
  285.           'Search for PNA members around you'.toUpperCase(),
  286.           textAlign: TextAlign.center,
  287.           style: TextStyle(
  288.             color: Colors.white70,
  289.             fontSize: 15,
  290.           ),
  291.         ),
  292.       ],
  293.     );
  294.   }
  295.  
  296.   Widget _buildAppBar() {
  297.     return AppBar(
  298.       title: Text(
  299.         'Connections'.toUpperCase(),
  300.         style: TextStyle(
  301.           fontSize: 20,
  302.           color: Colors.white,
  303.         ),
  304.       ),
  305.       backgroundColor: Colors.transparent,
  306.       automaticallyImplyLeading: true,
  307.       centerTitle: true,
  308.     );
  309.   }
  310. }
  311.  
  312. class ViewProfile extends StatefulWidget {
  313.   String name;
  314.   String email;
  315.   String country;
  316.   String aboutMe;
  317.   String profession;
  318.   String gender;
  319.   String photoUrl;
  320.   final List images;
  321.   String uid;
  322.  
  323.   ViewProfile(
  324.       {this.name,
  325.       this.email,
  326.       this.photoUrl,
  327.       this.uid,
  328.       this.aboutMe,
  329.       this.country,
  330.       this.gender,
  331.       this.profession,
  332.       this.images});
  333.  
  334.   @override
  335.   _ViewProfileState createState() => _ViewProfileState();
  336. }
  337.  
  338. class _ViewProfileState extends State<ViewProfile> {
  339.   DocumentSnapshot documentSnapshot;
  340.  
  341.   PhotoViewScaleStateController scaleStateController;
  342.  
  343.   main() async {
  344.     String username = 'ameenidris710@gmail.com';
  345.     String password = 'allahu710';
  346.  
  347.     final smtpServer = gmail(username, password);
  348.     // Creating the Gmail server
  349.  
  350.     // Create our email message.
  351.     final message = Message()
  352.       ..from = Address(username)
  353.       ..recipients.add('alameenidris710@gmail.com') //recipent email
  354.       ..subject = 'User Reported ${DateTime.now()}' //subject of the email
  355.       ..text =
  356.           'The user ${widget.name} from  ${widget.country} has been reported.\n The user has violated a rule will be under review'; //body of the email
  357.  
  358.     try {
  359.       final sendReport = await send(message, smtpServer);
  360.       print('Message sent: ' +
  361.           sendReport.toString()); //print if the email is sent
  362.     } on MailerException catch (e) {
  363.       print('Message not sent. \n' +
  364.           e.toString()); //print if the email is not sent
  365.       // e.toString() will show why the email is not sending
  366.     }
  367.  
  368.     Fluttertoast.showToast(
  369.         msg: "User reported and will be under review",
  370.         toastLength: Toast.LENGTH_SHORT,
  371.         gravity: ToastGravity.CENTER,
  372.         timeInSecForIos: 3,
  373.         backgroundColor: Color(0xffc67608),
  374.         textColor: Colors.white,
  375.         fontSize: 13.0);
  376.   }
  377.  
  378.   @override
  379.   void initState() {
  380.     super.initState();
  381.     scaleStateController = PhotoViewScaleStateController();
  382.   }
  383.  
  384.   @override
  385.   void dispose() {
  386.     scaleStateController.dispose();
  387.     super.dispose();
  388.   }
  389.  
  390.   void goBack() {
  391.     scaleStateController.scaleState = PhotoViewScaleState.originalSize;
  392.   }
  393.  
  394.   @override
  395.   Widget build(BuildContext context) {
  396.     // TODO: implement build
  397.     return Scaffold(
  398.       appBar: AppBar(
  399.         title: Text(
  400.           widget.name,
  401.           style: TextStyle(
  402.             fontSize: 25,
  403.             color: Colors.white,
  404.           ),
  405.         ),
  406.         backgroundColor: Colors.black,
  407.       ),
  408.       backgroundColor: Colors.black,
  409.       body: SingleChildScrollView(
  410.         child: Column(
  411.           children: <Widget>[
  412.             SizedBox(
  413.               height: 25,
  414.             ),
  415.             Row(
  416.               mainAxisAlignment: MainAxisAlignment.center,
  417.               children: <Widget>[
  418.                 Padding(
  419.                   padding: const EdgeInsets.all(10.0),
  420.                   child: Column(
  421.                     mainAxisAlignment: MainAxisAlignment.center,
  422.                     children: <Widget>[
  423.                       CircleAvatar(
  424.                         backgroundImage: NetworkImage(widget.photoUrl),
  425.                         radius: 50.0,
  426.                       ),
  427.                     ],
  428.                   ),
  429.                 ),
  430.               ],
  431.             ),
  432.             Column(
  433.               children: <Widget>[
  434.                 Row(
  435.                   mainAxisAlignment: MainAxisAlignment.center,
  436.                   children: <Widget>[
  437.                     RaisedButton(
  438.                       shape: RoundedRectangleBorder(
  439.                         side: BorderSide(
  440.                           style: BorderStyle.solid,
  441.                           color: Color(0xffc67608),
  442.                         ),
  443.                         borderRadius: BorderRadius.all(
  444.                           Radius.circular(16.0),
  445.                         ),
  446.                       ),
  447.                       color: Colors.black,
  448.                       onPressed: () {
  449.                         Navigator.push(
  450.                             context,
  451.                             new MaterialPageRoute(
  452.                                 builder: (context) => ChatScreen(
  453.                                       name: widget.name,
  454.                                       photoUrl: widget.photoUrl,
  455.                                       receiverUid: widget.uid,
  456.                                       country: widget.country,
  457.                                     )));
  458.                       },
  459.                       child: Text(
  460.                         'Message',
  461.                         style: TextStyle(
  462.                           color: Color(0xffc67608),
  463.                           fontSize: 14,
  464.                         ),
  465.                       ),
  466.                     ),
  467.                     SizedBox(
  468.                       width: 15,
  469.                     ),
  470.                     RaisedButton(
  471.                       shape: RoundedRectangleBorder(
  472.                         side: BorderSide(
  473.                           style: BorderStyle.solid,
  474.                           color: Color(0xffc67608),
  475.                         ),
  476.                         borderRadius: BorderRadius.all(
  477.                           Radius.circular(16.0),
  478.                         ),
  479.                       ),
  480.                       color: Colors.black,
  481.                       onPressed: main,
  482.                       child: Text(
  483.                         'Report',
  484.                         style: TextStyle(
  485.                           color: Color(0xffc67608),
  486.                           fontSize: 14,
  487.                         ),
  488.                       ),
  489.                     )
  490.                   ],
  491.                 ),
  492.               ],
  493.             ),
  494.             SizedBox(
  495.               height: 10,
  496.             ),
  497.             Padding(
  498.               padding: const EdgeInsets.fromLTRB(13.0, 0.0, 0.0, 0.0),
  499.               child: Row(
  500.                 mainAxisAlignment: MainAxisAlignment.start,
  501.                 children: <Widget>[
  502.                   Text(
  503.                     widget.country.toUpperCase(),
  504.                     textAlign: TextAlign.left,
  505.                     style: TextStyle(
  506.                         color: Colors.white,
  507.                         fontFamily: 'RalewayRegular',
  508.                         fontSize: 15,
  509.                         fontWeight: FontWeight.w400),
  510.                   ),
  511.                 ],
  512.               ),
  513.             ),
  514.             SizedBox(
  515.               height: 5,
  516.             ),
  517.             Padding(
  518.               padding: const EdgeInsets.fromLTRB(13.0, 0.0, 0.0, 0.0),
  519.               child: Row(
  520.                 mainAxisAlignment: MainAxisAlignment.start,
  521.                 children: <Widget>[
  522.                   Text(
  523.                     widget.profession.toUpperCase(),
  524.                     textAlign: TextAlign.left,
  525.                     style: TextStyle(
  526.                         color: Colors.white,
  527.                         fontFamily: 'RalewayRegular',
  528.                         fontSize: 15,
  529.                         fontWeight: FontWeight.w300),
  530.                   ),
  531.                 ],
  532.               ),
  533.             ),
  534.             SizedBox(
  535.               height: 5,
  536.             ),
  537.             Padding(
  538.               padding: const EdgeInsets.fromLTRB(13.0, 0.0, 0.0, 0.0),
  539.               child: Row(
  540.                 mainAxisAlignment: MainAxisAlignment.start,
  541.                 children: <Widget>[
  542.                   Text(
  543.                     widget.gender.toUpperCase(),
  544.                     textAlign: TextAlign.left,
  545.                     style: TextStyle(
  546.                         fontSize: 15,
  547.                         fontFamily: 'RalewayRegular',
  548.                         color: Colors.white,
  549.                         fontWeight: FontWeight.w300),
  550.                   ),
  551.                 ],
  552.               ),
  553.             ),
  554.             SizedBox(
  555.               height: 15,
  556.             ),
  557.             Row(
  558.               mainAxisAlignment: MainAxisAlignment.start,
  559.               children: <Widget>[
  560.                 Container(
  561.                   width: 190,
  562.                   child: Divider(
  563.                     height: 10,
  564.                     color: Color(0xffc67608),
  565.                     thickness: 4,
  566.                   ),
  567.                 ),
  568.               ],
  569.             ),
  570.             SizedBox(
  571.               height: 15,
  572.             ),
  573.             Padding(
  574.               padding: const EdgeInsets.all(15.0),
  575.               child: Column(
  576.                 mainAxisAlignment: MainAxisAlignment.start,
  577.                 children: <Widget>[
  578.                   Text(
  579.                     widget.aboutMe,
  580.                     textAlign: TextAlign.left,
  581.                     style: TextStyle(
  582.                       fontSize: 16,
  583.                       color: Colors.white,
  584.                     ),
  585.                   ),
  586.                 ],
  587.               ),
  588.             ),
  589.             SizedBox(
  590.               height: 10,
  591.             ),
  592.             (widget.images == null || widget.images.isEmpty)
  593.                 ? Container()
  594.                 : Align(
  595.                     alignment: Alignment.centerLeft,
  596.                     child: Padding(
  597.                       padding: const EdgeInsets.all(16.0),
  598.                       child: Wrap(
  599.                           alignment: WrapAlignment.start,
  600.                           children: widget.images
  601.                               .map((imageUrl) => ProfileImageItem(
  602.                                     imageUrl: imageUrl,
  603.                                   ))
  604.                               .toList()),
  605.                     ),
  606.                   ),
  607.             SizedBox(
  608.               height: 35,
  609.             ),
  610.           ],
  611.         ),
  612.       ),
  613.       bottomNavigationBar: BottomNavigationBar(
  614.         type: BottomNavigationBarType.fixed,
  615.         backgroundColor: Colors.black,
  616.         items: <BottomNavigationBarItem>[
  617.           BottomNavigationBarItem(
  618.             backgroundColor: Colors.black,
  619.             title: Text(''),
  620.             icon: IconButton(
  621.               icon: Icon(
  622.                 Icons.home,
  623.                 color: Colors.grey,
  624.               ),
  625.               onPressed: () {
  626.                 Navigator.push(
  627.                   context,
  628.                   MaterialPageRoute(builder: (context) => Navigation()),
  629.                 );
  630.               },
  631.             ),
  632.           ),
  633.           BottomNavigationBarItem(
  634.             icon: IconButton(
  635.               icon: Icon(
  636.                 Icons.vpn_lock,
  637.                 color: Color(0xffc67608),
  638.               ),
  639.               onPressed: () {},
  640.             ),
  641.             title: Text(''),
  642.           ),
  643.           BottomNavigationBarItem(
  644.             icon: IconButton(
  645.               icon: Icon(
  646.                 Icons.comment,
  647.                 color: Colors.grey,
  648.               ),
  649.               onPressed: () {
  650.                 Navigator.push(
  651.                   context,
  652.                   MaterialPageRoute(builder: (context) => Messages()),
  653.                 );
  654.               },
  655.             ),
  656.             title: Text(''),
  657.           ),
  658.           BottomNavigationBarItem(
  659.             icon: IconButton(
  660.               icon: Icon(
  661.                 Icons.perm_identity,
  662.                 color: Colors.grey,
  663.               ),
  664.               onPressed: () {
  665.                 Navigator.push(
  666.                   context,
  667.                   MaterialPageRoute(builder: (context) => Profile()),
  668.                 );
  669.               },
  670.             ),
  671.             title: Text(''),
  672.           ),
  673.         ],
  674.       ),
  675.     );
  676.   }
  677. }
  678.  
  679. class ProfileImageItem extends StatelessWidget {
  680.   final String imageUrl;
  681.  
  682.   const ProfileImageItem({Key key, @required this.imageUrl}) : super(key: key);
  683.  
  684.   @override
  685.   Widget build(BuildContext context) {
  686.     return Hero(
  687.       tag: imageUrl,
  688.       child: FractionallySizedBox(
  689.         widthFactor: 0.5,
  690.         child: Stack(children: [
  691.           Padding(
  692.             padding: const EdgeInsets.all(8.0),
  693.             child: AspectRatio(
  694.               aspectRatio: 1.0,
  695.               child: InkWell(
  696.                 onTap: () {
  697.                   Navigator.push(
  698.                       context,
  699.                       new MaterialPageRoute(
  700.                           builder: (context) =>
  701.                               FullScreenImage(imageUrl: imageUrl)));
  702.                 },
  703.                 child: CachedNetworkImage(
  704.                   placeholder: (context, url) => Container(
  705.                     child: Center(
  706.                       child: CircularProgressIndicator(
  707.                         strokeWidth: 2.0,
  708.                         valueColor: AlwaysStoppedAnimation<Color>(themeColor),
  709.                       ),
  710.                     ),
  711.                   ),
  712.                   imageUrl: imageUrl,
  713.                   fit: BoxFit.cover,
  714.                 ),
  715.               ),
  716.             ),
  717.           ),
  718.         ]),
  719.       ),
  720.     );
  721.   }
  722. }
  723. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement