【发布时间】:2020-12-24 22:31:03
【问题描述】:
我的应用中有一个列表视图。当我单击项目时,如果项目有任何数据,我想要显示公司名称,如果没有数据,我想保存选定的项目并移至下一页。如果有数据我想打开我的卡并将其显示为列表。 (在同一页上) 我怎样才能得到它根据公司名称开卡?是否可以在 ONTAP 中添加新的小部件?
这是我的代码,
class _CountryScreenState extends State<CountryScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: Text('Please chose',style: TextStyle(fontWeight: FontWeight.bold,fontSize: 16),),
),
Expanded(
child: Center(
child: FutureBuilder<CountryList>(
future: fetchCountryList(),
builder: (BuildContext context, AsyncSnapshot<CountryList> snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data.data.length,
itemBuilder: (BuildContext context, int position) {
return Container(
height: 72,
padding: const EdgeInsets.all(10.0),
child: Card(
child: InkWell(
onTap: () async {
List<Company> companies= await fetchCompaniesList(snapshot.data.data[position].code);
Navigator.pushNamed(context, MainScreen.routeName);
},
child: Row(
children: [
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 8.0),
child: Image.asset(
'icons/flags/png/${snapshot.data.data[position].code.toLowerCase()}.png',
package: 'country_icons',
height: 20,
width: 34,
),
),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 8.0),
child: Text(snapshot.data.data[position].name,style: TextStyle(fontSize: 16),),
),
],
),
),
),
);
},
);
} else {
return CircularProgressIndicator();
}
},
),
),
),
],
),
);
}
}
【问题讨论】: