Data is displayed on a page and it's values are updated periodically by reading a web service endpoint with returns a JSON. I have everything working but can't seem to get my head around how to actually access/update the data after it's been received. As main.dart shows, 4 items are shown. I would have thought it would be possible to access the object DataItem directly from my decodeMain method (also attached as part of comms.dart). I'm scratching my head and would appreciate being pointed in the right direction. Thanks.
import 'package:flutter/material.dart';
import 'dart:async';
import 'comms.dart' as comms;
import 'types.dart' as userTypes;
import 'data_item.dart';
import 'data_item_detail.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context){
// comms update timer...
new Timer.periodic(new Duration(seconds:5), comms.doUpdate);
return new MaterialApp(
title: 'Mobile Data',
theme: new ThemeData(
primarySwatch: Colors.blue
),
home: new MainPage(title:"Main Window"),
routes: <String,WidgetBuilder>{
'/data_item_detail':(BuildContext context) => new DataItemDetail(),
}
);
}
}
class MainPage extends StatefulWidget{
final String title;
MainPage({Key key, this.title}) : super(key: key);
@override
_MainPageState createState() => new _MainPageState();
}
class _MainPageState extends State<MainPage>{
@override
Widget build(BuildContext context){
// declare tags..
var tags = []
..add(new userTypes.Tag('[MobileTest]Main Pump/Pressure','Main Pump Pressure',0.0,'PSI',false))
..add(new userTypes.Tag('[MobileTest]Main Pump/Rate','Main Pump Rate',0.0,'PSI',false))
..add(new userTypes.Tag('[MobileTest]Booster Pump/Pressure','Booster Pump Pressure',0.0,'GPM',false))
..add(new userTypes.Tag('[MobileTest]Booster Pump/Rate','Booster Pump Rate',0.0,'GPM',false));
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
backgroundColor: Colors.blue,
),
body: new Padding(
padding: new EdgeInsets.all(20.0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new DataItem(tag:tags[0],color:Colors.blueAccent),
new DataItem(tag:tags[1],color:Colors.blueAccent),
new DataItem(tag:tags[2],color:Colors.blueAccent),
new DataItem(tag:tags[3],color:Colors.blueAccent),
],
)
)
);
}
}