Я новичок, чтобы трепетать.Я пытаюсь разместить 2 текстовых поля, а именно адрес электронной почты и пароль.И одна кнопка входа.Если пользователь нажимает кнопку входа в систему, я хочу проверить значение в текстовом поле.Если это "username and password = admin", я хочу напечатать сообщение "Вход в систему успешен".Чтобы получить значение в текстовом поле, я использовал controller , чтобы получить текст.но если я использую контроллер, когда я переключаюсь на следующее текстовое поле, значение в первом автоматически удаляется .Я не знаю, в чем проблема.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'stacked_icons.dart';
import 'main.dart';
class LoginPage extends StatelessWidget {
final emailController = TextEditingController();
final passwordController = TextEditingController();
@override
Widget build(BuildContext context) { SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
statusBarColor: Colors.orange, //or set color with: Color(0xFF0000FF)
));
return new Scaffold(
appBar: new AppBar(
backgroundColor:Colors.transparent,
elevation: 0.0,
iconTheme: new IconThemeData(color: Color(0xFF18D191))),
body: Container(
width: double.infinity,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new StakedIcons(),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 80.0),
child: new Text(
"Village",
style: new TextStyle(fontSize: 30.0),
),
)
],
),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
child: TextField(
controller: emailController,
decoration:
new InputDecoration(labelText: 'Email'),
),
),
new SizedBox(
height: 15.0,
),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
child: TextField(
obscureText: true,
decoration: InputDecoration(labelText: 'Password'),
//controller: passwordController
),
),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 5.0, top: 10.0),
child: GestureDetector(
onTap: () {
debugPrint(passwordController.text+emailController.text);
},
child: new Container(
alignment: Alignment.center,
height: 60.0,
decoration: new BoxDecoration(
color: Color(0xFF18D191),
borderRadius: new BorderRadius.circular(9.0)),
child: new Text("Login",
style: new TextStyle(
fontSize: 20.0, color: Colors.white))),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 10.0, right: 20.0, top: 10.0),
child: new Container(
alignment: Alignment.center,
height: 60.0,
child: new Text("Forgot Password?",
style: new TextStyle(
fontSize: 17.0, color: Color(0xFF18D191)))),
),
)
],
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(bottom:18.0),
child: new Text("Create A New Account ",style: new TextStyle(
fontSize: 17.0, color: Color(0xFF18D191),fontWeight: FontWeight.bold)),
),
],
),
)
],
),
),
);}}
Если я удаляю контроллер, значение в текстовом поле работает.Но без использования контроллера я не знаю, как получить текст.