import 'package:flash_chat_app/screen/chat_screen.dart';
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'chat_screen.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
class LoginScreen extends StatefulWidget {
static const String id = 'login_screen';
const LoginScreen({Key? key}) : super(key: key);
@override
LoginScreenState createState() => LoginScreenState();
}
class LoginScreenState extends State<LoginScreen> {
final _auth = FirebaseAuth.instance;
late String email;
late String password;
bool showSpinner = false;
bool _obscureText = true;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: ModalProgressHUD(
inAsyncCall: showSpinner,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.only(top: 180.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Hero(
tag: "logo",
child: SizedBox(
height: 200.0,
child: Image.asset('images/chat.png'),
),
),
const SizedBox(
height: 48.0,
),
TextField(
keyboardType: TextInputType.emailAddress,
textAlign: TextAlign.center,
obscureText: false,
onChanged: (value) {
email = value;
},
style: const TextStyle(color: Colors.black),
decoration: const InputDecoration(
hintText: 'Enter your Email',
hintStyle: TextStyle(color: Colors.black26),
contentPadding:
EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
enabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.lightBlueAccent, width: 1.0),
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.lightBlueAccent, width: 2.0),
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
),
),
const SizedBox(
height: 8.0,
),
TextField(
textAlign: TextAlign.center,
obscureText: _obscureText,
onChanged: (value) {
//Do something with the user input.
password = value;
},
style: const TextStyle(color: Colors.black),
decoration: const InputDecoration(
hintText: 'Enter your Password.',
hintStyle: TextStyle(color: Colors.black26),
suffix: InkWell(
child: Icon(Icons.visibility),
onTap: _togglePasswordView,
//here is error in onTap
),
contentPadding:
EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
enabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.lightBlueAccent, width: 1.0),
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.lightBlueAccent, width: 2.0),
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
),
),
const SizedBox(
height: 24.0,
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: Material(
color: Colors.lightBlueAccent,
borderRadius: const BorderRadius.all(
Radius.circular(30.0)),
elevation: 5.0,
child: MaterialButton(
onPressed: () async {
setState(() {
showSpinner = true;
});
try {
final user = await _auth.signInWithEmailAndPassword(
email: email, password: password);
if (user != null) {
Navigator.pushNamed(context, ChatScreen.id);
}
setState(() {
showSpinner = false;
});
}
catch (e) {
print(e);
}
},
minWidth: 200.0,
height: 42.0,
child: const Text(
'Log In',
),
),
),
),
],
),
),
),
),
),
);
}
void _togglePasswordView() {
setState(() {
_obscureText = !_obscureText;
});
}
}
这是页面的所有代码,在后缀的onTap函数中有一个erron。错误消息显示//无效常量//错误的图像在这里
,
发布于 2022-07-17 11:28:14
装饰:康斯特InputDecoration
您将输入装饰定义为常量,但如果出现错误,则不会是常量。移除康斯特
https://stackoverflow.com/questions/73011209
复制相似问题