будущий компоновщик, работающий несколько раз и открывающий страницу одновременно.Как исправить эту ошибку?
Подкатегория StatefulWidget
class subCategory extends StatefulWidget {
final int RegId;
final int AssetId;
final String title;
final int ParentId;
final int equipmentId;
subCategory(this.RegId, this.AssetId, this.title, this.ParentId,this.equipmentId, {Key key})
: super(key: key);
@override
State<StatefulWidget> createState() => _mainCategory();
}
_mainCategory State Widget
class _mainCategory extends State<subCategory> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: submitRequestAppBar(context),
body: Scaffold(
appBar: AppBar(
backgroundColor: Colors.grey[350],
leading: Container(),
title: Text(
widget.title,
textAlign: TextAlign.left,
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black),),),
FutureBuilder внутри тела
body: FutureBuilder(
future: getRegister1(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
return Text('Press button to start.');
case ConnectionState.active:
case ConnectionState.waiting:
return waitingCircle();
case ConnectionState.done:
if (snapshot.hasError) return Text('Error: ${snapshot.error}');
if (snapshot.data.length == 0)
return noResultFound();
else
return createListView(context, snapshot); }
return null; // unreachable
},)),); }
CreateListView Widget
Widget createListView(BuildContext context, AsyncSnapshot snapshot) {
List<SubCategoryItem> values = snapshot.data;
возврат ListView
return ListView.builder(
padding: EdgeInsets.only(top: 8.0, right: 0.0, left: 0.0),
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
return GridView.count(
physics: ScrollPhysics(),
shrinkWrap: true,
crossAxisCount: 4,
children: List.generate(values.length, (index) {
return GridTile
return GridTile(
child: GestureDetector(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => WoDescription2(
widget.RegId,
widget.AssetId,
widget.ParentId,
values[index].childId,
false,
1,
widget.title,
widget.equipmentId))),
Виджет столбца
child: Column(
children: [
Card(
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.blueAccent, width: 1.5)),
child: Stack(
children: <Widget>[
Использование плагина flutter_svg для изображений svg
SvgPicture.asset('assets/images/Defect/icon-${values[index].childId}.svg',
height: 50.0,),],),), ),
Expanded(
child: Text(
'${values[index].description}',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 10.0),),),],),), ); }),); },);}
FutureBuider future: getRegister1
Future getRegister1() async {
List<SubCategoryItem> description = [];
List cat = [];
var catLocal = (await HelperDatabase1().displayDefCatRelation());
var defCatLocal = (await HelperDatabase1().display());
for (int i = 0; i < catLocal.length; i++) {
if (widget.RegId == catLocal[i].r &&
widget.AssetId == catLocal[i].t &&
widget.ParentId == catLocal[i].p) {
cat.add(catLocal[i].c);}}
for (int i = 0; i < cat.length; i++) {
for (int j = 0; j < defCatLocal.length; j++) {
if (cat[i] == defCatLocal[j].deF_CAT_ID) {
var oneItem = SubCategoryItem(
childId: defCatLocal[j].deF_CAT_ID,
description: defCatLocal[j].description);
await description.add(oneItem);}}}
return description;}}
SubCategoryItem class
class SubCategoryItem {
int childId;String description;
SubCategoryItem({this.childId, this.description});}