Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 向ListView添加卡_Dart_Flutter - Fatal编程技术网

Dart 向ListView添加卡

Dart 向ListView添加卡,dart,flutter,Dart,Flutter,我正在尝试获取的列表,并尝试使用扩展的小部件,但出现了溢出错误 我的代码: new Expanded( child: StreamBuilder( stream: Firestore.instance.collection('baby').snapshots(), builder: (context, snapshot) { if (!snapshot.hasData) return const Text('Loadin

我正在尝试获取的列表,并尝试使用
扩展的
小部件,但出现了
溢出
错误

我的代码:

new Expanded(
      child: StreamBuilder(
          stream: Firestore.instance.collection('baby').snapshots(),
          builder: (context, snapshot) {
            if (!snapshot.hasData) return const Text('Loading...');
            return ListView.builder(
                itemCount: snapshot.data.documents.length,
                padding: const EdgeInsets.only(top: 10.0),
                itemExtent: 25.0,
                itemBuilder: (context, index) {
                  DocumentSnapshot ds = snapshot.data.documents[index];
                  return //Text(" ${ds['name']} ${ds['vote']}");
                    Card(
                      child: Expanded(
                        child: Column(
                          mainAxisSize: MainAxisSize.min,
                          children: <Widget>[
                            const ListTile(
                              leading: const Icon(Icons.album),
                              title: const Text('The Enchanted Nightingale'),
                              subtitle: const Text('Music by Julie Gable. Lyrics by Sidney Stein.'),
                            ),
                            new ButtonTheme.bar( // make buttons use the appropriate styles for cards
                              child: ButtonBar(
                                children: <Widget>[
                                   FlatButton(
                                    child: const Text('BUY TICKETS'),
                                    onPressed: () { /* ... */ },
                                  ),
                                   FlatButton(
                                    child: const Text('LISTEN'),
                                    onPressed: () { /* ... */ },
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                    ),
                    );
                });
          })),
新扩展(
孩子:StreamBuilder(
流:Firestore.instance.collection('baby').snapshots(),
生成器:(上下文,快照){
如果(!snapshot.hasData)返回常量文本('Loading…');
返回ListView.builder(
itemCount:snapshot.data.documents.length,
填充:仅限常量边集(顶部:10.0),
项目范围:25.0,
itemBuilder:(上下文,索引){
DocumentSnapshot ds=snapshot.data.documents[索引];
return//Text(${ds['name']}${ds['vote']});
卡片(
儿童:扩大(
子:列(
mainAxisSize:mainAxisSize.min,
儿童:[
常量列表(
前导:const图标(Icons.album),
标题:康斯特文本(“迷人的夜莺”),
字幕:康斯特文本(“朱莉·盖博的音乐,西德尼·斯坦的歌词”),
),
new ButtonTheme.bar(//使按钮对卡片使用适当的样式
孩子:巴顿巴(
儿童:[
扁平按钮(
孩子:const Text(‘买票’),
按下:(){/*…*/},
),
扁平按钮(
child:const Text('LISTEN'),
按下:(){/*…*/},
),
],
),
),
],
),
),
);
});
})),
我得到的错误是:
不正确地使用了ParentDataWidget。

完全错误:

正在执行热重新加载。。。 I/颤振(9119):══╡ WIDGETS库捕获到异常╞═══════════════════════════════════════════════════════════ I/flatter(9119):在构建DefaultTextStyle(debugLabel:(类似英语)时抛出以下断言 I/flatter(9119):body1.merge(blackMountainView body1),inherit:false,color:color(0xdd000000),family:Roboto, I/flatter(9119):尺寸:14.0,重量:400,基线:字母,装饰:textEdition.none,软包装:包装 I/颤振(9119):在箱宽处,溢出:剪辑): I/flatter(9119):不正确使用ParentDataWidget。 I/flatter(9119):扩展的小部件必须直接放在Flex小部件中。 I/flatter(9119):Expanded(无深度,flex:1,dirty)有一个flex祖先,但它们之间还有其他小部件: I/flatter(9119):InkFeatures-[GlobalKey 93e52墨水渲染器] I/颤振(9119):-CustomPaint I/颤振(9119):-物理形状(剪裁器:ShapeBorderClipper,标高:1.0,颜色:颜色(0xFFFFFF),阴影颜色: I/flatter(9119):颜色(0xff000000)) I/颤振(9119):-填充(填充:所有边缘集(4.0)) I/flatter(9119):-语义(容器:true,属性:semanticProperties,标签:null,值:null,提示:null) I/颤振(9119):-重新绘制边界-[] I/flatter(9119):-KeepAlive(KeepAlive:false) I/颤振(9119):-SliverFixedExtentList(代表:SliverChildBuilderDelegate#b334e(估计子计数:3)) I/颤振(9119):-狭缝填充(填充:边缘集(0.0,10.0,0.0,0.0)) I/flatter(9119):-视口(轴方向:向下,锚定:0.0,偏移:滚动位置和SingleContext#bebad(偏移: I/颤振(9119):0.0,范围:0.0..0.0,视口:380.0,可滚动状态,AlwaysScrollableScrollPhysics-> I/颤振(9119):夹持滚动物理,空闲滚动活动#7b3a8,滚动方向。空闲) I/flatter(9119):-IgnorePointer-[GlobalKey#4c7f9](忽略:false,忽略语义:false) I/flatter(9119):-语义(容器:false,属性:semanticProperties,标签:null,值:null,提示:null) I/flatter(9119):-侦听器(侦听器:[向下],行为:不透明) I/颤振(9119):\u手势语义学 I/颤振(9119):-_排除滚动语义-[GlobalKey#22165] I/颤振(9119):-重新绘制边界 I/颤振(9119):-CustomPaint I/颤振(9119):-重新绘制边界 I/颤振(9119):-扩展(flex:1)(这是一个不同于有问题的扩展) I/flatter(9119):这些小部件不能介于扩展和Flex之间。 I/Flatter(9119):违规扩展的父级的所有权链为: I/颤振(9119):默认文本样式← 动画默认文本样式← _InkFeatures-[GlobalKey#93e52墨水渲染器]← I/颤振(9119):通知侦听器← 定制油漆← _塑像颜料← 体形 I/颤振(9119):← _物质利益← 材料← 衬垫← ⋯ I/颤振(9119): ════════════════════════════════════════════════════════════════════════════════════════════════════ I/flatter(9119):引发了另一个异常:ParentDataWidget的使用不正确。 I/chatty(9119):uid=10096(com.example.app)线程3个相同的3行 I/flatter(9119):引发了另一个异常:ParentDataWidget的使用不正确

更新
这是我得到的输出屏幕:

如果我移除了import 'package:flutter/material.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'BabyModel.dart'; import 'BabyCard.dart'; void main() => runApp(MyApp( textInput: Text("Text Widget"), )); class MyApp extends StatefulWidget { final Widget textInput; MyApp({this.textInput}); @override State<StatefulWidget> createState() => MyAppState(); } class MyAppState extends State<MyApp> { bool checkBoxValue = false; @override Widget build(BuildContext ctxt) { return StreamBuilder( stream: Firestore.instance.collection('baby').snapshots(), builder: (_, AsyncSnapshot<QuerySnapshot> snapshot) { var documents = snapshot.data?.documents ?? []; var baby = documents.map((snapshot) => BabyData.from(snapshot)).toList(); return BabyPage(baby); }, ); } } class BabyPage extends StatefulWidget { final List<BabyData> allBaby; BabyPage(this.allBaby); @override State<StatefulWidget> createState() { return BabyPageState(); } } class BabyPageState extends State<BabyPage> { @override Widget build(BuildContext context) { // var filteredBaby = widget.allFish.where((BabyData data) { // data.name = 'Dana'; // }).toList(); return MaterialApp( home: SafeArea( child: Scaffold( body: Container( child: ListView.builder( itemCount: widget.allBaby.length, padding: const EdgeInsets.only(top: 10.0), itemBuilder: (context, index) { return BabyCard(widget.allBaby[index]); }) ), ))); } }
import 'package:cloud_firestore/cloud_firestore.dart';

class BabyData {
  final DocumentReference reference;
  String name;
  int vote;

  BabyData.data(this.reference,
      [this.name,
        this.vote]) {
    // Set these rather than using the default value because Firebase returns
    // null if the value is not specified.
    this.name ??= 'Frank';
    this.vote ??= 7;
  }

  factory BabyData.from(DocumentSnapshot document) => BabyData.data(
      document.reference,
      document.data['name'],
      document.data['vote']);

  void save() {
    reference.setData(toMap());
  }

  Map<String, dynamic> toMap() {
    return {
      'name': name,
      'vote': vote,
    };
  }
}
import 'package:flutter/material.dart';
import 'BabyModel.dart';

class BabyCard extends StatefulWidget {
  final BabyData baby;

  BabyCard(this.baby);

  @override
  State<StatefulWidget> createState() {
    return BabyCardState(baby);
  }
}

class BabyCardState extends State<BabyCard> {
  BabyData baby;
  String renderUrl;

  BabyCardState(this.baby);

  Widget get babyCard {
    return
      new Card(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            ListTile(
              leading: const Icon(Icons.album),
              title: Text('The ${baby.name} is having:'),
              subtitle: Text('${baby.vote} Votes.'),
            ),
            new ButtonTheme.bar( // make buttons use the appropriate styles for cards
              child: new ButtonBar(
                children: <Widget>[
                  new FlatButton(
                    child: const Text('Thumb up'),
                    onPressed: () { /* ... */ },
                  ),
                  new FlatButton(
                    child: const Text('Thumb down'),
                    onPressed: () { /* ... */ },
                  )]))]));
  }

  @override
  Widget build(BuildContext context) {
    return new Container(
          child:  babyCard,
        );
  }
}
ListView(
  children: <Widget>[
    Card(child: ListTile(title: Text('One-line ListTile'))),
    Card(
      child: ListTile(
        leading: FlutterLogo(),
        title: Text('One-line with leading widget'),
      ),
    ),
    Card(
      child: ListTile(
        title: Text('One-line with trailing widget'),
        trailing: Icon(Icons.more_vert),
      ),
    ),
    Card(
      child: ListTile(
        leading: FlutterLogo(),
        title: Text('One-line with both widgets'),
        trailing: Icon(Icons.more_vert),
      ),
    ),
    Card(
      child: ListTile(
        title: Text('One-line dense ListTile'),
        dense: true,
      ),
    ),
    Card(
      child: ListTile(
        leading: FlutterLogo(size: 56.0),
        title: Text('Two-line ListTile'),
        subtitle: Text('Here is a second line'),
        trailing: Icon(Icons.more_vert),
      ),
    ),
    Card(
      child: ListTile(
        leading: FlutterLogo(size: 72.0),
        title: Text('Three-line ListTile'),
        subtitle:
        Text('A sufficiently long subtitle warrants three lines.'),
        trailing: Icon(Icons.more_vert),
        isThreeLine: true,
      ),
    ),
    Card(
        child: InkWell(
          splashColor: Colors.blue.withAlpha(30),
          onTap: () {
            print('Card tapped.');
          },
          child: Container(
            width: 300,
            height: 100,
            child: Center(
              child: Text(
                'When tapped this Cards InkWell displays an ink splash that fills the entire card',
              ),
            ),
          ),
        )),
  ],
)