Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 6.75 KB | None | 0 0
  1. import 'package:alarms/screens/site_screen_presenter.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:alarms/screens/controller_screen.dart';
  4.  
  5. class SiteHomeWidget extends StatefulWidget {
  6.   final String clientID;
  7.  
  8.   SiteHomeWidget({Key key, this.clientID}) : super(key: key);
  9.  
  10.   @override
  11.   State<StatefulWidget> createState() => _SiteScreenState();
  12. }
  13.  
  14. class _SiteScreenState extends State<SiteHomeWidget> {
  15.   SiteScreenPresenter _siteScreenPresenter = new SiteScreenPresenter();
  16.  
  17.   @override
  18.   Widget build(BuildContext context) {
  19.     String siteType;
  20.  
  21.     return Scaffold(
  22.       backgroundColor: Colors.lightBlueAccent,
  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.getSites(widget.clientID),
  28.           builder: (context, snapshot) {
  29.             switch (snapshot.connectionState) {
  30.  
  31.               ///when the future is null
  32.               case ConnectionState.none:
  33.                 return Text(
  34.                   'No Internet Connection',
  35.                   textAlign: TextAlign.left,
  36.                 );
  37.               case ConnectionState.active:
  38.  
  39.               ///when data is being fetched
  40.               case ConnectionState.waiting:
  41.                 return CircularProgressIndicator(
  42.                     valueColor: AlwaysStoppedAnimation<Color>(Colors.blue));
  43.               case ConnectionState.done:
  44.                 return ListView.builder(
  45.                   itemCount:
  46.                       snapshot.hasError ? 0 : snapshot.data.getObjLengthSite,
  47.                   itemBuilder: (context, index) {
  48.                     siteType = getSiteType(
  49.                         snapshot.data.getObj[index]["site_type_id"]);
  50.                     return InkWell(
  51.                       splashColor: Colors.blue.withAlpha(30),
  52.                       onTap: () => Navigator.of(context)
  53.                           .push(new MaterialPageRoute(builder: (context) {
  54.                         return new ControllerWidget(
  55.                           clientID: widget.clientID,
  56.                         );
  57.                       })),
  58.                       child: Card(
  59.                         elevation: 3,
  60.                         child: Container(
  61.                           height: 100.0,
  62.                           child: Row(
  63.                             children: <Widget>[
  64.                               Container(
  65.                                 height: 150.0,
  66.                                 width: 70.0,
  67.                                 decoration: BoxDecoration(
  68.                                     borderRadius: BorderRadius.only(
  69.                                         bottomLeft: Radius.circular(5),
  70.                                         topLeft: Radius.circular(5)),
  71.                                     image: DecorationImage(
  72.                                         fit: BoxFit.scaleDown,
  73.                                         image: AssetImage('assets/site.png'))),
  74.                               ),
  75.                               Container(
  76.                                 height: 100,
  77.                                 child: Padding(
  78.                                   padding: EdgeInsets.fromLTRB(10, 2, 0, 0),
  79.                                   child: Column(
  80.                                     crossAxisAlignment:
  81.                                         CrossAxisAlignment.start,
  82.                                     children: <Widget>[
  83.                                       Text(
  84.                                         snapshot.data.getObj[index]["name"],
  85.                                         style: TextStyle(
  86.                                             fontWeight: FontWeight.bold),
  87.                                       ),
  88.                                       Padding(
  89.                                         padding:
  90.                                             EdgeInsets.fromLTRB(0, 5, 0, 3),
  91.                                         child: Container(
  92.                                           // width: 100,
  93.                                           //padding: EdgeInsets.fromLTRB(3.0, 2.0, 3.0, 2.0),
  94. //                                          decoration: BoxDecoration(
  95. //                                              border: Border.all(color: Colors.white),
  96. //                                              borderRadius: BorderRadius.all(Radius.circular(10))
  97. //                                          ),
  98.                                           child: Text(
  99.                                             snapshot.data.getObj[index]
  100.                                                     ["address"]["street"] +
  101.                                                 ", " +
  102.                                                 snapshot.data.getObj[index]
  103.                                                     ["address"]["city"] +
  104.                                                 ", " +
  105.                                                 snapshot.data.getObj[index]
  106.                                                     ["address"]["state"],
  107.                                             textAlign: TextAlign.center,
  108.                                             style: TextStyle(fontSize: 12),
  109.                                           ),
  110.                                         ),
  111.                                       ),
  112.                                       Padding(
  113.                                         padding:
  114.                                             EdgeInsets.fromLTRB(0, 0, 0, 0),
  115.                                         child: Container(
  116.                                           width: 260,
  117.                                           child: Text(
  118.                                             "Site Type: " + siteType,
  119.                                             style: TextStyle(fontSize: 12),
  120.                                           ),
  121.                                         ),
  122.                                       )
  123.                                     ],
  124.                                   ),
  125.                                 ),
  126.                               )
  127.                             ],
  128.                           ),
  129.                         ),
  130.                       ),
  131.                     );
  132.                   },
  133.                 );
  134.             }
  135.             return CircularProgressIndicator();
  136.           },
  137.         ),
  138.       ),
  139.     );
  140.   }
  141.  
  142.   String getSiteType(String siteType) {
  143.     if (siteType == "1") return "BLANK";
  144.     if (siteType == "2") return "OPC UA";
  145.     if (siteType == "3") return "Legacy";
  146.     if (siteType == "4") return "BLANK";
  147.     if (siteType == "5") return "BLANK";
  148.     if (siteType == "6") return "WAMP";
  149.     return "IDK";
  150.   }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement