Compare commits

...

4 Commits

Author SHA1 Message Date
JingChiang
cf3abfc12b style: format code 2024-09-08 20:28:52 +08:00
JingChiang
994701e2ff feat: 新增基礎驗證、錯誤處理
1. 為註冊資料新增基礎驗證及驗證碼驗證實作
 2. 錯誤欄位游標自動移到該欄
2024-09-08 20:23:18 +08:00
JingChiang
7e6b0df97f feat: textField 新增 focusNode 設置
新增 focusNode 用以控制游標目標位置
2024-09-08 20:21:01 +08:00
JingChiang
7c33bd99d9 更改資料庫連接,testdb->care(RegisterPage) 2024-09-08 20:19:12 +08:00
7 changed files with 285 additions and 225 deletions

View File

@@ -1,11 +1,4 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:topic/BottomNavBar.dart';
import 'package:topic/main.dart';
import 'package:topic/HomePage.dart';
import 'package:topic/PersonalInfo.dart';
import 'package:topic/KnowledgePage.dart';
import 'package:topic/MessagePage.dart';
import 'package:mysql_client/mysql_client.dart'; import 'package:mysql_client/mysql_client.dart';
class HistoricalRecord extends StatefulWidget { class HistoricalRecord extends StatefulWidget {
@@ -42,7 +35,8 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
await conn.connect(); await conn.connect();
try { try {
var result = await conn.execute('SELECT HomeElderFall.*, HomeElder.heName FROM HomeElderFall JOIN HomeElder ON HomeElderFall.heId = HomeElder.heId;'); var result = await conn.execute(
'SELECT HomeElderFall.*, HomeElder.heName FROM HomeElderFall JOIN HomeElder ON HomeElderFall.heId = HomeElder.heId;');
print('Result: ${result.length} rows found.'); print('Result: ${result.length} rows found.');
if (result.rows.isEmpty) { if (result.rows.isEmpty) {
@@ -51,12 +45,12 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
setState(() { setState(() {
_results = result.rows _results = result.rows
.map((row) => { .map((row) => {
'長者ID': row.colAt(0),//去裝資料庫的行數 '長者ID': row.colAt(0), //去裝資料庫的行數
'姓名': row.colAt(8), '姓名': row.colAt(8),
'跌倒時間': row.colAt(1), '跌倒時間': row.colAt(1),
'跌倒原因': row.colAt(2), '跌倒原因': row.colAt(2),
'跌倒地點': row.colAt(7), '跌倒地點': row.colAt(7),
}) })
.toList(); .toList();
}); });
} }

View File

@@ -1,7 +1,4 @@
// import 'dart:html';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:topic/TryPage.dart';
import 'package:webview_flutter/webview_flutter.dart'; import 'package:webview_flutter/webview_flutter.dart';
import 'BottomNavBar.dart'; import 'BottomNavBar.dart';
@@ -61,7 +58,6 @@ class _HomePageState extends State<HomePage> {
height: 240, height: 240,
width: double.infinity, width: double.infinity,
// TODO: 如果用http需要分別設定ios, android權限 // TODO: 如果用http需要分別設定ios, android權限
// TODO: 替換video_player to flutter_webView
child: WebViewWidget( child: WebViewWidget(
controller: WebViewController() controller: WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted) ..setJavaScriptMode(JavaScriptMode.unrestricted)

View File

@@ -9,6 +9,7 @@ import 'package:topic/HomePage.dart';
class KnowledgePage extends StatelessWidget { class KnowledgePage extends StatelessWidget {
final String email; // 接收來自上個頁面的 email final String email; // 接收來自上個頁面的 email
KnowledgePage({required this.email}); KnowledgePage({required this.email});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(

View File

@@ -58,7 +58,6 @@ class _MessagePageState extends State<MessagePage> {
height: 240, height: 240,
width: double.infinity, width: double.infinity,
// TODO: 如果用http需要分別設定ios, android權限 // TODO: 如果用http需要分別設定ios, android權限
// TODO: 替換video_player to flutter_webView
child: WebViewWidget( child: WebViewWidget(
controller: WebViewController() controller: WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted) ..setJavaScriptMode(JavaScriptMode.unrestricted)

View File

@@ -4,21 +4,22 @@ import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:topic/NoSwipeBackRoute.dart'; import 'package:topic/NoSwipeBackRoute.dart';
import 'package:topic/main.dart'; import 'package:topic/main.dart';
/*void main() {
runApp(MaterialApp(
home: PersonalInfo(),
));
}*/
class PersonalInfo extends StatefulWidget { class PersonalInfo extends StatefulWidget {
final String email; // 接收來自上個頁面的 email final String email; // 接收來自上個頁面的 email
PersonalInfo({required this.email}); PersonalInfo({required this.email});
@override @override
_PersonalInfoState createState() => _PersonalInfoState(); _PersonalInfoState createState() => _PersonalInfoState();
} }
class _PersonalInfoState extends State<PersonalInfo> { class _PersonalInfoState extends State<PersonalInfo> {
String _name = '', _phone = '', _gender = '', _address='', _email = '', _password = ''; String _name = '',
_phone = '',
_gender = '',
_address = '',
_email = '',
_password = '';
bool _isEditing = false; //是否為編輯狀態 bool _isEditing = false; //是否為編輯狀態
final TextEditingController _nameController = TextEditingController(); final TextEditingController _nameController = TextEditingController();
final TextEditingController _phoneController = TextEditingController(); final TextEditingController _phoneController = TextEditingController();
@@ -53,19 +54,20 @@ class _PersonalInfoState extends State<PersonalInfo> {
try { try {
print('ok'); print('ok');
print('狀態:$_isEditing'); print('狀態:$_isEditing');
var result = await conn.execute('SELECT * FROM HomeLogin WHERE homeemail = :email', var result = await conn.execute(
{'email': widget.email}, // 傳入參數 email 'SELECT * FROM HomeLogin WHERE homeemail = :email',
{'email': widget.email}, // 傳入參數 email
); );
if (result.rows.isNotEmpty) { if (result.rows.isNotEmpty) {
//有資料 //有資料
var row = result.rows.first; var row = result.rows.first;
setState(() { setState(() {
_name = row.colAt(0)??'';//如果沒有資料就是空直 _name = row.colAt(0) ?? ''; //如果沒有資料就是空直
_phone = row.colAt(1)??''; _phone = row.colAt(1) ?? '';
_gender = row.colAt(2)??''; _gender = row.colAt(2) ?? '';
_address = row.colAt(3)??''; _address = row.colAt(3) ?? '';
_email = row.colAt(4)??''; _email = row.colAt(4) ?? '';
_password = row.colAt(5)??''; _password = row.colAt(5) ?? '';
}); });
} }
} catch (e) { } catch (e) {
@@ -104,16 +106,16 @@ class _PersonalInfoState extends State<PersonalInfo> {
try { try {
await conn.execute( await conn.execute(
'UPDATE HomeLogin SET homeName = :homeName, homePhone = :homePhone, homeGender = :homeGender, homeAddress = :homeAddress, homeEmail = :new_email, homePassword = :homePassword WHERE homeEmail = :old_email', 'UPDATE HomeLogin SET homeName = :homeName, homePhone = :homePhone, homeGender = :homeGender, homeAddress = :homeAddress, homeEmail = :new_email, homePassword = :homePassword WHERE homeEmail = :old_email',
{ {
'homeName':_nameController.text, 'homeName': _nameController.text,
'homePhone': _phoneController.text, 'homePhone': _phoneController.text,
'homeGender': _genderController.text, 'homeGender': _genderController.text,
'homeAddress': _addressController.text, 'homeAddress': _addressController.text,
'new_email': _emailController.text, 'new_email': _emailController.text,
'old_email': widget.email, // 用戶的舊 email 作為查找條件 'old_email': widget.email, // 用戶的舊 email 作為查找條件
'homePassword': _passwordController.text, 'homePassword': _passwordController.text,
}, },
); );
setState(() { setState(() {
_name = _nameController.text; _name = _nameController.text;
@@ -171,7 +173,8 @@ class _PersonalInfoState extends State<PersonalInfo> {
children: [ children: [
Container( Container(
height: 100, height: 100,
color: Color(0xFFF5E3C3),//背景底色 color: Color(0xFFF5E3C3),
//背景底色
width: double.infinity, width: double.infinity,
padding: EdgeInsets.all(10.0), padding: EdgeInsets.all(10.0),
child: Center( child: Center(
@@ -187,7 +190,10 @@ class _PersonalInfoState extends State<PersonalInfo> {
children: [ children: [
ListTile( ListTile(
title: Text('姓名',style: TextStyle(fontSize: 20),), title: Text(
'姓名',
style: TextStyle(fontSize: 20),
),
subtitle: Text(_name), subtitle: Text(_name),
), ),
Divider(), Divider(),
@@ -195,13 +201,13 @@ class _PersonalInfoState extends State<PersonalInfo> {
title: Text('手機'), title: Text('手機'),
subtitle: _isEditing subtitle: _isEditing
? TextField( ? TextField(
controller: _phoneController, controller: _phoneController,
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {
_phone = value; _phone = value;
}); });
}, },
) )
: Text(_phone), : Text(_phone),
), ),
Divider(), Divider(),
@@ -209,13 +215,13 @@ class _PersonalInfoState extends State<PersonalInfo> {
title: Text('性別'), title: Text('性別'),
subtitle: _isEditing subtitle: _isEditing
? TextField( ? TextField(
controller: _genderController, controller: _genderController,
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {
_gender = value; _gender = value;
}); });
}, },
) )
: Text(_gender), : Text(_gender),
), ),
Divider(), Divider(),
@@ -223,13 +229,13 @@ class _PersonalInfoState extends State<PersonalInfo> {
title: Text('地址'), title: Text('地址'),
subtitle: _isEditing subtitle: _isEditing
? TextField( ? TextField(
controller: _addressController, controller: _addressController,
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {
_address = value; _address = value;
}); });
}, },
) )
: Text(_address), : Text(_address),
), ),
Divider(), Divider(),
@@ -237,13 +243,13 @@ class _PersonalInfoState extends State<PersonalInfo> {
title: Text('電子信箱'), title: Text('電子信箱'),
subtitle: _isEditing subtitle: _isEditing
? TextField( ? TextField(
controller: _emailController, controller: _emailController,
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {
_email = value; _email = value;
}); });
}, },
) )
: Text(_email), : Text(_email),
), ),
Divider(), Divider(),
@@ -251,23 +257,26 @@ class _PersonalInfoState extends State<PersonalInfo> {
title: Text('密碼'), title: Text('密碼'),
subtitle: _isEditing subtitle: _isEditing
? TextField( ? TextField(
controller: _passwordController, controller: _passwordController,
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {
_password = value; _password = value;
}); });
}, },
) )
: Text(_password), : Text(_password),
), ),
Divider(), Divider(),
SizedBox(height: 20,width: 60,), SizedBox(
height: 20,
width: 60,
),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
if (_isEditing) { if (_isEditing) {
_saveChanges(); // 儲存變更 _saveChanges(); // 儲存變更
} else { } else {
_toggleEdit(); // 進入編輯模式 _toggleEdit(); // 進入編輯模式
} }
}, },
child: Text(_isEditing ? '儲存變更' : '修改資料'), child: Text(_isEditing ? '儲存變更' : '修改資料'),
@@ -277,7 +286,10 @@ class _PersonalInfoState extends State<PersonalInfo> {
shadowColor: Colors.transparent, // 去除陰影 shadowColor: Colors.transparent, // 去除陰影
), ),
), ),
SizedBox(height: 10,width: 60,), SizedBox(
height: 10,
width: 60,
),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
_loginOut(); _loginOut();

View File

@@ -18,6 +18,7 @@ class RegisterPage extends StatefulWidget {
} }
class _RegisterPageState extends State<RegisterPage> { class _RegisterPageState extends State<RegisterPage> {
late FocusNode _nameFocusNode, _emailFocusNode, _passwordFocusNode, _codeFocusNode;
final TextEditingController _nameController = TextEditingController(); final TextEditingController _nameController = TextEditingController();
final TextEditingController _emailController = TextEditingController(); final TextEditingController _emailController = TextEditingController();
final TextEditingController _passwordController = TextEditingController(); final TextEditingController _passwordController = TextEditingController();
@@ -33,6 +34,10 @@ class _RegisterPageState extends State<RegisterPage> {
void initState() { void initState() {
super.initState(); super.initState();
_fetchData(); _fetchData();
_nameFocusNode = FocusNode();
_emailFocusNode = FocusNode();
_passwordFocusNode = FocusNode();
_codeFocusNode = FocusNode();
} }
void _fetchData() async { void _fetchData() async {
@@ -106,6 +111,7 @@ class _RegisterPageState extends State<RegisterPage> {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('請輸入正確的電子信箱')), SnackBar(content: Text('請輸入正確的電子信箱')),
); );
_emailFocusNode.requestFocus();
return; return;
} }
@@ -114,24 +120,63 @@ class _RegisterPageState extends State<RegisterPage> {
_startTimer(); _startTimer();
} }
bool _isDataCorrect() {
String name = _nameController.text;
String email = _emailController.text;
String password = _passwordController.text;
String code = _codeController.text;
if (name == '') {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('用戶姓名不可為空')),
);
_nameFocusNode.requestFocus();
return false;
}
if (email == '') {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('電子信箱不可為空')),
);
_emailFocusNode.requestFocus();
return false;
}
if (password == '') {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('密碼不可為空')),
);
_passwordFocusNode.requestFocus();
return false;
}
if (code != _generatedCode) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('驗證碼錯誤')),
);
_codeFocusNode.requestFocus();
return false;
}
return true;
}
void registerBtn() async { void registerBtn() async {
// TODO: 驗證碼未實作驗證 if (!_isDataCorrect()) return;
final conn = await MySQLConnection.createConnection( final conn = await MySQLConnection.createConnection(
host: '10.0.2.2', host: '203.64.84.154',
port: 3306, port: 33061,
userName: 'root', userName: 'root',
password: '0000', password: 'Topic@2024',
databaseName: 'testdb', databaseName: 'care',
); );
await conn.connect(); await conn.connect();
try { try {
String name = _nameController.text; String name = _nameController.text;
String email = _emailController.text; String email = _emailController.text;
String password = _passwordController.text; String password = _passwordController.text;
var result = await conn.execute( var result = await conn.execute(
'SELECT * FROM users WHERE email = :email AND password = :password', 'SELECT * FROM HomeLogin WHERE homeEmail = :email AND homePassword = :password',
{'email': email, 'password': password}, {'email': email, 'password': password},
); );
@@ -141,7 +186,7 @@ class _RegisterPageState extends State<RegisterPage> {
); );
} else { } else {
await conn.execute( await conn.execute(
'INSERT INTO users (name, email, password) VALUES (:name, :email, :password)', 'INSERT INTO HomeLogin (homeName, homeEmail, homePassword) VALUES (:name, :email, :password)',
{'name': name, 'email': email, 'password': password}, {'name': name, 'email': email, 'password': password},
); );
@@ -163,7 +208,7 @@ class _RegisterPageState extends State<RegisterPage> {
} catch (e) { } catch (e) {
print('資料庫錯誤: $e'); print('資料庫錯誤: $e');
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('登入失敗:系統錯誤')), SnackBar(content: Text('註冊失敗:系統錯誤')),
); );
} finally { } finally {
await conn.close(); await conn.close();
@@ -172,8 +217,13 @@ class _RegisterPageState extends State<RegisterPage> {
@override @override
void dispose() { void dispose() {
_timer?.cancel();
super.dispose(); super.dispose();
_timer?.cancel();
_nameFocusNode.dispose();
_emailFocusNode.dispose();
_passwordFocusNode.dispose();
_codeFocusNode.dispose();
} }
@override @override
@@ -207,6 +257,7 @@ class _RegisterPageState extends State<RegisterPage> {
SizedBox(height: 20), SizedBox(height: 20),
TextField( TextField(
controller: _nameController, controller: _nameController,
focusNode: _nameFocusNode,
decoration: InputDecoration( decoration: InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
prefixIcon: Icon(Icons.person_outlined), prefixIcon: Icon(Icons.person_outlined),
@@ -216,6 +267,7 @@ class _RegisterPageState extends State<RegisterPage> {
SizedBox(height: 20), SizedBox(height: 20),
TextField( TextField(
controller: _emailController, controller: _emailController,
focusNode: _emailFocusNode,
decoration: InputDecoration( decoration: InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
prefixIcon: Icon(Icons.email_outlined), prefixIcon: Icon(Icons.email_outlined),
@@ -226,6 +278,7 @@ class _RegisterPageState extends State<RegisterPage> {
SizedBox(height: 20), SizedBox(height: 20),
TextField( TextField(
controller: _passwordController, controller: _passwordController,
focusNode: _passwordFocusNode,
decoration: InputDecoration( decoration: InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
prefixIcon: Icon(Icons.lock_outlined), prefixIcon: Icon(Icons.lock_outlined),
@@ -235,7 +288,7 @@ class _RegisterPageState extends State<RegisterPage> {
: Icons.visibility_off), : Icons.visibility_off),
onPressed: () { onPressed: () {
setState( setState(
() { () {
_passwordNotVisible = !_passwordNotVisible; _passwordNotVisible = !_passwordNotVisible;
}, },
); );
@@ -251,6 +304,7 @@ class _RegisterPageState extends State<RegisterPage> {
Expanded( Expanded(
child: TextField( child: TextField(
controller: _codeController, controller: _codeController,
focusNode: _codeFocusNode,
decoration: InputDecoration( decoration: InputDecoration(
labelText: '驗證碼', labelText: '驗證碼',
hintText: '填寫驗證碼', hintText: '填寫驗證碼',

View File

@@ -5,13 +5,14 @@ import 'package:topic/HomePage.dart';
import 'package:mysql_client/mysql_client.dart'; import 'package:mysql_client/mysql_client.dart';
import 'package:topic/NoSwipeBackRoute.dart'; import 'package:topic/NoSwipeBackRoute.dart';
import 'package:topic/RegisterPage.dart'; import 'package:topic/RegisterPage.dart';
void main() { void main() {
runApp(MaterialApp( runApp(MaterialApp(
home: LoginPage(), home: LoginPage(),
)); ));
} }
class LoginPage extends StatefulWidget {//ful會改變 class LoginPage extends StatefulWidget {
@override @override
_LoginPageState createState() => _LoginPageState(); _LoginPageState createState() => _LoginPageState();
} }
@@ -22,10 +23,11 @@ class _LoginPageState extends State<LoginPage> {
bool _passwordNotVisible = true; bool _passwordNotVisible = true;
@override @override
void initState() {//初始化 void initState() {
//初始化
super.initState(); super.initState();
_fetchData();//連資料庫 _fetchData(); //連資料庫
_CheckPreLoginInfo();//確定有先前有無登入 _CheckPreLoginInfo(); //確定有先前有無登入
} }
void _fetchData() async { void _fetchData() async {
@@ -44,12 +46,12 @@ class _LoginPageState extends State<LoginPage> {
await conn.connect(); await conn.connect();
} }
void _CheckPreLoginInfo() async{ void _CheckPreLoginInfo() async {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
//get user data from share preference else set empty to check not login before //get user data from share preference else set empty to check not login before
String loginUserEmail = prefs.getString("email") ?? ""; String loginUserEmail = prefs.getString("email") ?? "";
//replace screen to HomePage if there are previous data in share preference //replace screen to HomePage if there are previous data in share preference
if(loginUserEmail != ""){ if (loginUserEmail != "") {
Navigator.pushReplacement( Navigator.pushReplacement(
context, context,
NoSwipeBackRoute( NoSwipeBackRoute(
@@ -61,134 +63,12 @@ class _LoginPageState extends State<LoginPage> {
} }
} }
void _setLoginInfo(String email) async{ void _setLoginInfo(String email) async {
//save user email into share preference to let app can auto login next open //save user email into share preference to let app can auto login next open
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString("email", email); prefs.setString("email", email);
} }
@override
Widget build(BuildContext context) {
debugPaintSizeEnabled=false;
//by use PopScope and disable can Pop avoid android user pop back by back button
return PopScope(
canPop: false,
child: Scaffold(
//appBar: AppBar(
//title: Text('Demo'),
//backgroundColor: Color(0xFF81D4FA),
//),
body: SafeArea(
child: Center(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 32.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
margin: EdgeInsets.only(bottom: 40), // 添加間距
height: 100, // 設置logo高度
child: Icon(
Icons.account_circle,
size: 100, // 設置圖標大小
color: Color(0xFF4FC3F7), // 設置圖標颜色
),
),
Text(
'全方位照護守護者',
style: TextStyle(
fontSize: 32,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),//全方位照護守護者
SizedBox(height: 20),
TextField(
controller: _emailController, // 绑定電子信箱输入框的控制器
decoration: InputDecoration(
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.email_outlined),//https://www.fluttericon.cn/v
labelText: '電子信箱',
),
),//電子信箱
SizedBox(height: 20),
TextField(
controller: _ageController,
decoration: InputDecoration(
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.lock_outlined),
suffixIcon: IconButton(
icon: Icon(_passwordNotVisible
? Icons.visibility
: Icons.visibility_off),
onPressed: () {
setState(
() {
_passwordNotVisible = !_passwordNotVisible;
},
);
},
),
labelText: '密碼',
),
obscureText: _passwordNotVisible,
),//密碼
SizedBox(height: 20),
ElevatedButton(
onPressed: loginBtn,/*() {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HomePage()),
);
},*/
child: Text(' 登入'),
style: ElevatedButton.styleFrom(
backgroundColor: Color(0xFF4FC3F7),
padding: EdgeInsets.symmetric(horizontal: 50, vertical: 15),
textStyle: TextStyle(fontSize: 18),
),
),//登入
SizedBox(height: 10),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => RegisterPage()),
);
},
child: Text('立即註冊'),
style: TextButton.styleFrom(
backgroundColor: Colors.transparent, // 無背景颜色
textStyle: TextStyle(fontSize: 18),
shadowColor: Colors.transparent, // 去除陰影
),
),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HomePage(
email: _emailController.text,
)),
);
},
child: Text('忘記密碼'),
style: TextButton.styleFrom(
backgroundColor: Colors.transparent, // 無背景颜色
textStyle: TextStyle(fontSize: 18),
shadowColor: Colors.transparent, // 去除陰影
),
),
],
),
),
),
),
),
),
);
}
void loginBtn() async { void loginBtn() async {
final conn = await MySQLConnection.createConnection( final conn = await MySQLConnection.createConnection(
host: '203.64.84.154', host: '203.64.84.154',
@@ -247,4 +127,128 @@ class _LoginPageState extends State<LoginPage> {
await conn.close(); await conn.close();
} }
} }
}
@override
Widget build(BuildContext context) {
debugPaintSizeEnabled = false;
//by use PopScope and disable can Pop avoid android user pop back by back button
return PopScope(
canPop: false,
child: Scaffold(
body: SafeArea(
child: Center(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 32.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
margin: EdgeInsets.only(bottom: 40), // 添加間距
height: 100, // 設置logo高度
child: Icon(
Icons.account_circle,
size: 100, // 設置圖標大小
color: Color(0xFF4FC3F7), // 設置圖標颜色
),
),
Text(
'全方位照護守護者',
style: TextStyle(
fontSize: 32,
fontWeight: FontWeight.bold,
color: Colors.black,
),
), //全方位照護守護者
SizedBox(height: 20),
TextField(
controller: _emailController, // 绑定電子信箱输入框的控制器
decoration: InputDecoration(
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.email_outlined),
//https://www.fluttericon.cn/v
labelText: '電子信箱',
),
), //電子信箱
SizedBox(height: 20),
TextField(
controller: _ageController,
decoration: InputDecoration(
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.lock_outlined),
suffixIcon: IconButton(
icon: Icon(_passwordNotVisible
? Icons.visibility
: Icons.visibility_off),
onPressed: () {
setState(
() {
_passwordNotVisible = !_passwordNotVisible;
},
);
},
),
labelText: '密碼',
),
obscureText: _passwordNotVisible,
), //密碼
SizedBox(height: 20),
ElevatedButton(
onPressed: loginBtn,
/*() {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HomePage()),
);
},*/
child: Text(' 登入'),
style: ElevatedButton.styleFrom(
backgroundColor: Color(0xFF4FC3F7),
padding:
EdgeInsets.symmetric(horizontal: 50, vertical: 15),
textStyle: TextStyle(fontSize: 18),
),
), //登入
SizedBox(height: 10),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RegisterPage()),
);
},
child: Text('立即註冊'),
style: TextButton.styleFrom(
backgroundColor: Colors.transparent, // 無背景颜色
textStyle: TextStyle(fontSize: 18),
shadowColor: Colors.transparent, // 去除陰影
),
),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomePage(
email: _emailController.text,
)),
);
},
child: Text('忘記密碼'),
style: TextButton.styleFrom(
backgroundColor: Colors.transparent, // 無背景颜色
textStyle: TextStyle(fontSize: 18),
shadowColor: Colors.transparent, // 去除陰影
),
),
],
),
),
),
),
),
),
);
}
}