在flatter中从XML显示动态listview
我有这样的XML:在flatter中从XML显示动态listview,xml,flutter,Xml,Flutter,我有这样的XML: <root> <customers> <customer customerId='A001'> <name>Alex</name> <address>...</address> <photo>http://myserver/images/alex.png</photo> <cust
<root>
<customers>
<customer customerId='A001'>
<name>Alex</name>
<address>...</address>
<photo>http://myserver/images/alex.png</photo>
<customer>
<customer customerId='B001'>
<name>Bruce</name>
<address>...</address>
<photo>http://myserver/images/bruce.png</photo>
<customer>
...
</customers>
</root>
import 'package:xml/xml.dart' as xml;
如何将XML转换为列表数组并显示listview
谢谢您的帮助。使用
xml
软件包。从这样的导入开始:
<root>
<customers>
<customer customerId='A001'>
<name>Alex</name>
<address>...</address>
<photo>http://myserver/images/alex.png</photo>
<customer>
<customer customerId='B001'>
<name>Bruce</name>
<address>...</address>
<photo>http://myserver/images/bruce.png</photo>
<customer>
...
</customers>
</root>
import 'package:xml/xml.dart' as xml;
将响应解码为字符串,然后解析它并将其映射到所需的任何类型的小部件中。我刚刚举了一个最简单的文本的例子。您可以使用卡片、详细信息、图像等创建自己的复合小部件
xml.XmlDocument document = xml.parse(response);
List<Text> names = document
.findAllElements('customer')
.map<Text>((e) => Text(e.findElements('name').first.text))
.toList();
xml.XmlDocument document=xml.parse(响应);
列表名称=文档
.findallements(“客户”)
.map((e)=>Text(e.findElements('name').first.Text))
.toList();
使用列表视图中的小部件列表作为子项。使用xml
包。从这样的导入开始:
<root>
<customers>
<customer customerId='A001'>
<name>Alex</name>
<address>...</address>
<photo>http://myserver/images/alex.png</photo>
<customer>
<customer customerId='B001'>
<name>Bruce</name>
<address>...</address>
<photo>http://myserver/images/bruce.png</photo>
<customer>
...
</customers>
</root>
import 'package:xml/xml.dart' as xml;
将响应解码为字符串,然后解析它并将其映射到所需的任何类型的小部件中。我刚刚举了一个最简单的文本的例子。您可以使用卡片、详细信息、图像等创建自己的复合小部件
xml.XmlDocument document = xml.parse(response);
List<Text> names = document
.findAllElements('customer')
.map<Text>((e) => Text(e.findElements('name').first.text))
.toList();
xml.XmlDocument document=xml.parse(响应);
列表名称=文档
.findallements(“客户”)
.map((e)=>Text(e.findElements('name').first.Text))
.toList();
使用列表视图中的小部件列表作为子项