【发布时间】:2021-02-05 05:42:59
【问题描述】:
我正在尝试为字母表中的每个字母制作一个页面。我需要从 JSON 中获取数据。所以我不必为每个字母定义一个类。
Row(
children: <Widget>[
Expanded(
child: Stack(
children: <Widget>[
Container(
margin: EdgeInsets.all(sizeY / 3 - 1),
height: sizeY,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
"assets/square-" + imgColor + "-big.png"),
fit: BoxFit.fitHeight)),
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Center(
child: Text(
this.letter + this.letter.toLowerCase(),
style: TextStyle(
color: Colors.white,
fontSize: 40.0,
fontFamily: 'ConcertOne',
fontWeight: FontWeight.normal),
textAlign: TextAlign.center,
),
),
),
),
],
),
),
Expanded(
child: Text(
this.shembulli1,
style: TextStyle(
color: Colors.pink,
fontWeight: FontWeight.bold,
fontSize: 30.0),
textAlign: TextAlign.center,
),
),
Expanded(
child: Container(
width: sizeY / 2,
height: sizeX / 2,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/" + shembulliImg1 + ".png"),
fit: BoxFit.contain)),
))
],
),
其中 shembulli1, shembulli2, shembulliImg1, shembulliImg2, letter 和 imgColor 必须来自 JSON,看起来像这样:
{
"shembulli1":"Bleta",
"shembulli2":"Biçikleta",
"shembulliImg1":"bee",
"shembulliImg2":"bike",
"letter":"B",
"imgColor":"blue"
},
{
"shembulli1":"Cicërima",
"shembulli2":"Certifikata",
"shembulliImg1":"bird",
"shembulliImg2":"letter",
"letter":"C",
"imgColor":"yellow"
},
【问题讨论】:
-
是的,您可以将 json 数据返回到任何内容中。
-
所有 Flutter 教程只展示了如何在 ListView 中从 json 返回数据,您对我如何正确解析数据有任何想法/示例吗?
标签: json flutter parsing dart mobile