栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Flutter TreeView Json数据解析

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Flutter TreeView Json数据解析

我对自己的json数据使用了相同的包。在这里您可以找到用法示例。也许您可以对其进行调整以供使用。

import 'dart:convert';import 'package:flutter/material.dart';import 'package:tree_view/tree_view.dart';​void main() {  runApp(MyApp());}​class MyApp extends StatefulWidget {  @override  _MyAppState createState() => _MyAppState();}​class _MyAppState extends State<MyApp> {  @override  Widget build(BuildContext context) {    return MaterialApp(      title: 'title',      theme: ThemeData(        primarySwatch: Colors.blue,      ),      initialRoute: '/',      routes: {        '/': (context) => TestPage(),      },    );  }}​class TestPage extends StatefulWidget {  @override  _TestPageState createState() => _TestPageState();}​class _TestPageState extends State<TestPage> {  String responseBody =      '{ "id": 0,"name": "A","children": [{  "id": 1, "name": "Aa","children": [{"id": 2,"name": "Aa1","children": null}]},{ "id": 3, "name": "Ab","children": [{"id": 4,"name": "Ab1","children": null},{"id": 5,"name": "Ab2","children": null}]}]}';​  @override  Widget build(BuildContext context) {    Map mapBody = jsonDepre(responseBody);​    return SafeArea(      child: Scaffold(        body: printGroupTree(          mapBody,        ),      ),    );  }​  Widget printGroupTree(    Map group, {    double level = 0,  }) {    if (group['children'] != null) {      List<Widget> subGroups = List<Widget>();​      for (Map subGroup in group['children']) {        subGroups.add(          printGroupTree( subGroup, level: level + 1,          ),        );      }​      return Parent(        parent: _card(          group['name'],          level * 20,        ),        childList: ChildList(          children: subGroups,        ),      );    } else {      return _card(        group['name'],        level * 20,      );    }  }​  Widget _card(    String groupName,    double leftPadding,  ) {    return Container(      padding: EdgeInsets.only(        left: leftPadding + 5,        right: 20,      ),      decoration: BoxDecoration(        borderRadius: BorderRadius.circular(50.0),      ),      height: 100,      child: Row(        children: <Widget>[          Container( width: 250, child: Row(   children: <Widget>[     Container(       height: 70,       width: 70,       decoration: BoxDecoration(         shape: BoxShape.rectangle,         image: DecorationImage(fit: BoxFit.fill,image: NetworkImage(  'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a6/Rubik%27s_cube.svg/220px-Rubik%27s_cube.svg.png',),         ),       ),     ),     SizedBox(       width: 10,     ),     Flexible(       child: Text(         'SomeText',       ),     ),   ], ),          ),          Expanded( child: SizedBox(),          ),          InkWell( //TODO:Empty method here onTap: () {}, child: Icon(   Icons.group_add,   size: 40, ),          )        ],      ),    );  }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/377112.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号