Commit 83ca9b54 authored by “Icebear”'s avatar “Icebear”

添加登录页,完成两个输入框和边框

parent 713d82dd
...@@ -18,4 +18,6 @@ class Images{ ...@@ -18,4 +18,6 @@ class Images{
static const ic_privacy = "${imagesPath}ic_privacy.png"; static const ic_privacy = "${imagesPath}ic_privacy.png";
static const ic_sign = "${imagesPath}ic_sign.png"; static const ic_sign = "${imagesPath}ic_sign.png";
static const ic_back_black = "${imagesPath}ic_back_black.png"; static const ic_back_black = "${imagesPath}ic_back_black.png";
static const ic_login_button = "${imagesPath}login_button.png";
} }
\ No newline at end of file
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:fluttertoast/fluttertoast.dart'; import 'package:fluttertoast/fluttertoast.dart';
import 'package:netrain_flutter_app/zhangfeng/UserModel.dart'; import 'package:netrain_flutter_app/zhangfeng/UserModel.dart';
import 'LoginApi.dart'; import 'LoginApi.dart';
import 'package:netrain_flutter_app/common/Images.dart';
class LoginRequestPage extends StatefulWidget { class LoginRequestPage extends StatefulWidget {
final String title = "登录页"; final String title = "登录页";
...@@ -12,6 +14,17 @@ class LoginRequestPage extends StatefulWidget { ...@@ -12,6 +14,17 @@ class LoginRequestPage extends StatefulWidget {
class _LoginState extends State<LoginRequestPage> { class _LoginState extends State<LoginRequestPage> {
// This widget is the root of your application. // This widget is the root of your application.
final phoneTextField = TextEditingController();
final pwdTextField = TextEditingController();
@override
void dispose() {
// Clean up the controller when disposing of the Widget.
phoneTextField.dispose();
pwdTextField.dispose();
super.dispose();
}
void _loginAction() { void _loginAction() {
if(UserModel.getModel() != null){ if(UserModel.getModel() != null){
Fluttertoast.showToast(msg:'已经登录'); Fluttertoast.showToast(msg:'已经登录');
...@@ -46,17 +59,33 @@ class _LoginState extends State<LoginRequestPage> { ...@@ -46,17 +59,33 @@ class _LoginState extends State<LoginRequestPage> {
), ),
body: Center( body: Center(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
FloatingActionButton( Container(
onPressed: _loginAction, child:Image(image: AssetImage(Images.logo_01)),
child:Icon(Icons.add), padding: EdgeInsets.only(top: 50,left: 50,right: 50),
heroTag: 0, ),
Container(
padding: EdgeInsets.only(top: 100,left: 16,right: 16),
child: TextField(
controller: phoneTextField,
decoration: InputDecoration(hintText: "请输入手机号码",border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
borderSide: BorderSide()),),
),
),
Container(
padding: EdgeInsets.only(top: 20,left: 16,right: 16),
child: TextField(
controller: pwdTextField,
decoration: InputDecoration(hintText: "请输入密码",border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
borderSide: BorderSide()),),
),
), ),
FloatingActionButton( Container(
onPressed: _logoutAction, padding: EdgeInsets.only(top: 50,left: 16,right: 16),
child:Icon(Icons.add), decoration: BoxDecoration(
heroTag: 1, image: DecorationImage(image: AssetImage(Images.ic_login_button))),
), ),
], ],
), ),
......
...@@ -10,41 +10,58 @@ class SampleAppPage extends StatefulWidget{ ...@@ -10,41 +10,58 @@ class SampleAppPage extends StatefulWidget{
} }
class _SampleAppPageState extends State<SampleAppPage>{ class _SampleAppPageState extends State<SampleAppPage>{
String _errorText; final PageController _pageController = PageController();
@override
void dispose() {
_pageController.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return MaterialApp(
appBar: AppBar( home: Scaffold(
title: Text("Sample App"), body: PageView(
), controller: _pageController,
body: Center( children: <Widget>[
child: TextField( Container(
onSubmitted: (String text) { color: Colors.red,
setState(() { child: Center(
if (!isEmail(text)) { child: ElevatedButton(
_errorText = 'Error: This is not an email'; onPressed: () {
} else { if (_pageController.hasClients) {
_errorText = null; _pageController.animateToPage(
1,
duration: const Duration(milliseconds: 400),
curve: Curves.easeInOut,
);
} }
});
}, },
decoration: InputDecoration(hintText: "This is a hint", errorText: _getErrorText()), child: const Text('Next'),
),
), ),
), ),
Container(
color: Colors.blue,
child: Center(
child: ElevatedButton(
onPressed: () {
if (_pageController.hasClients) {
_pageController.animateToPage(
0,
duration: const Duration(milliseconds: 400),
curve: Curves.easeInOut,
); );
} }
},
_getErrorText() { child: const Text('Previous'),
return _errorText; ),
} ),
),
bool isEmail(String em) { ],
String emailRegexp = ),
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$'; ),
);
RegExp regExp = RegExp(emailRegexp);
return regExp.hasMatch(em);
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment