I have a StatefulWidget along with it's associated state. I'd like to be able to change it's value and call setSate for the widget's state. However, from the StatefulWidget definition I can't figure out how to call setState. This custom widget is intended to be nested in other widgets like a ListView. Any help would be appreciated.
import 'package:flutter/material.dart';
import 'types.dart' as userTypes;
final _rowHeight = 50.0;
final _borderRadius = BorderRadius.horizontal(left:Radius.zero,right:Radius.zero );
final _fontSize = 20.0;
class DataItem extends StatefulWidget {
final Color color;
final userTypes.Tag tag;
DataItem({
Key, key,
@required this.tag,
@required this.color,
}): assert(tag != null),
assert(color != null),
super(key:key);
@override
DataItemState createState() => new DataItemState(tag,color);
}
class DataItemState extends State<DataItem>{
userTypes.Tag tag;
final Color color;
DataItemState(this.tag,this.color);
// set tag(userTypes.Tag newValue){
// setState(() {
// tag = newValue;
// print ("setState tag");
// });
// }
@override
Widget build(BuildContext context){
return new Container(
height: _rowHeight,
child: InkWell(
borderRadius: _borderRadius,
highlightColor: color,
splashColor: color,
onTap: () {
print("I was tapped " + tag.tagPath);
},
child: Padding(
padding: EdgeInsets.all(4.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: Text(
this.tag.label,
style: new TextStyle(fontSize: _fontSize),
),
),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Text(
tag.value.toStringAsFixed(2) + " "+ tag.units,
style: new TextStyle(fontSize: _fontSize),
)
),
),
]
)
),
)
);
}
}