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
Flutter Flatter ListView不滚动(我觉得我已经尝试了互联网上的所有解决方案)_Flutter_Listview_Dart_Mobile - Fatal编程技术网

Flutter Flatter ListView不滚动(我觉得我已经尝试了互联网上的所有解决方案)

Flutter Flatter ListView不滚动(我觉得我已经尝试了互联网上的所有解决方案),flutter,listview,dart,mobile,Flutter,Listview,Dart,Mobile,如果我按住手指向下拖动,我可以看到屏幕截止线以下的一些项目,但一旦我放开,它就会反弹到顶部。我尝试过使用SingleChildScrollView位置,尝试过设置primary=true,以及其他一些没有帮助的东西。我是一个新手,所以任何帮助都将不胜感激!!如果需要更多信息,请告诉我 这是我的密码: import 'package:flutter/material.dart'; import 'package:drink_specials/models/restaurant.dart'; imp

如果我按住手指向下拖动,我可以看到屏幕截止线以下的一些项目,但一旦我放开,它就会反弹到顶部。我尝试过使用SingleChildScrollView位置,尝试过设置primary=true,以及其他一些没有帮助的东西。我是一个新手,所以任何帮助都将不胜感激!!如果需要更多信息,请告诉我

这是我的密码:

import 'package:flutter/material.dart';
import 'package:drink_specials/models/restaurant.dart';
import 'package:drink_specials/screens/home/restaurant_list.dart';

class RestaurantNameTextStyle {
  static TextStyle display5(BuildContext context) {
    return Theme.of(context).textTheme.headline2.copyWith(color: Colors.white);
  }
}

class RestaurantTypeTextStyle {
  static TextStyle display5(BuildContext context) {
    return Theme.of(context).textTheme.headline6.copyWith(color: Colors.white);
  }
}


class RestaurantDetail extends StatelessWidget {

  final Restaurant restaurant;
  RestaurantDetail({Key key, @required this.restaurant}) : super(key: key);

  @override
  Widget build(BuildContext context) {

    final topContentText = Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        SizedBox(height: 100.0),
        Text(
          restaurant.name,
          style: RestaurantNameTextStyle.display5(context),
        ),
        SizedBox(height: 10.0),
        Expanded(
            flex: 6,
            child: Padding(
                padding: EdgeInsets.only(left: 10.0),
                child: Text(
                  restaurant.restaurant_type,
                  style: RestaurantTypeTextStyle.display5(context),
                ))),
      ],
    );

    final topContent = Stack(
      children: <Widget>[
        Container(
            padding: EdgeInsets.only(left: 10.0),
            height: MediaQuery.of(context).size.height * 0.5,
            decoration: new BoxDecoration(
              image: new DecorationImage(
                image: NetworkImage(restaurant.photo),
                fit: BoxFit.cover,
              ),
            )),
        Container(
          height: MediaQuery.of(context).size.height * 0.5,
          padding: EdgeInsets.all(40.0),
          width: MediaQuery.of(context).size.width,
          decoration: BoxDecoration(color: Color.fromRGBO(58, 66, 86, .9)),
          child: Center(
            child: topContentText,
          ),
        ),
        Positioned(
          left: 8.0,
          top: 60.0,
          child: InkWell(
            onTap: () {
              Navigator.pop(context);
            },
            child: Icon(Icons.arrow_back, color: Colors.white),
          ),
        )
      ],
    );


    final bottomContent = Container(
      width: MediaQuery.of(context).size.width,
      padding: EdgeInsets.all(8.0),
      child: Center(
        child: ListView.builder(
          scrollDirection: Axis.vertical,
          physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
          itemCount: restaurant.specials.length,
          itemBuilder: (context, index) {
            final item = restaurant.specials[index];
            return Card(
              elevation: 8.0,
              margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
              child: Container(
                decoration: BoxDecoration(color: Color.fromRGBO(58, 66, 86, 1.0)),
                child: ListTile(
                  contentPadding: EdgeInsets.symmetric(horizontal:20, vertical:10),
                  title: Text(item, style: TextStyle(color: Colors.white)),
            )
                ),
            );
          }
        ),
      ),
    );

    return Scaffold(
      body: Column(
        children: <Widget>[
          topContent,
          Expanded(
            child: bottomContent,
          ),
        ],
      ),
    );
  }
}

导入“包装:颤振/材料.省道”;
进口“包装:饮料/特色/模特/餐厅.dart”;
进口“包装:饮料/特色菜/屏风/家庭/餐厅列表.dart”;
类RestaurantNameTextStyle{
静态文本样式显示5(构建上下文){
返回Theme.of(context).textTheme.headline2.copyWith(颜色:Colors.white);
}
}
类RestaurantTypeTextStyle{
静态文本样式显示5(构建上下文){
返回Theme.of(context).textTheme.headline6.copyWith(颜色:Colors.white);
}
}
类RestaurantDetail扩展了无状态小部件{
最终餐厅;
RestaurantDetail({Key-Key,@required this.restaurant}):super(Key:Key);
@凌驾
小部件构建(构建上下文){
最终topContentText=列(
crossAxisAlignment:crossAxisAlignment.center,
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
尺寸箱(高度:100.0),
正文(
餐厅名称,
样式:RestaurantNameTextStyle.display5(上下文),
),
尺寸箱(高度:10.0),
扩大(
弹性:6,
孩子:填充(
填充:仅限边缘设置(左:10.0),
子:文本(
餐厅,餐厅类型,
样式:RestaurantTypeTextStyle.display5(上下文),
))),
],
);
最终topContent=堆栈(
儿童:[
容器(
填充:仅限边缘设置(左:10.0),
高度:MediaQuery.of(上下文).size.height*0.5,
装饰:新盒子装饰(
图片:新装饰图片(
图片:NetworkImage(餐厅图片),
适合:BoxFit.cover,
),
)),
容器(
高度:MediaQuery.of(上下文).size.height*0.5,
填充:所有边缘设置(40.0),
宽度:MediaQuery.of(context).size.width,
装饰:盒子装饰(颜色:color.fromRGBO(58,66,86,9)),
儿童:中心(
child:topContentText,
),
),
定位(
左:8.0,
排名:60.0,
孩子:InkWell(
onTap:(){
Navigator.pop(上下文);
},
子:图标(Icons.arrow\u back,颜色:Colors.white),
),
)
],
);
最终含量=容器(
宽度:MediaQuery.of(context).size.width,
填充:边缘设置。全部(8.0),
儿童:中心(
子项:ListView.builder(
滚动方向:轴垂直,
物理:常量反弹滚动物理(父项:AlwaysScrollableScrollPhysics()),
物品计数:餐厅、特色菜、长度、,
itemBuilder:(上下文,索引){
最终项目=餐厅。特色菜[索引];
回程卡(
标高:8.0,
边距:新边集。对称(水平:10.0,垂直:6.0),
子:容器(
装饰:盒子装饰(颜色:color.fromRGBO(58,66,86,1.0)),
孩子:ListTile(
内容填充:边集。对称(水平:20,垂直:10),
标题:文本(项目,样式:TextStyle(颜色:Colors.white)),
)
),
);
}
),
),
);
返回脚手架(
正文:专栏(
儿童:[
顶级内容,
扩大(
孩子:我满足了,
),
],
),
);
}
}

SingleChildScrollView
中有一个
列表视图
,它们都是可滚动的。在其中一个屏幕上滚动应该被禁用。

正如他们已经解释的那样。如果您有一个ListView.builder,则不需要SingleChildScrollView。 尝试删除SingleChildScrollView。代码应该如下所示:

Scaffold(
  body: Column(
      children: <Widget>[
        topContent,
        Expanded(
            child: bottomContent,
        ),
      ],
  ),
);
脚手架(
正文:专栏(
儿童:[
顶级内容,
扩大(
孩子:我满足了,
),
],
),
);

列表视图
已经有了滚动行为,因此您不需要一些
单子女滚动视图

我认为列表视图上的primary=false会禁用滚动。。。我看现在不是这样。谢谢你的帮助,我觉得自己很笨:)我已经将代码块更新为功能代码