diff --git a/lib/HistoricalRecord.dart b/lib/HistoricalRecord.dart index 20f18e5..7c711c7 100644 --- a/lib/HistoricalRecord.dart +++ b/lib/HistoricalRecord.dart @@ -1,11 +1,4 @@ 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'; class HistoricalRecord extends StatefulWidget { @@ -42,7 +35,8 @@ class _HistoricalRecordState extends State { await conn.connect(); 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.'); if (result.rows.isEmpty) { @@ -51,12 +45,12 @@ class _HistoricalRecordState extends State { setState(() { _results = result.rows .map((row) => { - '長者ID': row.colAt(0),//去裝資料庫的行數 - '姓名': row.colAt(8), - '跌倒時間': row.colAt(1), - '跌倒原因': row.colAt(2), - '跌倒地點': row.colAt(7), - }) + '長者ID': row.colAt(0), //去裝資料庫的行數 + '姓名': row.colAt(8), + '跌倒時間': row.colAt(1), + '跌倒原因': row.colAt(2), + '跌倒地點': row.colAt(7), + }) .toList(); }); } diff --git a/lib/HomePage.dart b/lib/HomePage.dart index 861c5c4..22d2095 100644 --- a/lib/HomePage.dart +++ b/lib/HomePage.dart @@ -1,7 +1,4 @@ -// import 'dart:html'; - import 'package:flutter/material.dart'; -import 'package:topic/TryPage.dart'; import 'package:webview_flutter/webview_flutter.dart'; import 'BottomNavBar.dart'; @@ -61,7 +58,6 @@ class _HomePageState extends State { height: 240, width: double.infinity, // TODO: 如果用http需要分別設定ios, android權限 - // TODO: 替換video_player to flutter_webView child: WebViewWidget( controller: WebViewController() ..setJavaScriptMode(JavaScriptMode.unrestricted) diff --git a/lib/KnowledgePage.dart b/lib/KnowledgePage.dart index 7b9c6dd..162f7d9 100644 --- a/lib/KnowledgePage.dart +++ b/lib/KnowledgePage.dart @@ -9,6 +9,7 @@ import 'package:topic/HomePage.dart'; class KnowledgePage extends StatelessWidget { final String email; // 接收來自上個頁面的 email KnowledgePage({required this.email}); + @override Widget build(BuildContext context) { return Scaffold( diff --git a/lib/MessagePage.dart b/lib/MessagePage.dart index a9cd5d2..a473e24 100644 --- a/lib/MessagePage.dart +++ b/lib/MessagePage.dart @@ -58,7 +58,6 @@ class _MessagePageState extends State { height: 240, width: double.infinity, // TODO: 如果用http需要分別設定ios, android權限 - // TODO: 替換video_player to flutter_webView child: WebViewWidget( controller: WebViewController() ..setJavaScriptMode(JavaScriptMode.unrestricted) diff --git a/lib/PersonalInfo.dart b/lib/PersonalInfo.dart index 4a32ef5..2b2ffa6 100644 --- a/lib/PersonalInfo.dart +++ b/lib/PersonalInfo.dart @@ -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:topic/NoSwipeBackRoute.dart'; import 'package:topic/main.dart'; -/*void main() { - runApp(MaterialApp( - home: PersonalInfo(), - )); -}*/ class PersonalInfo extends StatefulWidget { final String email; // 接收來自上個頁面的 email PersonalInfo({required this.email}); + @override _PersonalInfoState createState() => _PersonalInfoState(); } class _PersonalInfoState extends State { - String _name = '', _phone = '', _gender = '', _address='', _email = '', _password = ''; + String _name = '', + _phone = '', + _gender = '', + _address = '', + _email = '', + _password = ''; bool _isEditing = false; //是否為編輯狀態 final TextEditingController _nameController = TextEditingController(); final TextEditingController _phoneController = TextEditingController(); @@ -53,19 +54,20 @@ class _PersonalInfoState extends State { try { print('ok'); print('狀態:$_isEditing'); - var result = await conn.execute('SELECT * FROM HomeLogin WHERE homeemail = :email', - {'email': widget.email}, // 傳入參數 email + var result = await conn.execute( + 'SELECT * FROM HomeLogin WHERE homeemail = :email', + {'email': widget.email}, // 傳入參數 email ); if (result.rows.isNotEmpty) { //有資料 var row = result.rows.first; setState(() { - _name = row.colAt(0)??'';//如果沒有資料就是空直 - _phone = row.colAt(1)??''; - _gender = row.colAt(2)??''; - _address = row.colAt(3)??''; - _email = row.colAt(4)??''; - _password = row.colAt(5)??''; + _name = row.colAt(0) ?? ''; //如果沒有資料就是空直 + _phone = row.colAt(1) ?? ''; + _gender = row.colAt(2) ?? ''; + _address = row.colAt(3) ?? ''; + _email = row.colAt(4) ?? ''; + _password = row.colAt(5) ?? ''; }); } } catch (e) { @@ -104,16 +106,16 @@ class _PersonalInfoState extends State { try { await conn.execute( - 'UPDATE HomeLogin SET homeName = :homeName, homePhone = :homePhone, homeGender = :homeGender, homeAddress = :homeAddress, homeEmail = :new_email, homePassword = :homePassword WHERE homeEmail = :old_email', - { - 'homeName':_nameController.text, - 'homePhone': _phoneController.text, - 'homeGender': _genderController.text, - 'homeAddress': _addressController.text, - 'new_email': _emailController.text, - 'old_email': widget.email, // 用戶的舊 email 作為查找條件 - 'homePassword': _passwordController.text, - }, + 'UPDATE HomeLogin SET homeName = :homeName, homePhone = :homePhone, homeGender = :homeGender, homeAddress = :homeAddress, homeEmail = :new_email, homePassword = :homePassword WHERE homeEmail = :old_email', + { + 'homeName': _nameController.text, + 'homePhone': _phoneController.text, + 'homeGender': _genderController.text, + 'homeAddress': _addressController.text, + 'new_email': _emailController.text, + 'old_email': widget.email, // 用戶的舊 email 作為查找條件 + 'homePassword': _passwordController.text, + }, ); setState(() { _name = _nameController.text; @@ -171,7 +173,8 @@ class _PersonalInfoState extends State { children: [ Container( height: 100, - color: Color(0xFFF5E3C3),//背景底色 + color: Color(0xFFF5E3C3), + //背景底色 width: double.infinity, padding: EdgeInsets.all(10.0), child: Center( @@ -187,7 +190,10 @@ class _PersonalInfoState extends State { children: [ ListTile( - title: Text('姓名',style: TextStyle(fontSize: 20),), + title: Text( + '姓名', + style: TextStyle(fontSize: 20), + ), subtitle: Text(_name), ), Divider(), @@ -195,13 +201,13 @@ class _PersonalInfoState extends State { title: Text('手機'), subtitle: _isEditing ? TextField( - controller: _phoneController, - onChanged: (value) { - setState(() { - _phone = value; - }); - }, - ) + controller: _phoneController, + onChanged: (value) { + setState(() { + _phone = value; + }); + }, + ) : Text(_phone), ), Divider(), @@ -209,13 +215,13 @@ class _PersonalInfoState extends State { title: Text('性別'), subtitle: _isEditing ? TextField( - controller: _genderController, - onChanged: (value) { - setState(() { - _gender = value; - }); - }, - ) + controller: _genderController, + onChanged: (value) { + setState(() { + _gender = value; + }); + }, + ) : Text(_gender), ), Divider(), @@ -223,13 +229,13 @@ class _PersonalInfoState extends State { title: Text('地址'), subtitle: _isEditing ? TextField( - controller: _addressController, - onChanged: (value) { - setState(() { - _address = value; - }); - }, - ) + controller: _addressController, + onChanged: (value) { + setState(() { + _address = value; + }); + }, + ) : Text(_address), ), Divider(), @@ -237,13 +243,13 @@ class _PersonalInfoState extends State { title: Text('電子信箱'), subtitle: _isEditing ? TextField( - controller: _emailController, - onChanged: (value) { - setState(() { - _email = value; - }); - }, - ) + controller: _emailController, + onChanged: (value) { + setState(() { + _email = value; + }); + }, + ) : Text(_email), ), Divider(), @@ -251,23 +257,26 @@ class _PersonalInfoState extends State { title: Text('密碼'), subtitle: _isEditing ? TextField( - controller: _passwordController, - onChanged: (value) { - setState(() { - _password = value; - }); - }, - ) + controller: _passwordController, + onChanged: (value) { + setState(() { + _password = value; + }); + }, + ) : Text(_password), ), Divider(), - SizedBox(height: 20,width: 60,), + SizedBox( + height: 20, + width: 60, + ), ElevatedButton( onPressed: () { if (_isEditing) { - _saveChanges(); // 儲存變更 + _saveChanges(); // 儲存變更 } else { - _toggleEdit(); // 進入編輯模式 + _toggleEdit(); // 進入編輯模式 } }, child: Text(_isEditing ? '儲存變更' : '修改資料'), @@ -277,7 +286,10 @@ class _PersonalInfoState extends State { shadowColor: Colors.transparent, // 去除陰影 ), ), - SizedBox(height: 10,width: 60,), + SizedBox( + height: 10, + width: 60, + ), ElevatedButton( onPressed: () { _loginOut(); diff --git a/lib/RegisterPage.dart b/lib/RegisterPage.dart index 63295b8..22ee608 100644 --- a/lib/RegisterPage.dart +++ b/lib/RegisterPage.dart @@ -126,7 +126,7 @@ class _RegisterPageState extends State { String password = _passwordController.text; String code = _codeController.text; - if (name == ''){ + if (name == '') { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('用戶姓名不可為空')), ); @@ -134,7 +134,7 @@ class _RegisterPageState extends State { return false; } - if (email == ''){ + if (email == '') { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('電子信箱不可為空')), ); @@ -142,7 +142,7 @@ class _RegisterPageState extends State { return false; } - if (password== ''){ + if (password == '') { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('密碼不可為空')), ); @@ -150,7 +150,7 @@ class _RegisterPageState extends State { return false; } - if (code != _generatedCode){ + if (code != _generatedCode) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('驗證碼錯誤')), ); @@ -208,7 +208,7 @@ class _RegisterPageState extends State { } catch (e) { print('資料庫錯誤: $e'); ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('登入失敗:系統錯誤')), + SnackBar(content: Text('註冊失敗:系統錯誤')), ); } finally { await conn.close(); @@ -288,7 +288,7 @@ class _RegisterPageState extends State { : Icons.visibility_off), onPressed: () { setState( - () { + () { _passwordNotVisible = !_passwordNotVisible; }, ); diff --git a/lib/main.dart b/lib/main.dart index 75accbc..8b26d2f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,13 +5,14 @@ import 'package:topic/HomePage.dart'; import 'package:mysql_client/mysql_client.dart'; import 'package:topic/NoSwipeBackRoute.dart'; import 'package:topic/RegisterPage.dart'; + void main() { runApp(MaterialApp( home: LoginPage(), )); } -class LoginPage extends StatefulWidget {//ful會改變 +class LoginPage extends StatefulWidget { @override _LoginPageState createState() => _LoginPageState(); } @@ -22,10 +23,11 @@ class _LoginPageState extends State { bool _passwordNotVisible = true; @override - void initState() {//初始化 + void initState() { + //初始化 super.initState(); - _fetchData();//連資料庫 - _CheckPreLoginInfo();//確定有先前有無登入 + _fetchData(); //連資料庫 + _CheckPreLoginInfo(); //確定有先前有無登入 } void _fetchData() async { @@ -44,12 +46,12 @@ class _LoginPageState extends State { await conn.connect(); } - void _CheckPreLoginInfo() async{ + void _CheckPreLoginInfo() async { SharedPreferences prefs = await SharedPreferences.getInstance(); //get user data from share preference else set empty to check not login before String loginUserEmail = prefs.getString("email") ?? ""; //replace screen to HomePage if there are previous data in share preference - if(loginUserEmail != ""){ + if (loginUserEmail != "") { Navigator.pushReplacement( context, NoSwipeBackRoute( @@ -61,134 +63,12 @@ class _LoginPageState extends State { } } - void _setLoginInfo(String email) async{ + void _setLoginInfo(String email) async { //save user email into share preference to let app can auto login next open SharedPreferences prefs = await SharedPreferences.getInstance(); 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 { final conn = await MySQLConnection.createConnection( host: '203.64.84.154', @@ -247,4 +127,128 @@ class _LoginPageState extends State { await conn.close(); } } -} \ No newline at end of file + + @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, // 去除陰影 + ), + ), + ], + ), + ), + ), + ), + ), + ), + ); + } +}