Flutter 颤振:步进电机不';滚动
我想做一个按钮波纹步进器。问题是,如果我将其包装在列或列表视图中,在Stepper中滚动将不起作用。我试图用NestedScrollView包装它们,滚动正在工作,但问题是按钮贴在了Stepper上面。代码中有两个_MyHomePageState示例,第一个是ListView,第二个是NestedView,这两个示例都不适用于我。我如何实现按钮下的步进器 这就是我想要的Flutter 颤振:步进电机不';滚动,flutter,stepper,Flutter,Stepper,我想做一个按钮波纹步进器。问题是,如果我将其包装在列或列表视图中,在Stepper中滚动将不起作用。我试图用NestedScrollView包装它们,滚动正在工作,但问题是按钮贴在了Stepper上面。代码中有两个_MyHomePageState示例,第一个是ListView,第二个是NestedView,这两个示例都不适用于我。我如何实现按钮下的步进器 这就是我想要的 导入“包装:颤振/材料.省道”; void main()=>runApp(MyApp()); 类MyApp扩展了无状态小部件
导入“包装:颤振/材料.省道”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(
主样本:颜色。蓝色,
),
主页:MyHomePage(标题:“颤振演示主页”),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
//带有ListView的1个案例(不滚动)
类_MyHomePageState扩展状态{
int _currentStep=0;
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
背景颜色:Colors.white,
iconTheme:IconThemeData(颜色:Colors.red),
),
正文:表格(
子:ListView(
儿童:[
步进机(
类型:StepperType.vertical,
currentStep:_currentStep,
onstep:(int索引){
设置状态(){
_currentStep=索引;
});
},
步骤:[
台阶(
标题:文本(“步骤1”),
内容:专栏(
儿童:[
TextFormField(
装饰:输入装饰(
labelText:“城市”,边框:UnderlineInputBorder()),
),
TextFormField(
装饰:输入装饰(标签文本:“名称”),
),
TextFormField(
装饰:输入装饰(标签文本:“地址”),
),
],
),
是的,
),
台阶(
标题:文本(“步骤2”),
内容:专栏(
儿童:[
TextFormField(
装饰:输入装饰(标签文本:“城市”),
),
TextFormField(
装饰:输入装饰(标签文本:“名称”),
),
TextFormField(
装饰:输入装饰(标签文本:“地址”),
),
],
),
是的,
),
台阶(
标题:文本(“步骤3”),
内容:专栏(
儿童:[
TextFormField(
装饰:输入装饰(标签文本:“宽度”),
),
TextFormField(
装饰:输入装饰(标签文本:“长度”),
),
TextFormField(
装饰:输入装饰(标签文本:“高度”),
),
TextFormField(
装饰:输入装饰(labelText:“Weigth”),
),
],
),
是的,
),
],
),
升起的按钮(
子项:文本(“按钮”),
按下:(){},
)
],
),
),
);
}
}
//2个带有嵌套滚动视图的案例
类_MyHomePageState扩展状态{
int _currentStep=0;
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
背景颜色:Colors.white,
iconTheme:IconThemeData(颜色:Colors.red),
),
正文:表格(
子:嵌套滚动视图(
headerSliverBuilder:(BuildContext上下文,boolInnerBoxIsCrolled){
返回[
银表(
委托:SliverChildListDelegate([
升起的按钮(
子项:文本(“按钮”),
按下:(){},
)
]),
),
];
},
机身:步进电机(
类型:StepperType.vertical,
currentStep:_currentStep,
onstep:(int索引){
设置状态(){
_currentStep=索引;
});
},
步骤:[
台阶(
标题:文本(“步骤1”),
内容:专栏(
儿童:[
TextFormField(
装饰:输入装饰(
labelText:“城市”,边框:UnderlineInputBorder()),
),
TextFormField(
装饰:输入装饰(标签文本:“名称”),
),
TextFormField(
装饰:输入装饰(标签文本:“地址”),
),
],
),
是的,
),
台阶(
标题:文本(“步骤2”),
内容:专栏(
儿童:[
TextFormField(
装饰:输入装饰(标签文本:“城市”),
),
TextFormField(
装饰:输入装饰(标签文本:“名称”),
),
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(),