Compare commits
No commits in common. "cf3abfc12bc3acc2913d6536631b55ce34b707ac" and "edd2f5780026b471f90887618d222c6ca4936aee" have entirely different histories.
cf3abfc12b
...
edd2f57800
|
|
@ -1,4 +1,11 @@
|
||||||
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 {
|
||||||
|
|
@ -35,8 +42,7 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
|
||||||
await conn.connect();
|
await conn.connect();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var result = await conn.execute(
|
var result = await conn.execute('SELECT HomeElderFall.*, HomeElder.heName FROM HomeElderFall JOIN HomeElder ON HomeElderFall.heId = HomeElder.heId;');
|
||||||
'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) {
|
||||||
|
|
@ -45,7 +51,7 @@ 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),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
|
// 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';
|
||||||
|
|
@ -58,6 +61,7 @@ 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)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ 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(
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ 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)
|
||||||
|
|
|
||||||
|
|
@ -4,22 +4,21 @@ 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 = '',
|
String _name = '', _phone = '', _gender = '', _address='', _email = '', _password = '';
|
||||||
_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();
|
||||||
|
|
@ -54,20 +53,19 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
try {
|
try {
|
||||||
print('ok');
|
print('ok');
|
||||||
print('狀態:$_isEditing');
|
print('狀態:$_isEditing');
|
||||||
var result = await conn.execute(
|
var result = await conn.execute('SELECT * FROM HomeLogin WHERE homeemail = :email',
|
||||||
'SELECT * FROM HomeLogin WHERE homeemail = :email',
|
|
||||||
{'email': widget.email}, // 傳入參數 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) {
|
||||||
|
|
@ -108,7 +106,7 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
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,
|
||||||
|
|
@ -173,8 +171,7 @@ 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(
|
||||||
|
|
@ -190,10 +187,7 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
|
|
||||||
children: [
|
children: [
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(
|
title: Text('姓名',style: TextStyle(fontSize: 20),),
|
||||||
'姓名',
|
|
||||||
style: TextStyle(fontSize: 20),
|
|
||||||
),
|
|
||||||
subtitle: Text(_name),
|
subtitle: Text(_name),
|
||||||
),
|
),
|
||||||
Divider(),
|
Divider(),
|
||||||
|
|
@ -267,10 +261,7 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
: Text(_password),
|
: Text(_password),
|
||||||
),
|
),
|
||||||
Divider(),
|
Divider(),
|
||||||
SizedBox(
|
SizedBox(height: 20,width: 60,),
|
||||||
height: 20,
|
|
||||||
width: 60,
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (_isEditing) {
|
if (_isEditing) {
|
||||||
|
|
@ -286,10 +277,7 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
shadowColor: Colors.transparent, // 去除陰影
|
shadowColor: Colors.transparent, // 去除陰影
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(height: 10,width: 60,),
|
||||||
height: 10,
|
|
||||||
width: 60,
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_loginOut();
|
_loginOut();
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ 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();
|
||||||
|
|
@ -34,10 +33,6 @@ 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 {
|
||||||
|
|
@ -111,7 +106,6 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text('請輸入正確的電子信箱')),
|
SnackBar(content: Text('請輸入正確的電子信箱')),
|
||||||
);
|
);
|
||||||
_emailFocusNode.requestFocus();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,63 +114,24 @@ 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 {
|
||||||
if (!_isDataCorrect()) return;
|
// TODO: 驗證碼未實作驗證
|
||||||
final conn = await MySQLConnection.createConnection(
|
final conn = await MySQLConnection.createConnection(
|
||||||
host: '203.64.84.154',
|
host: '10.0.2.2',
|
||||||
port: 33061,
|
port: 3306,
|
||||||
userName: 'root',
|
userName: 'root',
|
||||||
password: 'Topic@2024',
|
password: '0000',
|
||||||
databaseName: 'care',
|
databaseName: 'testdb',
|
||||||
);
|
);
|
||||||
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 HomeLogin WHERE homeEmail = :email AND homePassword = :password',
|
'SELECT * FROM users WHERE email = :email AND password = :password',
|
||||||
{'email': email, 'password': password},
|
{'email': email, 'password': password},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -186,7 +141,7 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
await conn.execute(
|
await conn.execute(
|
||||||
'INSERT INTO HomeLogin (homeName, homeEmail, homePassword) VALUES (:name, :email, :password)',
|
'INSERT INTO users (name, email, password) VALUES (:name, :email, :password)',
|
||||||
{'name': name, 'email': email, 'password': password},
|
{'name': name, 'email': email, 'password': password},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -208,7 +163,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();
|
||||||
|
|
@ -217,13 +172,8 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
super.dispose();
|
|
||||||
_timer?.cancel();
|
_timer?.cancel();
|
||||||
|
super.dispose();
|
||||||
_nameFocusNode.dispose();
|
|
||||||
_emailFocusNode.dispose();
|
|
||||||
_passwordFocusNode.dispose();
|
|
||||||
_codeFocusNode.dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -257,7 +207,6 @@ 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),
|
||||||
|
|
@ -267,7 +216,6 @@ 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),
|
||||||
|
|
@ -278,7 +226,6 @@ 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),
|
||||||
|
|
@ -304,7 +251,6 @@ 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: '填寫驗證碼',
|
||||||
|
|
|
||||||
262
lib/main.dart
262
lib/main.dart
|
|
@ -5,14 +5,13 @@ 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 {
|
class LoginPage extends StatefulWidget {//ful會改變
|
||||||
@override
|
@override
|
||||||
_LoginPageState createState() => _LoginPageState();
|
_LoginPageState createState() => _LoginPageState();
|
||||||
}
|
}
|
||||||
|
|
@ -23,11 +22,10 @@ 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 {
|
||||||
|
|
@ -46,12 +44,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(
|
||||||
|
|
@ -63,12 +61,134 @@ 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',
|
||||||
|
|
@ -127,128 +247,4 @@ 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, // 去除陰影
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user