Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:alarms/screens/site_screen_presenter.dart';
- import 'package:flutter/material.dart';
- import 'package:alarms/screens/controller_screen.dart';
- class SiteHomeWidget extends StatefulWidget {
- final String clientID;
- SiteHomeWidget({Key key, this.clientID}) : super(key: key);
- @override
- State<StatefulWidget> createState() => _SiteScreenState();
- }
- class _SiteScreenState extends State<SiteHomeWidget> {
- SiteScreenPresenter _siteScreenPresenter = new SiteScreenPresenter();
- @override
- Widget build(BuildContext context) {
- String siteType;
- return Scaffold(
- backgroundColor: Colors.lightBlueAccent,
- body: Center(
- child: FutureBuilder(
- ///If future is null then API will not be called as soon as the screen
- ///loads. This can be used to make this Future Builder dependent
- future: _siteScreenPresenter.getSites(widget.clientID),
- builder: (context, snapshot) {
- switch (snapshot.connectionState) {
- ///when the future is null
- case ConnectionState.none:
- return Text(
- 'No Internet Connection',
- textAlign: TextAlign.left,
- );
- case ConnectionState.active:
- ///when data is being fetched
- case ConnectionState.waiting:
- return CircularProgressIndicator(
- valueColor: AlwaysStoppedAnimation<Color>(Colors.blue));
- case ConnectionState.done:
- return ListView.builder(
- itemCount:
- snapshot.hasError ? 0 : snapshot.data.getObjLengthSite,
- itemBuilder: (context, index) {
- siteType = getSiteType(
- snapshot.data.getObj[index]["site_type_id"]);
- return InkWell(
- splashColor: Colors.blue.withAlpha(30),
- onTap: () => Navigator.of(context)
- .push(new MaterialPageRoute(builder: (context) {
- return new ControllerWidget(
- clientID: widget.clientID,
- );
- })),
- child: Card(
- elevation: 3,
- child: Container(
- height: 100.0,
- child: Row(
- children: <Widget>[
- Container(
- height: 150.0,
- width: 70.0,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.only(
- bottomLeft: Radius.circular(5),
- topLeft: Radius.circular(5)),
- image: DecorationImage(
- fit: BoxFit.scaleDown,
- image: AssetImage('assets/site.png'))),
- ),
- Container(
- height: 100,
- child: Padding(
- padding: EdgeInsets.fromLTRB(10, 2, 0, 0),
- child: Column(
- crossAxisAlignment:
- CrossAxisAlignment.start,
- children: <Widget>[
- Text(
- snapshot.data.getObj[index]["name"],
- style: TextStyle(
- fontWeight: FontWeight.bold),
- ),
- Padding(
- padding:
- EdgeInsets.fromLTRB(0, 5, 0, 3),
- child: Container(
- // width: 100,
- //padding: EdgeInsets.fromLTRB(3.0, 2.0, 3.0, 2.0),
- // decoration: BoxDecoration(
- // border: Border.all(color: Colors.white),
- // borderRadius: BorderRadius.all(Radius.circular(10))
- // ),
- child: Text(
- snapshot.data.getObj[index]
- ["address"]["street"] +
- ", " +
- snapshot.data.getObj[index]
- ["address"]["city"] +
- ", " +
- snapshot.data.getObj[index]
- ["address"]["state"],
- textAlign: TextAlign.center,
- style: TextStyle(fontSize: 12),
- ),
- ),
- ),
- Padding(
- padding:
- EdgeInsets.fromLTRB(0, 0, 0, 0),
- child: Container(
- width: 260,
- child: Text(
- "Site Type: " + siteType,
- style: TextStyle(fontSize: 12),
- ),
- ),
- )
- ],
- ),
- ),
- )
- ],
- ),
- ),
- ),
- );
- },
- );
- }
- return CircularProgressIndicator();
- },
- ),
- ),
- );
- }
- String getSiteType(String siteType) {
- if (siteType == "1") return "BLANK";
- if (siteType == "2") return "OPC UA";
- if (siteType == "3") return "Legacy";
- if (siteType == "4") return "BLANK";
- if (siteType == "5") return "BLANK";
- if (siteType == "6") return "WAMP";
- return "IDK";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement