gpt4 book ai didi

dart - 扩展列表下的Flutter ListTile

转载 作者:行者123 更新时间:2023-12-03 04:04:10 27 4
gpt4 key购买 nike

我目前有一个ExpansionTile,其中有一个包含ListTile的ListView.builder。

我正在做的任务是将多个listTiles放在一个Expansiontile下。

这是文件列表。dart

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'dart:async' show Future;
import 'package:flutter/services.dart' show rootBundle;
import 'dart:convert';
import 'package:emas_app/model/accounts_model.dart';


Future<String> _loadAsset() async{
return await rootBundle.loadString('Assets/accounts.json');
}

Future<Accounts> loadAccounts() async{

final response = await _loadAsset();
final jsonResponse = json.decode(response);

Accounts accounts = new Accounts.fromJson(jsonResponse);

return accounts;
}

class ProviderList extends StatefulWidget {

@override
ListState createState() {
return new ListState();
}
}

class ListState extends State<ProviderList> {

@override
Widget build(BuildContext context) {

Widget body = new FutureBuilder<Accounts>(
future: loadAccounts(),
builder: (context, snapshot){
if(snapshot.hasData){
return new ListView.builder(
itemCount: snapshot.data.accountinfo.length,
itemBuilder: (context,index){
return new Card(
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new ExpansionTile(
title: new Text("Johor"),
children: <Widget>[
new ListTile(
title: new Text("${snapshot.data.accountinfo[index].name}"),
)
]
),
],
),
);
});
}else{
return new Center(
child: new CircularProgressIndicator(),
);
}
});

return new Scaffold(
appBar: new AppBar(title: new Text("Providers")),
body: body
);
}
}

我当前面临的主要问题是ExpansionTile对每个新的ListTile不断重复。

Repeating "Johor" for each new ListTile

关于如何正确放置ExpansionTile的任何想法?

最佳答案

因为你建立

Card(
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new ExpansionTile(
title: new Text("Johor"),
children: <Widget>[
new ListTile(
title: new Text("${snapshot.data.accountinfo[index].name}"),
)
]
),
],

直到= snapshot.data.accountinfo.length

尝试仅创建具有该长度的ListTile,而不创建整个卡小部件

关于dart - 扩展列表下的Flutter ListTile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52162314/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com