· 6 years ago · Oct 16, 2019, 01:52 PM
1import 'package:alarms/screens/site_screen_presenter.dart';
2import 'package:alarms/utils/sharedpreferences.dart';
3import 'package:flutter/material.dart';
4import 'package:alarms/screens/controller_screen.dart';
5import 'package:shared_preferences/shared_preferences.dart';
6
7class SiteHomeWidget extends StatefulWidget {
8 final String clientID;
9
10 SiteHomeWidget({Key key, this.clientID}) : super(key: key);
11
12 @override
13 State<StatefulWidget> createState() => _SiteScreenState();
14}
15
16class _SiteScreenState extends State<SiteHomeWidget> {
17 SiteScreenPresenter _siteScreenPresenter = new SiteScreenPresenter();
18
19
20 @override
21 Widget build(BuildContext context) {
22 return Scaffold(
23 body: Center(
24 child: FutureBuilder(
25 ///If future is null then API will not be called as soon as the screen
26 ///loads. This can be used to make this Future Builder dependent
27 future: _siteScreenPresenter
28 .getSites(widget.clientID), //TODO: MAKE THIS NUMBER DYNAMIC
29 builder: (context, snapshot) {
30 switch (snapshot.connectionState) {
31
32 ///when the future is null
33 case ConnectionState.none:
34 return Text(
35 'No Internet Connection',
36 textAlign: TextAlign.left,
37 );
38 case ConnectionState.active:
39
40 ///when data is being fetched
41 case ConnectionState.waiting:
42 return CircularProgressIndicator(
43 valueColor: AlwaysStoppedAnimation<Color>(Colors.blue));
44 case ConnectionState.done:
45 return ListView.builder(
46 itemCount:
47 snapshot.hasError ? 0 : snapshot.data.getObjLengthSite,
48 itemBuilder: (context, index) {
49 return InkWell(
50 splashColor: Colors.blue.withAlpha(30),
51 onTap: () => Navigator.of(context).push(
52 new MaterialPageRoute(builder: (context){
53 return new ControllerWidget();})),
54 child: Card(
55 elevation: 3,
56 child: Container(
57 height: 100.0,
58 child: Row(
59 children: <Widget>[
60 Container(
61 height: 150.0,
62 width: 70.0,
63 decoration: BoxDecoration(
64 borderRadius: BorderRadius.only(
65 bottomLeft: Radius.circular(5),
66 topLeft: Radius.circular(5)
67 ),
68 image: DecorationImage(
69 fit: BoxFit.cover,
70 image: AssetImage('assets/login_background.jpg')
71 )
72 ),
73 ),
74 Container(
75 height: 100,
76 child: Padding(
77 padding: EdgeInsets.fromLTRB(10, 2, 0, 0),
78 child: Column(
79 crossAxisAlignment: CrossAxisAlignment.start,
80 children: <Widget>[
81 Text(
82 snapshot.data.getObj[index]["name"],
83 ),
84 Padding(
85 padding: EdgeInsets.fromLTRB(0, 3, 0, 3),
86 child: Container(
87 // width: 100,
88 //padding: EdgeInsets.fromLTRB(3.0, 2.0, 3.0, 2.0),
89// decoration: BoxDecoration(
90// border: Border.all(color: Colors.white),
91// borderRadius: BorderRadius.all(Radius.circular(10))
92// ),
93 child: Text("Huston, Tx",textAlign: TextAlign.center,),
94 ),
95 ),
96 Padding(
97 padding: EdgeInsets.fromLTRB(0, 10, 0, 2),
98 child: Container(
99 width: 260,
100 //TODO: MAKE THIS DYNAMIC
101 child: Text("Placement holder Text",style: TextStyle(
102 fontSize: 15,
103 color: Color.fromARGB(255, 48, 48, 54)
104 ),),
105 ),
106 )
107 ],
108 ),
109 ),
110 )
111 ],
112 ),
113 ),
114 ),
115 );
116 },
117 );
118 }
119 return CircularProgressIndicator();
120 },
121 ),
122 ),
123 );
124 }
125
126
127}