2017-07-14 91 views
0

我是新来Flutter,所以我试图进入它。但我一直在创建一个带有ExpansionPanels的ExpansionPanelList。就像标题中所说的那样,所有这一切都是在Google的Flutter中创建的。不能创建扩展面板列表中的项目在颤动

到目前为止我的代码:

import 'package:flutter/material.dart'; 


class ShoppingBasket extends StatefulWidget { 
    @override 
    ShoppingBasketState createState() => new ShoppingBasketState(); 
} 

class ShoppingBasketState extends State<ShoppingBasket> { 

    @override 
    Widget build(BuildContext context) { 
    return new ExpansionPanelList(
     children: <ExpansionPanel>[ 
     new ExpansionPanel(
      headerBuilder: _headerBuilder, 
      body: new Container(
      child: new Text("body"), 
     ), 
     ) 
     ], 
    ); 
    } 


    Widget _headerBuilder(BuildContext context, bool isExpanded) { 
    return new Text("headerBuilder"); 
    } 
} 

但是当我打开应用程序调试器说: 另一个异常被抛出:“包:扑/ src目录/渲染/ box.dart”:失败的断言:行1430 pos 12:'hasSize':不正确。

我搜索了很多,但我不能找到一种方法来帮助自己对不起:)

回答

1

这听起来像你需要把你的ExpansionPanelListListViewColumn或其他一些容器,不会迫使它成为一个特定的尺寸。

以下是扩展面板使用示例。

screenshot

import 'package:flutter/material.dart'; 

class ShoppingBasket extends StatefulWidget { 
    @override 
    ShoppingBasketState createState() => new ShoppingBasketState(); 
} 

class MyItem { 
    MyItem({ this.isExpanded: false, this.header, this.body }); 

    bool isExpanded; 
    final String header; 
    final String body; 
} 

class ShoppingBasketState extends State<ShoppingBasket> { 
    List<MyItem> _items = <MyItem>[ 
    new MyItem(header: 'header', body: 'body') 
    ]; 

    @override 
    Widget build(BuildContext context) { 
    return new ListView(
     children: [ 
     new ExpansionPanelList(
      expansionCallback: (int index, bool isExpanded) { 
      setState(() { 
       _items[index].isExpanded = !_items[index].isExpanded; 
      }); 
      }, 
      children: _items.map((MyItem item) { 
      return new ExpansionPanel(
       headerBuilder: (BuildContext context, bool isExpanded) { 
       return new Text(item.header); 
       }, 
       isExpanded: item.isExpanded, 
       body: new Container(
       child: new Text("body"), 
      ), 
      ); 
      }).toList(), 
     ), 
     ], 
    ); 
    } 
} 

void main() { 
    runApp(new MaterialApp(
    home: new Scaffold(
     appBar: new AppBar(
     title: new Text('ExpansionPanel Example'), 
    ), 
     body: new ShoppingBasket(), 
    ), 
)); 
} 

飞舞的画廊有一个更详细的expansion panels example

+0

谢谢你:) –