2017-07-14 93 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

謝謝你:) –