颤音的形式步骤和滚动
我有形式和步进小部件的颤动视图。每个步进器都有很多小部件。当我单击步骤时,屏幕会自动滚动到新扩展的步骤的末尾。如何更改滚动以查看单击之后扩展的步骤的顶部?
(当我单击步骤2时,Step2扩展了,我从STEP2中看到了最后的小部件,而不是STEP2的第一个小部件)
代码:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
final String title;
const MyHomePage({
Key? key,
required this.title,
}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int currentStep = 0;
List<Step> generateSteps(int j) {
List<Step> a = [];
for (int i = 0; i < j; i++) {
a.add(Step(
title: const Text("STEP"),
content: Column(children: generateWidgets(10))));
}
return a;
}
List<Widget> generateWidgets(int j) {
List<Widget> a = [];
for (int i = 0; i < j; i++) {
a.addAll([
Text("Field: $i"),
TextFormField(
decoration: const InputDecoration(
hintText: 'Enter your email',
),
),
]);
}
return a;
}
@override
Widget build(BuildContext context) {
List<Step> ft = generateSteps(6);
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Form(
child: Stepper(
currentStep: currentStep,
onStepTapped: (int step) {
setState(() {
currentStep = step;
});
},
steps: ft,
physics: const NeverScrollableScrollPhysics(),
)),
),
);
}
}
I have Flutter view with Form and Stepper widgets. Every Stepper have a lot of widgets inside. When I click on Step, screen is automatically scrolling to the end of new expanded Step. How to change scrolling to see top of expanded Step after click on it?
(When I click on STEP 2, STEP2 is expanded and I see last widgets from STEP2, not first widgets of STEP2)
Code:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
final String title;
const MyHomePage({
Key? key,
required this.title,
}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int currentStep = 0;
List<Step> generateSteps(int j) {
List<Step> a = [];
for (int i = 0; i < j; i++) {
a.add(Step(
title: const Text("STEP"),
content: Column(children: generateWidgets(10))));
}
return a;
}
List<Widget> generateWidgets(int j) {
List<Widget> a = [];
for (int i = 0; i < j; i++) {
a.addAll([
Text("Field: $i"),
TextFormField(
decoration: const InputDecoration(
hintText: 'Enter your email',
),
),
]);
}
return a;
}
@override
Widget build(BuildContext context) {
List<Step> ft = generateSteps(6);
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Form(
child: Stepper(
currentStep: currentStep,
onStepTapped: (int step) {
setState(() {
currentStep = step;
});
},
steps: ft,
physics: const NeverScrollableScrollPhysics(),
)),
),
);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论