fix: 修正安卓用戶使用返回鍵退回不正當頁面
This commit is contained in:
@@ -29,95 +29,98 @@ class _HomePageState extends State<HomePage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 100,
|
||||
// APPBar height
|
||||
color: Color(0xFFF5E3C3),
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.all(10.0),
|
||||
child: Stack(children: [
|
||||
Container(
|
||||
padding: EdgeInsets.only(
|
||||
left: MediaQuery.of(context).size.width,
|
||||
top: MediaQuery.of(context).size.height / 2,
|
||||
return PopScope(
|
||||
child: Scaffold(
|
||||
body: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 100,
|
||||
// APPBar height
|
||||
color: Color(0xFFF5E3C3),
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.all(10.0),
|
||||
child: Stack(children: [
|
||||
Container(
|
||||
padding: EdgeInsets.only(
|
||||
left: MediaQuery.of(context).size.width,
|
||||
top: MediaQuery.of(context).size.height / 2,
|
||||
),
|
||||
child: Icon(Icons.settings, size: 48, color: Colors.orange),
|
||||
),
|
||||
child: Icon(Icons.settings, size: 48, color: Colors.orange),
|
||||
),
|
||||
Center(
|
||||
child: Text(
|
||||
'全方位照護守護者',
|
||||
style: TextStyle(fontSize: 24, height: 5),
|
||||
Center(
|
||||
child: Text(
|
||||
'全方位照護守護者',
|
||||
style: TextStyle(fontSize: 24, height: 5),
|
||||
),
|
||||
),
|
||||
),
|
||||
])),
|
||||
Container(
|
||||
color: Color(0xFFFFF0E0),
|
||||
margin: EdgeInsets.only(top: 5),
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 240,
|
||||
width: double.infinity,
|
||||
// TODO: 如果用http需要分別設定ios, android權限
|
||||
// TODO: 替換video_player to flutter_webView
|
||||
child: WebViewWidget(
|
||||
controller: WebViewController()
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||
..setNavigationDelegate(
|
||||
NavigationDelegate(
|
||||
onProgress: (int progress) {
|
||||
// Update loading bar.
|
||||
},
|
||||
onPageStarted: (String url) {},
|
||||
onPageFinished: (String url) {},
|
||||
onHttpError: (HttpResponseError error) {
|
||||
print("httpError");
|
||||
},
|
||||
onWebResourceError: (WebResourceError error) {
|
||||
print("httpResourceError");
|
||||
print(error.description);
|
||||
},
|
||||
onNavigationRequest: (NavigationRequest request) {
|
||||
if (request.url.startsWith(
|
||||
'http://203.64.84.154:8088/video_feed')) {
|
||||
return NavigationDecision.prevent;
|
||||
}
|
||||
return NavigationDecision.navigate;
|
||||
},
|
||||
),
|
||||
)
|
||||
..loadRequest(Uri.parse('http://203.64.84.154:8088')),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'即時畫面',
|
||||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: GridView.count(
|
||||
crossAxisCount: 2,
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
])),
|
||||
Container(
|
||||
color: Color(0xFFFFF0E0),
|
||||
margin: EdgeInsets.only(top: 5),
|
||||
padding: EdgeInsets.all(16),
|
||||
children: [
|
||||
_buildGridItem(Icons.history_edu, '跌倒紀錄', context),
|
||||
_buildGridItem(Icons.lightbulb_outline, '知識補充', context),
|
||||
_buildGridItem(Icons.monitor_outlined, '切換畫面', context),
|
||||
_buildGridItem(Icons.person_sharp, '個人資料', context),
|
||||
],
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 240,
|
||||
width: double.infinity,
|
||||
// TODO: 如果用http需要分別設定ios, android權限
|
||||
// TODO: 替換video_player to flutter_webView
|
||||
child: WebViewWidget(
|
||||
controller: WebViewController()
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||
..setNavigationDelegate(
|
||||
NavigationDelegate(
|
||||
onProgress: (int progress) {
|
||||
// Update loading bar.
|
||||
},
|
||||
onPageStarted: (String url) {},
|
||||
onPageFinished: (String url) {},
|
||||
onHttpError: (HttpResponseError error) {
|
||||
print("httpError");
|
||||
},
|
||||
onWebResourceError: (WebResourceError error) {
|
||||
print("httpResourceError");
|
||||
print(error.description);
|
||||
},
|
||||
onNavigationRequest: (NavigationRequest request) {
|
||||
if (request.url.startsWith(
|
||||
'http://203.64.84.154:8088/video_feed')) {
|
||||
return NavigationDecision.prevent;
|
||||
}
|
||||
return NavigationDecision.navigate;
|
||||
},
|
||||
),
|
||||
)
|
||||
..loadRequest(Uri.parse('http://203.64.84.154:8088')),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'即時畫面',
|
||||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
Expanded(
|
||||
child: GridView.count(
|
||||
crossAxisCount: 2,
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
padding: EdgeInsets.all(16),
|
||||
children: [
|
||||
_buildGridItem(Icons.history_edu, '跌倒紀錄', context),
|
||||
_buildGridItem(Icons.lightbulb_outline, '知識補充', context),
|
||||
_buildGridItem(Icons.monitor_outlined, '切換畫面', context),
|
||||
_buildGridItem(Icons.person_sharp, '個人資料', context),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
canPop: false,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
190
lib/main.dart
190
lib/main.dart
@@ -69,107 +69,111 @@ class _LoginPageState extends State<LoginPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
debugPaintSizeEnabled=false;
|
||||
return 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), // 設置圖標颜色
|
||||
//by use PopScope and disable can Pop avoid android user pop back by back button
|
||||
return PopScope(
|
||||
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,
|
||||
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),
|
||||
labelText: '密碼',
|
||||
),
|
||||
obscureText: true,
|
||||
),//密碼
|
||||
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, // 去除陰影
|
||||
),
|
||||
),
|
||||
),//全方位照護守護者
|
||||
SizedBox(height: 20),
|
||||
TextField(
|
||||
controller: _emailController, // 绑定電子信箱输入框的控制器
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.email_outlined),//https://www.fluttericon.cn/v
|
||||
labelText: '電子信箱',
|
||||
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, // 去除陰影
|
||||
),
|
||||
),
|
||||
),//電子信箱
|
||||
SizedBox(height: 20),
|
||||
TextField(
|
||||
controller: _ageController,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.lock_outlined),
|
||||
labelText: '密碼',
|
||||
),
|
||||
obscureText: true,
|
||||
),//密碼
|
||||
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, // 去除陰影
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
canPop: false,
|
||||
);
|
||||
}
|
||||
void loginBtn() async {
|
||||
|
||||
Reference in New Issue
Block a user