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 当滚动方向为水平时,如何显示ListView的设置中间子级?_Flutter_Flutter Layout - Fatal编程技术网

Flutter 当滚动方向为水平时,如何显示ListView的设置中间子级?

Flutter 当滚动方向为水平时,如何显示ListView的设置中间子级?,flutter,flutter-layout,Flutter,Flutter Layout,所以,我试图展示定价卡 其中的想法是水平滚动显示它们,所以我使用listView并设置滚动方向:Axis.horizontal但是, 现在,当它开始渲染时,它显示第一个孩子处于一个奇怪的位置 所以,我试着在屏幕上显示中间的孩子,而不是第一个。如图所示: 另外,是否可以为ListView中的子项添加更多边距?或者其他任何方式 以下是我的代码: Container _priceCard() { return Container( margin: new EdgeInsets.o

所以,我试图展示定价卡

其中的想法是水平滚动显示它们,所以我使用listView并设置
滚动方向:Axis.horizontal
但是, 现在,当它开始渲染时,它显示第一个孩子处于一个奇怪的位置

所以,我试着在屏幕上显示中间的孩子,而不是第一个。如图所示:

另外,是否可以为ListView中的子项添加更多边距?或者其他任何方式

以下是我的代码:

Container _priceCard() {
    return Container(
      margin: new EdgeInsets.only(top: 35),
      height: 480,
      child: ListView(
        shrinkWrap: true,
        scrollDirection: Axis.horizontal,
        children: <Widget>[
          Card(
            child: InkWell(
              // splashColor: Colors.blue.withAlpha(30),
              onTap: () {
                print('Card tapped.');
              },
              child: Container(
                width: 300,
                height: 450,
                padding: new EdgeInsets.all(30),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text(
                      '3 month Test Pass',
                      style:
                          TextStyle(fontSize: 23, fontWeight: FontWeight.bold),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 10),
                      child: Text(
                        '50% off for early Birds',
                        style: TextStyle(color: Colors.black54, fontSize: 16),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 40),
                      child: Text(
                        'INR 49/month',
                        style: TextStyle(
                            fontSize: 21, fontWeight: FontWeight.bold),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 7),
                      child: Text(
                        'INR 147 for 90 days',
                        style: TextStyle(
                            color: Colors.black54,
                            fontSize: 16,
                            fontWeight: FontWeight.bold),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 30),
                      child: Text(
                        'New live exam every Monday',
                        style: TextStyle(
                          color: Colors.black87,
                          fontSize: 16,
                        ),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 15),
                      child: Text(
                        'Unlimited practise tests series',
                        style: TextStyle(
                          color: Colors.black87,
                          fontSize: 16,
                        ),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 15),
                      child: Text(
                        'Paper tailored by AI for you',
                        style: TextStyle(
                          color: Colors.black87,
                          fontSize: 16,
                        ),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 15),
                      child: Text(
                        'Solved previous year questions',
                        style: TextStyle(
                          color: Colors.black87,
                          fontSize: 16,
                        ),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 35),
                      child: RaisedButton(
                        padding: const EdgeInsets.only(
                            top: 10, bottom: 10, left: 40, right: 40),
                        textColor: Colors.black,
                        color: Colors.green,
                        child: Text(
                          'Buy Now',
                          style: TextStyle(fontSize: 20),
                        ),
                        onPressed: null,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
          Card(
            child: InkWell(
              // splashColor: Colors.blue.withAlpha(30),
              onTap: () {
                print('Card tapped.');
              },
              child: Container(
                width: 300,
                height: 450,
                padding: new EdgeInsets.all(30),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text(
                      '3 month Test Pass',
                      style:
                          TextStyle(fontSize: 23, fontWeight: FontWeight.bold),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 10),
                      child: Text(
                        '50% off for early Birds',
                        style: TextStyle(color: Colors.black54, fontSize: 16),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 40),
                      child: Text(
                        'INR 49/month',
                        style: TextStyle(
                            fontSize: 21, fontWeight: FontWeight.bold),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 7),
                      child: Text(
                        'INR 147 for 90 days',
                        style: TextStyle(
                            color: Colors.black54,
                            fontSize: 16,
                            fontWeight: FontWeight.bold),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 30),
                      child: Text(
                        'New live exam every Monday',
                        style: TextStyle(
                          color: Colors.black87,
                          fontSize: 16,
                        ),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 15),
                      child: Text(
                        'Unlimited practise tests series',
                        style: TextStyle(
                          color: Colors.black87,
                          fontSize: 16,
                        ),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 15),
                      child: Text(
                        'Paper tailored by AI for you',
                        style: TextStyle(
                          color: Colors.black87,
                          fontSize: 16,
                        ),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 15),
                      child: Text(
                        'Solved previous year questions',
                        style: TextStyle(
                          color: Colors.black87,
                          fontSize: 16,
                        ),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 35),
                      child: RaisedButton(
                        padding: const EdgeInsets.only(
                            top: 10, bottom: 10, left: 40, right: 40),
                        textColor: Colors.black,
                        color: Colors.green,
                        child: Text(
                          'Buy Now',
                          style: TextStyle(fontSize: 20),
                        ),
                        onPressed: null,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
          Card(
            child: InkWell(
              // splashColor: Colors.blue.withAlpha(30),
              onTap: () {
                print('Card tapped.');
              },
              child: Container(
                width: 300,
                height: 450,
                padding: new EdgeInsets.all(30),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text(
                      '3 month Test Pass',
                      style:
                          TextStyle(fontSize: 23, fontWeight: FontWeight.bold),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 10),
                      child: Text(
                        '50% off for early Birds',
                        style: TextStyle(color: Colors.black54, fontSize: 16),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 40),
                      child: Text(
                        'INR 49/month',
                        style: TextStyle(
                            fontSize: 21, fontWeight: FontWeight.bold),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 7),
                      child: Text(
                        'INR 147 for 90 days',
                        style: TextStyle(
                            color: Colors.black54,
                            fontSize: 16,
                            fontWeight: FontWeight.bold),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 30),
                      child: Text(
                        'New live exam every Monday',
                        style: TextStyle(
                          color: Colors.black87,
                          fontSize: 16,
                        ),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 15),
                      child: Text(
                        'Unlimited practise tests series',
                        style: TextStyle(
                          color: Colors.black87,
                          fontSize: 16,
                        ),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 15),
                      child: Text(
                        'Paper tailored by AI for you',
                        style: TextStyle(
                          color: Colors.black87,
                          fontSize: 16,
                        ),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 15),
                      child: Text(
                        'Solved previous year questions',
                        style: TextStyle(
                          color: Colors.black87,
                          fontSize: 16,
                        ),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(top: 35),
                      child: RaisedButton(
                        padding: const EdgeInsets.only(
                            top: 10, bottom: 10, left: 40, right: 40),
                        textColor: Colors.black,
                        color: Colors.green,
                        child: Text(
                          'Buy Now',
                          style: TextStyle(fontSize: 20),
                        ),
                        onPressed: null,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
Container\u priceCard(){
返回容器(
边距:仅限新边集(顶部:35),
身高:480,
子:ListView(
收缩膜:对,
滚动方向:轴水平,
儿童:[
卡片(
孩子:InkWell(
//飞溅颜色:颜色。蓝色。带有alpha(30),
onTap:(){
打印(点击卡片);
},
子:容器(
宽度:300,
身高:450,
填充:新的边缘设置。全部(30),
子:列(
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
正文(
“3个月测试合格”,
风格:
TextStyle(fontSize:23,fontWeight:fontWeight.bold),
),
容器(
边距:仅限新边集(前10名),
子:文本(
“早起鸟五折”,
样式:TextStyle(颜色:Colors.black54,字体大小:16),
),
),
容器(
边距:仅限新边集(顶部:40),
子:文本(
“49卢比/月”,
样式:TextStyle(
fontSize:21,fontWeight:fontWeight.bold),
),
),
容器(
边距:仅限新边集(顶部:7),
子:文本(
“147卢比,为期90天”,
样式:TextStyle(
颜色:颜色。黑色54,
尺寸:16,
fontWeight:fontWeight.bold),
),
),
容器(
边距:仅限新边集(顶部:30),
子:文本(
“每周一新的现场考试”,
样式:TextStyle(
颜色:颜色。黑色87,
尺寸:16,
),
),
),
容器(
边距:仅限新边集(顶部:15),
子:文本(
"无限实践测试系列",,
样式:TextStyle(
颜色:颜色。黑色87,
尺寸:16,
),
),
),
容器(
边距:仅限新边集(顶部:15),
子:文本(
“AI为您量身定制的纸张”,
样式:TextStyle(
颜色:颜色。黑色87,
尺寸:16,
),
),
),
容器(
边距:仅限新边集(顶部:15),
子:文本(
“解决了上一年的问题”,
样式:TextStyle(
颜色:颜色。黑色87,
尺寸:16,
),
),
),
容器(
边距:仅限新边集(顶部:35),
孩子:升起按钮(
填充:仅限常量边设置(
顶部:10,底部:10,左侧:40,右侧:40),
textColor:Colors.black,
颜色:颜色。绿色,
子:文本(
“立即购买”,
样式:TextStyle(字体大小:20),
),
onPressed:null,
),
),
],
),
),
),
),
卡片(
孩子:InkWell(
//飞溅颜色:颜色。蓝色。带有alpha(30),
onTap:(){
打印(点击卡片);
},
子:容器(
宽度:300,
身高:450,
填充:新的边缘设置。全部(30),
子:列(
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
正文(
“3个月测试合格”,
风格:
TextStyle(fontSize:23,fontWeight:fontWeight.bold),
),
容器(
边距:仅限新边集(前10名),
子:文本(
“早起鸟五折”,
样式:TextStyle(颜色:Colors.black54,字体大小:16),
),
),
容器(
边距:仅限新边集(顶部:40),
子:文本(
“49卢比/月”,
样式:TextStyle(
fontSize:21,fontWeight:fontWeight.bold),
),
class SO extends StatefulWidget {
  @override
  _SOState createState() => _SOState();
}

class _SOState extends State<SO> {
  var colors = [Colors.red, Colors.pink, Colors.yellow, Colors.green];
  PageController _controller;

  @override
  void initState() {
    super.initState();
    _controller = PageController(viewportFraction: .9,initialPage: 1);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      backgroundColor: Colors.blue,
      body: PageView.builder(
        controller: _controller,
        itemCount: colors.length,
        itemBuilder: (BuildContext context, int index) {
          return Container(
            margin: EdgeInsets.symmetric(horizontal: 8, vertical: 8),
            child: Card(
              color: colors[index],
            ),
          );
        },
      ),
    );
  }
}