首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flutter: Stepper不滚动

Flutter: Stepper不滚动
EN

Stack Overflow用户
提问于 2019-02-19 03:05:32
回答 2查看 2.1K关注 0票数 0

我正在试着使一个按钮下面的步进器。问题是,如果我将它包装在一个列或ListView中,在Stepper中滚动不起作用。我试着用NestedScrollView来包装它们,滚动是有效的,但问题是上面的按钮张贴在Stepper上面。代码中有两个_MyHomePageState示例,第一个使用ListView,第二个使用NestedView,这两个示例都不适用于我。如何实现带有Button的Stepper?

这就是我想要的enter image description here

代码语言:javascript
复制
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

// 1 case with ListView (doesn't scroll)
class _MyHomePageState extends State<MyHomePage> {
  int _currentStep = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        iconTheme: IconThemeData(color: Colors.red),
      ),
      body: Form(
        child: ListView(
          children: <Widget>[
            Stepper(
              type: StepperType.vertical,
              currentStep: _currentStep,
              onStepTapped: (int index) {
                setState(() {
                  _currentStep = index;
                });
              },
              steps: [
                Step(
                  title: Text('Step 1'),
                  content: Column(
                    children: <Widget>[
                      TextFormField(
                        decoration: InputDecoration(
                            labelText: 'City', border: UnderlineInputBorder()),
                      ),
                      TextFormField(
                        decoration: InputDecoration(labelText: 'Name'),
                      ),
                      TextFormField(
                        decoration: InputDecoration(labelText: 'Address'),
                      ),
                    ],
                  ),
                  isActive: true,
                ),
                Step(
                  title: Text('Step 2'),
                  content: Column(
                    children: <Widget>[
                      TextFormField(
                        decoration: InputDecoration(labelText: 'City'),
                      ),
                      TextFormField(
                        decoration: InputDecoration(labelText: 'Name'),
                      ),
                      TextFormField(
                        decoration: InputDecoration(labelText: 'Address'),
                      ),
                    ],
                  ),
                  isActive: true,
                ),
                Step(
                  title: Text('Step 3'),
                  content: Column(
                    children: <Widget>[
                      TextFormField(
                        decoration: InputDecoration(labelText: 'Width'),
                      ),
                      TextFormField(
                        decoration: InputDecoration(labelText: 'Length'),
                      ),
                      TextFormField(
                        decoration: InputDecoration(labelText: 'Height'),
                      ),
                      TextFormField(
                        decoration: InputDecoration(labelText: 'Weigth'),
                      ),
                    ],
                  ),
                  isActive: true,
                ),
              ],
            ),
            RaisedButton(
              child: Text('Button'),
              onPressed: () {},
            )
          ],
        ),
      ),
    );
  }
} 

// 2 case with NestedScrollView
class _MyHomePageState extends State<MyHomePage> {
  int _currentStep = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        iconTheme: IconThemeData(color: Colors.red),
      ),
      body: Form(
        child: NestedScrollView(
          headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
            return <Widget>[
              SliverList(
                delegate: SliverChildListDelegate(<Widget>[
                  RaisedButton(
                    child: Text('Button'),
                    onPressed: () {},
                  )
                ]),
              ),
            ];
          },
          body: Stepper(
            type: StepperType.vertical,
            currentStep: _currentStep,
            onStepTapped: (int index) {
              setState(() {
                _currentStep = index;
              });
            },
            steps: [
              Step(
                title: Text('Step 1'),
                content: Column(
                  children: <Widget>[
                    TextFormField(
                      decoration: InputDecoration(
                          labelText: 'City', border: UnderlineInputBorder()),
                    ),
                    TextFormField(
                      decoration: InputDecoration(labelText: 'Name'),
                    ),
                    TextFormField(
                      decoration: InputDecoration(labelText: 'Address'),
                    ),
                  ],
                ),
                isActive: true,
              ),
              Step(
                title: Text('Step 2'),
                content: Column(
                  children: <Widget>[
                    TextFormField(
                      decoration: InputDecoration(labelText: 'City'),
                    ),
                    TextFormField(
                      decoration: InputDecoration(labelText: 'Name'),
                    ),
                    TextFormField(
                      decoration: InputDecoration(labelText: 'Address'),
                    ),
                  ],
                ),
                isActive: true,
              ),
              Step(
                title: Text('Step 3'),
                content: Column(
                  children: <Widget>[
                    TextFormField(
                      decoration: InputDecoration(labelText: 'Width'),
                    ),
                    TextFormField(
                      decoration: InputDecoration(labelText: 'Length'),
                    ),
                    TextFormField(
                      decoration: InputDecoration(labelText: 'Height'),
                    ),
                    TextFormField(
                      decoration: InputDecoration(labelText: 'Weigth'),
                    ),
                  ],
                ),
                isActive: true,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
EN

回答 2

Stack Overflow用户

发布于 2019-03-28 00:13:24

你需要做的就是添加

代码语言:javascript
复制
physics: ClampingScrollPhysics(),

属性,因为Listview是一个可滚动的小部件。

我希望它能解决你的问题

票数 6
EN

Stack Overflow用户

发布于 2019-02-19 03:34:09

如果按钮应该持续显示在屏幕底部,您可以使用Scaffold小部件的persistentFooterButtons属性,或者使用自定义小部件的bottomNavigationBar属性。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54753804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档