gpt4 book ai didi

Flutter:步进器不滚动

转载 作者:IT王子 更新时间:2023-10-29 07:22:49 25 4
gpt4 key购买 nike

我正在尝试在 Stepper 下方制作一个按钮。问题是,如果我将它包装在 Column 或 ListView 中,则在 Stepper 中滚动不起作用。我试图用 NestedScrollView 包装它们,滚动工作正常,但问题是按钮发布在 Stepper 上方。代码中有两个 _MyHomePageState 示例,第一个是 ListView,第二个是 NestedView,两者都不适合我。如何在其下实现带有 Button 的 Stepper?

这就是我想要的 enter image description here

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

最佳答案

你只需要添加

physics: ClampingScrollPhysics(),

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

希望能解决你的问题

关于Flutter:步进器不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54753804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com