我还在努力适应颤动。我有一个用户的注册表,当用户单击按钮时,我希望所有文本都发送到我的link.But接口。有没有简单的方法可以做到这一点?或者我应该一个接一个地发短信?我的文本不应该是空的。我怎么才能提供这个呢?
我将在将来调用我的api,并且我想发送用户将在此处输入我的数据的文本。
Future<RegisterComplete> createRegisterComplete(
String email, String language) async {
final http.Response response = await http.post(
'MY API URL',
headers: <String, String>{'Content-Type': 'application/json'},
body: jsonEncode(<String, String>{
'firstName': ' ',
'lastName': ' ',
'password': ' ',
'countryCode': ' ',
'language': ' ',
}),
);
if (response.statusCode == 201) {
return RegisterComplete.fromJson(json.decode(response.body));
} else {
print('Here:${response.statusCode}');
throw Exception('Failed to load page');
}
}
class RegisterPage extends StatefulWidget {
@override
_RegisterPageState createState() => _RegisterPageState();
}
class _RegisterPageState extends State<RegisterPage> {
Future<ConfirmCode> _confirmCode;
var textFieldPasswordController = TextEditingController();
var textFieldConfirmPasswordController = TextEditingController();
var cityController=TextEditingController();
var nameController=TextEditingController();
var surnameController=TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.pop(context);
},
),
Text(
allTranslations.text('login'),
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: HexColor('#4A8EB0'),
),
),
],
),
),
Text(
allTranslations.text('signUp'),
style: TextStyle(fontSize: 26, fontWeight: FontWeight.bold),
),
_paddingWidget('E-mail', 'E-mail',emailController),
_paddingPasswordWidget(allTranslations.text('password'), allTranslations.text('password')),
_paddingWidget('City', 'City',cityController),
_paddingWidget('Name', 'Name',nameController),
_paddingWidget('Surname', 'Surname',surnameController),
Padding(
padding: EdgeInsets.all(16.0),
child: Container(
height: 50.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: HexColor('#B0B0B0'),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 6,
offset: Offset(0, 2), // changes position of shadow
),
BoxShadow(
color: Colors.black.withOpacity(0.1),
blurRadius: 20,
offset: Offset(0, 10), // changes position of shadow
),
],
),
child: InkWell(
onTap: () {
setState(() {
BUTTON I USE FOR SİGN UP
});
},
child: Center(
child: Text(
allTranslations.text('signUp'),
style: TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
],
),
),
),
);
}
_paddingWidget(String hintTextStr, String labelTextStr,TextEditingController _controller) {
return Padding(
padding: EdgeInsets.only(top: 15, left: 22, right: 22),
child: TextFormField(
controller: _controller,
keyboardType: TextInputType.text,
style: TextStyle(
color: HexColor('#868686'),
),
decoration: CommonInputStyle.textFieldStyle(
hintTextStr: hintTextStr,
labelTextStr: labelTextStr,
),
),
);
}
_buttonWidget(String title,GestureTapCallback onPressed) {
return Container(
height: 40,
width: 160,
child: RaisedButton(
child: Text(
title,
style: TextStyle(color: Colors.white),
),
onPressed: onPressed,
color: HexColor('#4A8EB0'),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
),
);
}
_paddingPasswordWidget(String hintTextStr, String labelTextStr) {
return Padding(
padding: EdgeInsets.only(top: 15, left: 22, right: 22),
child: TextFormField(
controller: textFieldPasswordController,
keyboardType: TextInputType.text,
style: TextStyle(
color: HexColor('#868686'),
),
decoration: CommonInputStyle.textFieldStyle(
hintTextStr: hintTextStr,
labelTextStr: labelTextStr,
),
obscureText: true,
),
);
}
发布于 2020-09-17 09:30:16
首先。
这个方法应该包含var data
,它将成为你身体的处理器。
如下所示:
Future<RegisterComplete> createRegisterComplete(
String email, String language, var data) async {
final http.Response response = await http.post(
'MY API URL',
headers: <String, String>{'Content-Type': 'application/json'},
body: jsonEncode(data),
);
if (response.statusCode == 201) {
return RegisterComplete.fromJson(json.decode(response.body));
} else {
print('Here:${response.statusCode}');
throw Exception('Failed to load page');
}
}
现在,这允许您实际包装来自TextEditingControllers
的所有数据,因此您可以执行以下操作:
child: InkWell(
onTap: () async {
setState(() {
var data = {
'firstName': nameController.text,
'lastName': lastNameController.text,
'password': passwordController.text,
'countryCode': countryCodeController.text,
'language': languageController.text,
}
// here you do an actual API call
await createRegisterComplete(emailController.text, languageController.text, data);
});
},
但有一种更好的方法来实现这一点,那就是使用存储库来处理这样的事情。
但还有更多的例子
https://stackoverflow.com/questions/63934866
复制相似问题