Advertisement
Guest User

SearchClub.dart

a guest
Oct 4th, 2018
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.54 KB | None | 0 0
  1. class joinClub extends StatefulWidget {
  2. joinClub({ObjectKey key, this.player, this.themeConsole, this.themeBackground}) : super(key: key);
  3.  
  4.  
  5. Color themeConsole;
  6. Color themeBackground;
  7.  
  8. Player player;
  9.  
  10. @override
  11. _JoinClubState createState() {
  12. return _JoinClubState(
  13. searchClub: "",
  14. );
  15. }
  16. }
  17.  
  18. class _JoinClubState extends State<joinClub> {
  19.  
  20. Player player;
  21. String searchClub="";
  22.  
  23. // FIREBASE INVITATION USER SEND
  24. List<Player> items2 = List();
  25. Player item2;
  26. DatabaseReference itemRef2;
  27.  
  28.  
  29. // FIREBASE INVITATION CLUB SEND
  30. List<Club> items3 = List();
  31. Club item3;
  32. DatabaseReference itemRef3;
  33.  
  34. // FIREBASE CLUBS
  35. List<Club> itemsJoin = List();
  36. Club itemJoin;
  37. DatabaseReference itemRefJoin;
  38.  
  39. /////////ELEGIR COMUNIDAD/////////////
  40. final _comunidad = TextEditingController();
  41. List<String> _comunidades = new List<String>();
  42. String _imgComunidad = null;
  43. List<String> _imgComunidades = new List<String>();
  44.  
  45. var sub1, sub2, sub3, sub4, sub5, sub6, sub7;
  46.  
  47. @override
  48. void initState() {
  49. _comunidades.addAll([
  50. Country.ITEM_ARGENTINA,
  51. Country.ITEM_AUSTRALIA,
  52. Country.ITEM_AUSTRIA,
  53. Country.ITEM_BELGIUM,
  54. Country.ITEM_BRAZIL,
  55. Country.ITEM_CAMEROON,
  56. Country.ITEM_CHILE,
  57. Country.ITEM_COLOMBIA,
  58. Country.ITEM_COSTA_RICA,
  59. Country.ITEM_CROATIA,
  60. Country.ITEM_CUBA,
  61. Country.ITEM_DENMARK,
  62. Country.ITEM_ECUADOR,
  63. Country.ITEM_ENGLISH,
  64. Country.ITEM_FRANCE,
  65. Country.ITEM_GERMANY,
  66. Country.ITEM_HONDURAS,
  67. Country.ITEM_INDIA,
  68. Country.ITEM_ITALIAN,
  69. Country.ITEM_JAMAICA,
  70. Country.ITEM_MEXICO,
  71. Country.ITEM_MOROCCO,
  72. Country.ITEM_NETHERLANDS,
  73. Country.ITEM_NORWAY,
  74. Country.ITEM_PERU,
  75. Country.ITEM_POLAND,
  76. Country.ITEM_PORTUGAL,
  77. Country.ITEM_PUERTO_RICO,
  78. Country.ITEM_SOUTH_AFRICA,
  79. Country.ITEM_SPAIN,
  80. Country.ITEM_SWEDEN,
  81. Country.ITEM_SWITZERLAND,
  82. Country.ITEM_TURKEY,
  83. Country.ITEM_UKRAINE,
  84. Country.ITEM_UNITED_STATES,
  85. Country.ITEM_URUGUAY,
  86. Country.ITEM_VENEZUELA,
  87. ]);
  88. _comunidad.text = widget.player.country;
  89.  
  90. _imgComunidades.addAll([
  91. "images/idiomas/argentina.png",
  92. "images/idiomas/australia.png",
  93. "images/idiomas/austria.png",
  94. "images/idiomas/belgium.png",
  95. "images/idiomas/brazil.png",
  96. "images/idiomas/cameroon.png",
  97. "images/idiomas/chile.png",
  98. "images/idiomas/colombia.png",
  99. "images/idiomas/costa_rica.png",
  100. "images/idiomas/croatia.png",
  101. "images/idiomas/cuba.png",
  102. "images/idiomas/denmark.png",
  103. "images/idiomas/ecuador.png",
  104. "images/idiomas/england.png",
  105. "images/idiomas/france.png",
  106. "images/idiomas/germany.png",
  107. "images/idiomas/honduras.png",
  108. "images/idiomas/india.png",
  109. "images/idiomas/italy.png",
  110. "images/idiomas/jamaica.png",
  111. "images/idiomas/mexico.png",
  112. "images/idiomas/morocco.png",
  113. "images/idiomas/netherlands.png",
  114. "images/idiomas/norway.png",
  115. "images/idiomas/peru.png",
  116. "images/idiomas/poland.png",
  117. "images/idiomas/portugal.png",
  118. "images/idiomas/puerto_rico.png",
  119. "images/idiomas/south_africa.png",
  120. "images/idiomas/spain.png",
  121. "images/idiomas/sweden.png",
  122. "images/idiomas/switzerland.png",
  123. "images/idiomas/turkey.png",
  124. "images/idiomas/ukraine.png",
  125. "images/idiomas/united_states.png",
  126. "images/idiomas/uruguay.png",
  127. "images/idiomas/venezuela.png",
  128. ]);
  129. int obtenerImagen = _imgComunidades.indexOf('images/idiomas/${widget.player.country.toLowerCase().replaceAll(" ", "_")}.png');
  130. _imgComunidad = _imgComunidades.elementAt(obtenerImagen);
  131.  
  132. // CLUBS
  133. itemJoin = Club('', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', '', false, 0, 0);
  134. final FirebaseDatabase database = FirebaseDatabase.instance;
  135. itemRefJoin = database.reference().child(widget.player.platform).child("CLUB");
  136. sub1 = itemRefJoin.onChildAdded.listen(_onEntryAdded);
  137. sub2 = itemRefJoin.onChildRemoved.listen(_onEntryRemoved);
  138. sub3 = itemRefJoin.onChildChanged.listen(_onEntryChanged);
  139.  
  140. // INVITATIONS USERS SEND
  141. item2 = new Player('', '', '', '', '', '', '', '', '', 0, false, 0, 0, '', '', '', '', '', '', '', 0, 0, 0, 0, 0, false, '', '', false, false);
  142. final FirebaseDatabase database2 = FirebaseDatabase.instance;
  143. itemRef2 = database2.reference().child(widget.player.platform).child("USERS").child(widget.player.user.toUpperCase()).child("INVITATION");
  144. sub4 = itemRef2.onChildAdded.listen(_onEntryAdded_INVITATION);
  145. sub5 = itemRef2.onChildChanged.listen(_onEntryChanged_INVITATION);
  146.  
  147. super.initState();
  148. }
  149.  
  150. @override
  151. void dispose() {
  152. sub1?.cancel();
  153. sub2?.cancel();
  154. sub3?.cancel();
  155. sub4?.cancel();
  156. sub5?.cancel();
  157. sub6?.cancel();
  158. sub7?.cancel();
  159. super.dispose();
  160. }
  161.  
  162. @override // EN CASO DE QUE ALGÜN CAMBIO EN LA APP NO SALTE ERRORES
  163. void didChangeDependencies() {
  164. if(sub1 == null) {
  165.  
  166. }
  167. if(sub2 == null) {
  168.  
  169. }
  170. if(sub3 == null) {
  171.  
  172. }
  173. if(sub4 == null) {
  174.  
  175. }
  176. if(sub5 == null) {
  177.  
  178. }
  179. if(sub6 == null) {
  180.  
  181. }
  182. if(sub7 == null) {
  183.  
  184. }
  185. super.didChangeDependencies();
  186. }
  187.  
  188.  
  189.  
  190. // INVITATIONS USER SEND
  191. _onEntryAdded_INVITATION(Event event) {
  192. setState(() {
  193. items2.add(Player.fromSnapshot(event.snapshot));
  194. });
  195. }
  196. _onEntryChanged_INVITATION(Event event) {
  197. var old = items2.singleWhere((entry) {
  198. return entry.key == event.snapshot.key;
  199. });
  200. setState(() {
  201. items2[items2.indexOf(old)] = Player.fromSnapshot(event.snapshot);
  202. });
  203. }
  204.  
  205.  
  206.  
  207. // CLUBS
  208. _onEntryAdded(Event event) {
  209. setState(() {
  210. itemsJoin.add(Club.fromSnapshot(event.snapshot));
  211. });
  212. }
  213. _onEntryRemoved(Event event) {
  214. setState(() {
  215. print(event.snapshot.value);
  216. itemsJoin.removeAt(event.snapshot.value['club_id']);
  217. });
  218. }
  219. _onEntryChanged(Event event) {
  220. var old = itemsJoin.singleWhere((entry) {
  221. return entry.key == event.snapshot.key;
  222. });
  223. setState(() {
  224. itemsJoin[itemsJoin.indexOf(old)] = Club.fromSnapshot(event.snapshot);
  225. });
  226. }
  227.  
  228.  
  229. // App Search Bar
  230. SearchBar searchBar;
  231. final myController = TextEditingController();
  232.  
  233. AppBar buildAppBar(BuildContext context) {
  234. return new AppBar(
  235. title: new Text('Join Club'),
  236. centerTitle: true,
  237. backgroundColor: widget.themeBackground,
  238. actions: [searchBar.getSearchAction(context)]
  239. );
  240. }
  241.  
  242. _JoinClubState({this.searchClub, this.player}) {
  243. searchBar = new SearchBar(
  244. inBar: false,
  245. onChanged: onSubmitted,
  246. setState: setState,
  247. onSubmitted: onSubmitted,
  248. controller: myController,
  249. closeOnSubmit: true,
  250. hintText: "Escriba su club",
  251. clearOnSubmit: false,
  252. colorBackButton: true,
  253. showClearButton: true,
  254. buildDefaultAppBar: buildAppBar
  255. );
  256. }
  257.  
  258.  
  259. int listIndext = 2;
  260. void onSubmitted(String value) {
  261. setState(() {
  262. if(value.isNotEmpty) {
  263. searchClub = value;
  264. }
  265. });
  266. }
  267.  
  268. final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
  269. String key;
  270.  
  271.  
  272.  
  273. // ELEGIR COMUNIDAD MOSTRAR LISTA
  274. Widget _buildBottomPicker() {
  275. final FixedExtentScrollController scrollController = new FixedExtentScrollController();
  276. return new Container(
  277. height: MediaQuery.of(context).size.height/3.5,
  278. color: CupertinoColors.white,
  279. child: new DefaultTextStyle(
  280. style: const TextStyle(
  281. color: CupertinoColors.black,
  282. fontSize: 22.0,
  283. ),
  284. child: new SafeArea(
  285. child: new CupertinoPicker(
  286. scrollController: scrollController,
  287. itemExtent: MediaQuery.of(context).size.height/15,
  288. magnification: 0.7,
  289. diameterRatio: 0.5,
  290. backgroundColor: CupertinoColors.white,
  291. onSelectedItemChanged: (int index) {
  292. setState(() {
  293. _comunidad.text = _comunidades[index];
  294. _imgComunidad = _imgComunidades[index];
  295. });
  296. },
  297. children: new List<Widget>.generate(_comunidades.length, (int index) {
  298. return new Row(
  299. mainAxisAlignment: MainAxisAlignment.center,
  300. children: <Widget>[
  301. new Text(_comunidades[index]),
  302. ],
  303. );
  304. }),
  305. ),
  306. ),
  307. ),
  308. );
  309. }
  310.  
  311. searchClubs(TextEditingController countryChanged) {
  312. var widgetFireUpdate;
  313. setState(() {
  314. if(countryChanged.text == 'SPAIN') {
  315. widgetFireUpdate = new FirebaseAnimatedList(
  316. query: FirebaseDatabase.instance.reference().child(widget.player.platform).child("CLUB").orderByChild('country').equalTo(countryChanged.text),
  317. sort: (a, b) => a.value['createdDate'].compareTo(b.value['createdDate']),
  318. reverse: true,
  319. shrinkWrap: true,
  320. defaultChild: new CircularProgressIndicator(),
  321. itemBuilder: (BuildContext context, DataSnapshot snapshot,
  322. Animation<double> animation, int index) {
  323. return new StreamBuilder<Event>(
  324. stream: itemRef2.orderByKey().onValue,
  325. builder: (context, AsyncSnapshot<Event> snapshot2){
  326. if(snapshot2.hasData) {
  327. try {
  328. return new Container(
  329. decoration: new BoxDecoration(
  330. color: Colors.grey[300],
  331. ),
  332. child: new ListTile(
  333. leading: snapshot.value['logoURL'].toString().indexOf('images/assets/logo_notfound.png') == -1 ? new CachedNetworkImage(imageUrl: snapshot.value['logoURL'], width: MediaQuery.of(context).size.width/8) : new Image.asset(snapshot.value['logoURL'], width: MediaQuery.of(context).size.width/8),
  334. title: new Text(snapshot.value['name'].toUpperCase(), style: new TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: MediaQuery.of(context).size.width/30)),
  335. subtitle: new RichText(
  336. text: new TextSpan(
  337. children: <TextSpan>[
  338. new TextSpan(text: "CAPITÁN:", style: new TextStyle(color: Colors.black, fontSize: MediaQuery.of(context).size.width/35, fontWeight: FontWeight.bold)),
  339. new TextSpan(text: " ${snapshot.value['captain'].toUpperCase()}", style: new TextStyle(color: Colors.black, fontSize: MediaQuery.of(context).size.width/35)),
  340. ]
  341. ),
  342. ),
  343. ),
  344. );
  345.  
  346. }catch(e) {
  347. return new Container();
  348. }
  349. } else if(snapshot2.hasError){
  350. return new Container();
  351. } else {
  352. return new Container(
  353. child: new Center(
  354. child: new CircularProgressIndicator(
  355. backgroundColor: Colors.red,
  356. ),
  357. ),
  358. );
  359. }
  360. },
  361. );
  362. },
  363. );
  364. } else if(countryChanged.text == 'BRAZIL') {
  365. widgetFireUpdate = new FirebaseAnimatedList(
  366. query: FirebaseDatabase.instance.reference().child(widget.player.platform).child("CLUB").orderByChild('country').equalTo(countryChanged.text),
  367. sort: (a, b) => a.value['createdDate'].compareTo(b.value['createdDate']),
  368. reverse: true,
  369. shrinkWrap: true,
  370. defaultChild: new CircularProgressIndicator(),
  371. itemBuilder: (BuildContext context, DataSnapshot snapshot,
  372. Animation<double> animation, int index) {
  373. return new StreamBuilder<Event>(
  374. stream: itemRef2.orderByKey().onValue,
  375. builder: (context, AsyncSnapshot<Event> snapshot2){
  376. if(snapshot2.hasData) {
  377. try {
  378. return new Container(
  379. decoration: new BoxDecoration(
  380. color: Colors.grey[300],
  381. ),
  382. child: new ListTile(
  383. leading: snapshot.value['logoURL'].toString().indexOf('images/assets/logo_notfound.png') == -1 ? new CachedNetworkImage(imageUrl: snapshot.value['logoURL'], width: MediaQuery.of(context).size.width/8) : new Image.asset(snapshot.value['logoURL'], width: MediaQuery.of(context).size.width/8),
  384. title: new Text(snapshot.value['name'].toUpperCase(), style: new TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: MediaQuery.of(context).size.width/30)),
  385. subtitle: new RichText(
  386. text: new TextSpan(
  387. children: <TextSpan>[
  388. new TextSpan(text: "CAPITÁN:", style: new TextStyle(color: Colors.black, fontSize: MediaQuery.of(context).size.width/35, fontWeight: FontWeight.bold)),
  389. new TextSpan(text: " ${snapshot.value['captain'].toUpperCase()}", style: new TextStyle(color: Colors.black, fontSize: MediaQuery.of(context).size.width/35)),
  390. ]
  391. ),
  392. ),
  393. ),
  394. );
  395.  
  396. }catch(e) {
  397. return new Container();
  398. }
  399. } else if(snapshot2.hasError){
  400. return new Container();
  401. } else {
  402. return new Container(
  403. child: new Center(
  404. child: new CircularProgressIndicator(
  405. backgroundColor: Colors.red,
  406. ),
  407. ),
  408. );
  409. }
  410. },
  411. );
  412. },
  413. );
  414. }
  415. });
  416. return widgetFireUpdate;
  417. }
  418.  
  419. @override
  420. Widget build(BuildContext context) {
  421. return new Scaffold(
  422. key: _scaffoldKey,
  423. appBar: searchBar.build(context),
  424. body: new Container(
  425. color: widget.themeConsole,
  426. child: new Column(
  427. children: <Widget>[
  428. new Card(
  429. elevation: 0.0,
  430. color: Colors.grey[50],
  431. child: new Container(
  432. child: new Row(
  433. mainAxisAlignment: MainAxisAlignment.center,
  434. children: <Widget>[
  435. new Container(
  436. width: MediaQuery.of(context).size.width/1.35,
  437. child: new TextFormField(
  438. controller: _comunidad,
  439. style: new TextStyle(color: Colors.white),
  440. enabled: false,
  441. decoration: new InputDecoration(
  442. labelText: 'Community:',
  443. labelStyle: new TextStyle(color: Colors.white),
  444. icon: new Image.asset(_imgComunidad, width: 24.0),
  445. filled: true,
  446. fillColor: Colors.grey[800],
  447. ),
  448. validator: (String value){
  449. player.country = value;
  450. },
  451. ),
  452. ),
  453. new IconButton(
  454. icon: new Icon(Icons.flag, color: Colors.grey[800], size: 30.0,),
  455. color: Colors.black,
  456. onPressed: ()async {
  457. await showModalBottomSheet<void>(
  458. context: context,
  459. builder: (BuildContext context) {
  460. return _buildBottomPicker();
  461. },
  462. );
  463. },
  464. ),
  465. ],
  466. ),
  467. ),
  468. ),
  469. new Flexible(child: searchClubs(_comunidad))
  470. ],
  471. )
  472. ),
  473. );
  474. }
  475. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement