Флаттер: Степпер не прокручивает - PullRequest
0 голосов
/ 18 февраля 2019

Пытаюсь сделать кнопку ниже степпера.Проблема в том, что если я оберну его в Column или ListView, прокрутка в Stepper не будет работать.Я пытался обернуть их NestedScrollView, прокрутка работает, но проблема в том, что кнопка размещена над Stepper.В коде есть два примера _MyHomePageState, первый с ListView, а второй с NestedView, оба не работают для меня.Как я могу реализовать Stepper с кнопкой под ним?

Это то, что я хочу введите описание изображения здесь

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,
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Ответы [ 2 ]

0 голосов
/ 27 марта 2019

Все, что вам нужно, это добавить

physics: ClampingScrollPhysics(),

свойство внутри Stepper, поскольку Listview - это прокручиваемый виджет.

Надеюсь, это решит вашу проблему

0 голосов
/ 18 февраля 2019

Если кнопка должна быть постоянной в нижней части экрана, вы можете использовать свойство persistentFooterButtons виджета Scaffold или свойство bottomNavigationBar с пользовательским виджетом.

...