Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.88 KB | None | 0 0
  1. import 'dart:async';
  2. import 'dart:convert';
  3.  
  4. import 'package:flutter/material.dart';
  5. import 'package:http/http.dart' as http;
  6. import 'package:travel_world/meetup/meetup.dart';
  7. import 'package:travel_world/messages/messages.dart';
  8. import 'package:travel_world/navigation/navigation.dart';
  9. import 'package:travel_world/profile/profile.dart';
  10.  
  11. class PrivilegePage extends StatefulWidget {
  12. @override
  13. State createState() => PrivilegePageState();
  14. }
  15.  
  16. class PrivilegePageState extends State<PrivilegePage> {
  17. TextEditingController controller = new TextEditingController();
  18. Future<List<Privilege>> _getPrivileges() async {
  19. var data = await http
  20. .get("http://www.playnetworkafrica.com/public/api/privileges");
  21.  
  22. var jsonData = json.decode(data.body);
  23.  
  24. List<Privilege> privileges = [];
  25.  
  26. for (var u in jsonData) {
  27. Privilege privilege = Privilege(
  28. u["pid"], u["desc"], u["name"], u["code"], u["image"], u["type"]);
  29.  
  30. privileges.add(privilege);
  31. }
  32.  
  33. print(privileges.length);
  34.  
  35. return privileges;
  36. }
  37.  
  38. @override
  39. void initState() {
  40. super.initState();
  41.  
  42. _getPrivileges();
  43. }
  44.  
  45. onSearchTextChanged(String text) async {
  46. _searchResult.clear();
  47. if (text.isEmpty) {
  48. setState(() {});
  49. return;
  50. }
  51.  
  52. final privileges = await _getPrivileges();
  53. privileges.forEach((privilege) {
  54. if (privilege.name.contains(text)) _searchResult.add(privilege);
  55. });
  56.  
  57. setState(() {});
  58. }
  59.  
  60. List<Privilege> _searchResult = [];
  61.  
  62. @override
  63. Widget build(BuildContext context) {
  64. return Scaffold(
  65. appBar: PreferredSize(
  66. child: AppBar(
  67. title: Text(
  68. 'Privileges',
  69. style: TextStyle(
  70. fontSize: 30,
  71. ),
  72. ),
  73. backgroundColor: Colors.transparent,
  74. automaticallyImplyLeading: true,
  75. //`true` if you want Flutter to automatically add Back Button when needed,
  76. //or `false` if you want to force your own back button every where
  77. leading: IconButton(
  78. icon: Icon(Icons.arrow_back),
  79. onPressed: () {
  80. Navigator.push(
  81. context,
  82. MaterialPageRoute(builder: (context) => Navigation()),
  83. );
  84. },
  85. ),
  86. flexibleSpace: Column(
  87. children: <Widget>[
  88. SizedBox(
  89. height: 120,
  90. ),
  91. Row(
  92. mainAxisAlignment: MainAxisAlignment.center,
  93. children: <Widget>[
  94. Container(
  95. width: 330,
  96. height: 50,
  97. child: TextField(
  98. onChanged: onSearchTextChanged,
  99. controller: controller,
  100. decoration: InputDecoration(
  101. labelText: "Search",
  102. filled: true,
  103. fillColor: Colors.white,
  104. hintText: "Search",
  105. prefixIcon: Icon(Icons.search),
  106. border: OutlineInputBorder(
  107. borderRadius:
  108. BorderRadius.all(Radius.circular(25.0)))),
  109. ),
  110. ),
  111. ],
  112. ),
  113. ],
  114. ),
  115. ),
  116. preferredSize: Size.fromHeight(140.0),
  117. ),
  118. backgroundColor: Colors.black,
  119. body: FutureBuilder(
  120. future: _getPrivileges(),
  121. builder: (BuildContext context, AsyncSnapshot snapshot) {
  122. print(snapshot.data);
  123. if (snapshot.data == null) {
  124. return Container(
  125. child: Column(
  126. mainAxisAlignment: MainAxisAlignment.center,
  127. children: <Widget>[
  128. Center(
  129. child: CircularProgressIndicator(
  130. valueColor:
  131. AlwaysStoppedAnimation<Color>(Colors.orangeAccent),
  132. ),
  133. ),
  134. ],
  135. ));
  136. } else {
  137. return Column(
  138. children: <Widget>[
  139. new Expanded(
  140. child: _searchResult.length != 1 || controller.text.isNotEmpty
  141. ? new ListView.builder(
  142. itemCount: _searchResult.length,
  143. itemBuilder: (context, i) {
  144. return new Card(
  145. child: new RaisedButton(
  146. color: Colors.black,
  147. onPressed: () {
  148. Navigator.push(
  149. context,
  150. MaterialPageRoute(
  151. builder: (context) =>
  152. PrivilegeDetail(snapshot.data[i])),
  153. );
  154. },
  155. child: Stack(
  156. children: <Widget>[
  157. Image(
  158. image:
  159. NetworkImage(snapshot.data[i].image),
  160. width: 450,
  161. height: 250,
  162. gaplessPlayback: true,
  163. ),
  164. Padding(
  165. padding: EdgeInsets.fromLTRB(
  166. 0.0, 140.0, 0.0, 0.0),
  167. child: Center(
  168. child: ButtonTheme(
  169. minWidth: 80,
  170. height: 30,
  171. child: RaisedButton(
  172. color: Color(0xffc67608),
  173. shape: RoundedRectangleBorder(
  174. side: BorderSide(
  175. color: Color(0xffc67608),
  176. ),
  177. borderRadius: BorderRadius.all(
  178. Radius.circular(40.0),
  179. ),
  180. ),
  181. child: Text(snapshot.data[i].type),
  182. textColor: Colors.black,
  183. onPressed: () {
  184. Navigator.push(
  185. context,
  186. MaterialPageRoute(
  187. builder: (context) =>
  188. PrivilegeDetail(
  189. snapshot.data[i])),
  190. );
  191. },
  192. ),
  193. ),
  194. ),
  195. ),
  196. Padding(
  197. padding: const EdgeInsets.fromLTRB(
  198. 10.0, 180.0, 0.0, 0.0),
  199. child: Row(
  200. mainAxisAlignment:
  201. MainAxisAlignment.spaceBetween,
  202. children: <Widget>[
  203. Row(
  204. children: <Widget>[
  205. Text(
  206. snapshot.data[i].name,
  207. style: TextStyle(
  208. color: Colors.white,
  209. fontWeight: FontWeight.bold,
  210. fontSize: 17,
  211. ),
  212. ),
  213. ],
  214. ),
  215. ],
  216. ),
  217. ),
  218. Padding(
  219. padding: EdgeInsets.fromLTRB(
  220. 10.0, 230, 0.0, 0.0),
  221. child: Text(
  222. snapshot.data[i].desc,
  223. style: TextStyle(
  224. color: Colors.white,
  225. fontSize: 17,
  226. fontWeight: FontWeight.w200,
  227. ),
  228. ),
  229. ),
  230. ],
  231. ),
  232. ),
  233. margin: const EdgeInsets.all(0.0),
  234. );
  235. },
  236. )
  237. : ListView.builder(
  238. shrinkWrap: true,
  239. itemCount: snapshot.data.length,
  240. itemBuilder: (BuildContext context, int index) {
  241. return SingleChildScrollView(
  242. child: Center(
  243. child: SafeArea(
  244. child: Column(
  245. children: <Widget>[
  246. SizedBox(
  247. height: 40,
  248. ),
  249. RaisedButton(
  250. color: Colors.black,
  251. onPressed: () {
  252. Navigator.push(
  253. context,
  254. MaterialPageRoute(
  255. builder: (context) =>
  256. PrivilegeDetail(
  257. snapshot.data[index])),
  258. );
  259. },
  260. child: Stack(
  261. children: <Widget>[
  262. Image(
  263. image: NetworkImage(
  264. snapshot.data[index].image),
  265. width: 450,
  266. height: 250,
  267. gaplessPlayback: true,
  268. ),
  269. Padding(
  270. padding: EdgeInsets.fromLTRB(
  271. 0.0, 140.0, 0.0, 0.0),
  272. child: Center(
  273. child: ButtonTheme(
  274. minWidth: 80,
  275. height: 30,
  276. child: RaisedButton(
  277. color: Color(0xffc67608),
  278. shape:
  279. RoundedRectangleBorder(
  280. side: BorderSide(
  281. color:
  282. Color(0xffc67608),
  283. ),
  284. borderRadius:
  285. BorderRadius.all(
  286. Radius.circular(40.0),
  287. ),
  288. ),
  289. child: Text(snapshot
  290. .data[index].type),
  291. textColor: Colors.black,
  292. onPressed: () {
  293. Navigator.push(
  294. context,
  295. MaterialPageRoute(
  296. builder: (context) =>
  297. PrivilegeDetail(
  298. snapshot.data[
  299. index])),
  300. );
  301. },
  302. ),
  303. ),
  304. ),
  305. ),
  306. Padding(
  307. padding:
  308. const EdgeInsets.fromLTRB(
  309. 10.0, 180.0, 0.0, 0.0),
  310. child: Row(
  311. mainAxisAlignment:
  312. MainAxisAlignment
  313. .spaceBetween,
  314. children: <Widget>[
  315. Row(
  316. children: <Widget>[
  317. Text(
  318. snapshot
  319. .data[index].name,
  320. style: TextStyle(
  321. color: Colors.white,
  322. fontWeight:
  323. FontWeight.bold,
  324. fontSize: 17,
  325. ),
  326. ),
  327. ],
  328. ),
  329. ],
  330. ),
  331. ),
  332. Padding(
  333. padding: EdgeInsets.fromLTRB(
  334. 10.0, 230, 0.0, 0.0),
  335. child: Text(
  336. snapshot.data[index].desc,
  337. style: TextStyle(
  338. color: Colors.white,
  339. fontSize: 17,
  340. fontWeight: FontWeight.w200,
  341. ),
  342. ),
  343. ),
  344. ],
  345. ),
  346. ),
  347. SizedBox(
  348. height: 30,
  349. ),
  350. ],
  351. ),
  352. ),
  353. ),
  354. );
  355. },
  356. ),
  357. ),
  358. ],
  359. );
  360. }
  361. },
  362. ),
  363. bottomNavigationBar: BottomNavigationBar(
  364. type: BottomNavigationBarType.fixed,
  365. backgroundColor: Colors.black,
  366. items: <BottomNavigationBarItem>[
  367. BottomNavigationBarItem(
  368. backgroundColor: Colors.black,
  369. title: Text(''),
  370. icon: IconButton(
  371. icon: Icon(
  372. Icons.home,
  373. color: Colors.orangeAccent,
  374. ),
  375. onPressed: () {
  376. Navigator.push(
  377. context,
  378. MaterialPageRoute(builder: (context) => Navigation()),
  379. );
  380. },
  381. ),
  382. ),
  383. BottomNavigationBarItem(
  384. icon: IconButton(
  385. icon: Icon(
  386. Icons.vpn_lock,
  387. color: Colors.orangeAccent,
  388. ),
  389. onPressed: () {
  390. Navigator.push(
  391. context,
  392. MaterialPageRoute(builder: (context) => Meetup()),
  393. );
  394. },
  395. ),
  396. title: Text(''),
  397. ),
  398. BottomNavigationBarItem(
  399. icon: IconButton(
  400. icon: Icon(
  401. Icons.comment,
  402. color: Colors.orangeAccent,
  403. ),
  404. onPressed: () {
  405. Navigator.push(
  406. context,
  407. MaterialPageRoute(builder: (context) => Messages()),
  408. );
  409. },
  410. ),
  411. title: Text(''),
  412. ),
  413. BottomNavigationBarItem(
  414. icon: IconButton(
  415. icon: Icon(
  416. Icons.perm_identity,
  417. color: Colors.orangeAccent,
  418. ),
  419. onPressed: () {
  420. Navigator.push(
  421. context,
  422. MaterialPageRoute(builder: (context) => Profile()),
  423. );
  424. },
  425. ),
  426. title: Text(''),
  427. ),
  428. ],
  429. ),
  430. );
  431. }
  432. }
  433.  
  434. class PrivilegeDetail extends StatelessWidget {
  435. final Privilege privilege;
  436.  
  437. PrivilegeDetail(this.privilege);
  438.  
  439. void _showModalSheet(BuildContext context) {
  440. showModalBottomSheet(
  441. context: context,
  442. builder: (builder) {
  443. return Center(
  444. child: Column(
  445. children: <Widget>[
  446. Text(
  447. privilege.code,
  448. style: TextStyle(
  449. fontSize: 22,
  450. fontWeight: FontWeight.bold,
  451. color: Colors.black,
  452. ),
  453. ),
  454. Padding(
  455. padding: const EdgeInsets.all(40.0),
  456. child: Text(
  457. 'PLEASE DISPLAY THIS CODE TO AN APPROPIRATE STAFF TO APPLY YOUR DISCOUNT',
  458. textAlign: TextAlign.center,
  459. style: TextStyle(
  460. fontSize: 18,
  461. fontWeight: FontWeight.bold,
  462. color: Colors.black,
  463. ),
  464. ),
  465. ),
  466. ],
  467. ),
  468. );
  469. });
  470. }
  471.  
  472. @override
  473. Widget build(BuildContext context) {
  474. return Scaffold(
  475. appBar: AppBar(
  476. title: Text(
  477. privilege.name,
  478. style: TextStyle(
  479. fontSize: 22,
  480. fontWeight: FontWeight.bold,
  481. ),
  482. ),
  483. backgroundColor: Colors.black,
  484. automaticallyImplyLeading: true,
  485. //`true` if you want Flutter to automatically add Back Button when needed,
  486. //or `false` if you want to force your own back button every where
  487. leading: IconButton(
  488. icon: Icon(
  489. Icons.arrow_back,
  490. color: Colors.white,
  491. ),
  492. onPressed: () {
  493. Navigator.push(
  494. context,
  495. MaterialPageRoute(builder: (context) => PrivilegePage()),
  496. );
  497. },
  498. ),
  499. ),
  500. backgroundColor: Colors.black,
  501. body: SingleChildScrollView(
  502. child: Stack(
  503. children: <Widget>[
  504. Image(
  505. image: NetworkImage(privilege.image),
  506. width: 450,
  507. height: 250,
  508. ),
  509. Container(
  510. color: Colors.transparent,
  511. child: SafeArea(
  512. child: Padding(
  513. padding: const EdgeInsets.all(16.0),
  514. child: Column(
  515. crossAxisAlignment: CrossAxisAlignment.center,
  516. children: <Widget>[
  517. SizedBox(
  518. height: 200,
  519. ),
  520. Padding(
  521. padding: const EdgeInsets.fromLTRB(20.0, 0.0, 0.0, 0.0),
  522. child: Text(
  523. privilege.desc,
  524. style: TextStyle(
  525. color: Colors.white,
  526. fontSize: 18,
  527. ),
  528. ),
  529. ),
  530. SizedBox(
  531. height: 10,
  532. ),
  533. Container(
  534. color: Colors.black,
  535. child: Column(
  536. children: <Widget>[
  537. SizedBox(
  538. height: 50,
  539. ),
  540. Padding(
  541. padding: const EdgeInsets.fromLTRB(
  542. 10.0, 0.0, 20.0, 0.0),
  543. child: ButtonTheme(
  544. minWidth: 350.0,
  545. height: 60.0,
  546. child: RaisedButton(
  547. color: Color(0xffc67608),
  548. shape: RoundedRectangleBorder(
  549. side: BorderSide(
  550. color: Color(0xffc67608),
  551. ),
  552. borderRadius: BorderRadius.all(
  553. Radius.circular(10.0),
  554. ),
  555. ),
  556. child: Text("VIEW DISCOUNT"),
  557. textColor: Colors.white,
  558. onPressed: () => _showModalSheet(context),
  559. ),
  560. ),
  561. ),
  562. ],
  563. ),
  564. ),
  565. ],
  566. ),
  567. ),
  568. ),
  569. ),
  570. ],
  571. ),
  572. ),
  573. bottomNavigationBar: BottomNavigationBar(
  574. type: BottomNavigationBarType.fixed,
  575. backgroundColor: Colors.black,
  576. items: <BottomNavigationBarItem>[
  577. BottomNavigationBarItem(
  578. backgroundColor: Colors.black,
  579. title: Text(''),
  580. icon: IconButton(
  581. icon: Icon(
  582. Icons.home,
  583. color: Colors.orangeAccent,
  584. ),
  585. onPressed: () {
  586. Navigator.push(
  587. context,
  588. MaterialPageRoute(builder: (context) => Navigation()),
  589. );
  590. },
  591. ),
  592. ),
  593. BottomNavigationBarItem(
  594. icon: IconButton(
  595. icon: Icon(
  596. Icons.people,
  597. color: Colors.orangeAccent,
  598. ),
  599. onPressed: () {
  600. Navigator.push(
  601. context,
  602. MaterialPageRoute(builder: (context) => Meetup()),
  603. );
  604. },
  605. ),
  606. title: Text(''),
  607. ),
  608. BottomNavigationBarItem(
  609. icon: IconButton(
  610. icon: Icon(
  611. Icons.comment,
  612. color: Colors.orangeAccent,
  613. ),
  614. onPressed: () {
  615. Navigator.push(
  616. context,
  617. MaterialPageRoute(builder: (context) => Messages()),
  618. );
  619. },
  620. ),
  621. title: Text(''),
  622. ),
  623. BottomNavigationBarItem(
  624. icon: IconButton(
  625. icon: Icon(
  626. Icons.perm_identity,
  627. color: Colors.orangeAccent,
  628. ),
  629. onPressed: () {
  630. Navigator.push(
  631. context,
  632. MaterialPageRoute(builder: (context) => Profile()),
  633. );
  634. },
  635. ),
  636. title: Text(''),
  637. ),
  638. ],
  639. ),
  640. );
  641. }
  642. }
  643.  
  644. class Privilege {
  645. final int eid;
  646. final String desc;
  647. final String name;
  648. final String code;
  649. final String image;
  650. final String type;
  651.  
  652. Privilege(this.eid, this.desc, this.name, this.code, this.image, this.type);
  653. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement