【发布时间】:2021-04-07 03:36:06
【问题描述】:
我正在尝试在 Flutter 中创建一个 LoginPage。我只想放置“服务条款。隐私政策”。 Flatbutton 在屏幕的末尾。我尝试了很多东西,但似乎没有任何效果!
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Expense Tracker',
home: LoginPage(),
);
}
}
class LoginPage extends StatefulWidget {
// String titleInput;
// String amountInput;
@override
_LoginPage createState() => _LoginPage();
}
class _LoginPage extends State<LoginPage> {
final userName = TextEditingController();
final password = TextEditingController();
String textDisplay = "";
void onSubmit() {
setState(() {
if (userName == null) {
textDisplay = "Invalid Username";
} else if (password == null && userName != null) {
textDisplay = "Invalid Password";
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('LOGIN'),
),
body: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: EdgeInsets.all(10),
child: Image.asset("assets/images/nike.png"),
),
Container(
padding: EdgeInsets.all(10),
child: Column(
children: [
TextField(
controller: userName,
decoration: InputDecoration(
labelText: "Username",
labelStyle: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
keyboardType: TextInputType.emailAddress,
onSubmitted: (_) => onSubmit(),
),
TextField(
controller: password,
decoration: InputDecoration(
labelText: "Password",
labelStyle: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
keyboardType: TextInputType.visiblePassword,
onSubmitted: (_) => onSubmit(),
),
Text(
textDisplay,
style: TextStyle(
color: Colors.redAccent[700],
),
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
FlatButton(
child: Text(
"Not a User. Sign Up Here.",
style: TextStyle(
color: Colors.black,
fontSize: 15,
),
),
onPressed: () {},
),
FlatButton(
child: Text(
"Terms of Service. Privacy Policy.",
style: TextStyle(
color: Colors.grey[700],
fontSize: 13,
),
),
onPressed: () {},
),
],
)
],
),
)
],
),
),
);
}
}
SetState(() {})也不行!由于我还在学习 Flutter,请也解释一下答案。
如果我的代码有任何好的更改以使我的应用程序更好,请提出建议。
【问题讨论】: