您可以尝试使用参数传递参数,并使用命名的路由调用将其发送到导航器,请参见烹饪书上的示例:
https://flutter.dev/docs/cookbook/navigation/navigate-with-arguments
1)在第二个屏幕中,您必须像这样创建ScreenArguments类:
class ScreenArguments {
final String email;
final String password;
ScreenArguments(this.email,this.password);
}
2)在第二个屏幕本身上启动var:
String email;
String password;
3)从第一个屏幕上的按钮(例如)调用导航器,发送值:
Navigator.pushNamed(context,"/secondScreen",arguments: email,password)
*将命名路由添加到您的main.dart中,以使其起作用。
4)使用从screen1发送到screen2的值。
希望有帮助。
,
您也可以尝试使用soapType
,以连续的步骤以“向导”的形式收集电子邮件,密码等。有很多变体(Google“步进器小部件”)。
这是一个非常基本的设置,其中添加了TextFormField
,您可以使用并将验证添加到:
import 'package:flutter/material.dart';
class StepperForm extends StatefulWidget {
static Future<void> show(BuildContext context) async {}
@override
_StepperFormState createState() => _StepperFormState();
}
class _StepperFormState extends State<StepperForm> {
///Stepper variables and functions
//declare the currentStep (starting point) as an int 0
int _currentStep = 0;
//Create a list of steps. Use TextFormFields for the email/password. Add validation if needed.
List<Step> _myStepperForm() {
List<Step> _steps = [
Step(
title: Text("Enter Your Email"),//state: StepState.complete,isActive: _currentStep >= 0,content: TextFormField(
decoration: InputDecoration(
labelText: 'Email',suffixIcon: Icon(Icons.email),border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),),validator: (value) =>
value.isNotEmpty ? null : 'email can\'t be empty',//Additional validation code as needed
),Step(
title: Text("Second"),isActive: _currentStep >= 1,content: Text("My Second Example"),Step(
title: Text("Third"),isActive: _currentStep >= 2,content: Text("My Third Example"),Step(
title: Text("Fourth"),isActive: _currentStep >= 3,content: Text("My Fourth Example"),];
return _steps;
}
//Create function for continue button
onStepContinue() {
setState(() {
if (this._currentStep < this._myStepperForm().length - 1) {
this._currentStep = this._currentStep + 1;
} else {
//Completion Code
print('The form is complete.');
}
});
}
//create cancel function
onStepCancel() {
setState(() {
if (this._currentStep > 0) {
this._currentStep = this._currentStep - 1;
} else {
this._currentStep = 0;
}
});
}
//Create the Stepper Widget
Widget _stepperWidget() => Container(
margin: EdgeInsets.only(top: 10),color: Colors.orangeAccent,child: Stepper(
//type: StepperType.horizontal,currentStep: this._currentStep,steps: _myStepperForm(),onStepCancel: onStepCancel,onStepContinue: onStepContinue,onStepTapped: (step) {
setState(() {
this._currentStep = step;
});
},);
//Call Stepper Function in Scaffold. SingleChildScrollView helps with different screen sizes
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('My Stepper Form'),body: SingleChildScrollView(
child: Column(
children: <Widget>[
_stepperWidget(),SizedBox(height: 600)
],);
}
}
本文链接:https://www.f2er.com/3163110.html