我建立了一个使用statefulwidget作为图块的列表视图。一切都很好,除了在我调用setState时平铺中的按钮不重建的问题。
我在其中一个磁贴中也有一个editfield,它有一个texteditcontroller,当我单击按钮甚至不使用setstate时,它都可以正常工作。我可以用钥匙或类似的东西做类似的事情吗?以下是我的设置的示例代码。这是更大代码的非常简单的版本。
class FeedContent extends StatefulWidget {
@override
State<StatefulWidget> createState() => FeedContentState();
}
class FeedContentState extends State<FeedContent>{
@override
Widget build(BuildContext context) {
return new Scaffold(
body: RefreshIndicator(
key: _refreshIndicatorKey,
onRefresh: _refresh,
child: Stack(
// fit: StackFit.expand,
children: <Widget>[
Container(
color: Colors.grey[200],
padding: EdgeInsets.only(top: 0.0, left: 7.0, right:7.0, bottom: 0.0),
child: FutureBuilder(
future: fetchFeedData(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if(snapshot.data == null){
return Container(
child: Center(
child: Text(
"Loading....",
),
),
);
}else{
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, index) {
return Container(
child: ListTileGenerator(
feeddata: snapshot.data,
feedindex: index,
)
);
},
);
}
},
),
),
],
),
),
);
}
}
class ListTileGenerator extends StatefulWidget{
ListTileGenerator({this.feeddata, this.feedindex});
final List feeddata;
final int feedindex;
@override
State<StatefulWidget> createState() => ListTileGeneratorState();
}
class ListTileGeneratorState extends State<ListTileGenerator>{
Color goBtn;
@override
void initState() {
goBtn = Color(0xFF3489D8);
super.initState();
}
@override
Widget build(BuildContext context){
return setTile();
}
Widget setTile(){
return GestureDetector(
child: Container(
width: 40.0,
height: 40.0,
margin: EdgeInsets.only(left: 15.0),
decoration: BoxDecoration(
color: goBtn,
shape: BoxShape.circle,
),
child: Align(
alignment: Alignment.center,
child: Text("Go",
style: TextStyle(color: Colors.white, fontWeight: FontWeight.w700),
textAlign: TextAlign.center,
),
),
),
onTap: (){
//this is working and removing text from a textedit
textUpateController.clear();
this.setState((){
print("set state called on: ${setState.toString()}");
goBtn = Colors.red;
});
},
);
}
}