fix: 修正安卓用戶使用返回鍵退回不正當頁面
This commit is contained in:
parent
939d8ddef0
commit
dc1a6534bc
|
|
@ -29,95 +29,98 @@ class _HomePageState extends State<HomePage> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return PopScope(
|
||||||
body: Center(
|
child: Scaffold(
|
||||||
child: Column(
|
body: Center(
|
||||||
children: [
|
child: Column(
|
||||||
Container(
|
children: [
|
||||||
height: 100,
|
Container(
|
||||||
// APPBar height
|
height: 100,
|
||||||
color: Color(0xFFF5E3C3),
|
// APPBar height
|
||||||
width: double.infinity,
|
color: Color(0xFFF5E3C3),
|
||||||
padding: EdgeInsets.all(10.0),
|
width: double.infinity,
|
||||||
child: Stack(children: [
|
padding: EdgeInsets.all(10.0),
|
||||||
Container(
|
child: Stack(children: [
|
||||||
padding: EdgeInsets.only(
|
Container(
|
||||||
left: MediaQuery.of(context).size.width,
|
padding: EdgeInsets.only(
|
||||||
top: MediaQuery.of(context).size.height / 2,
|
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(
|
||||||
Center(
|
'全方位照護守護者',
|
||||||
child: Text(
|
style: TextStyle(fontSize: 24, height: 5),
|
||||||
'全方位照護守護者',
|
),
|
||||||
style: TextStyle(fontSize: 24, height: 5),
|
|
||||||
),
|
),
|
||||||
),
|
])),
|
||||||
])),
|
Container(
|
||||||
Container(
|
color: Color(0xFFFFF0E0),
|
||||||
color: Color(0xFFFFF0E0),
|
margin: EdgeInsets.only(top: 5),
|
||||||
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(),
|
|
||||||
padding: EdgeInsets.all(16),
|
padding: EdgeInsets.all(16),
|
||||||
children: [
|
child: Column(
|
||||||
_buildGridItem(Icons.history_edu, '跌倒紀錄', context),
|
children: [
|
||||||
_buildGridItem(Icons.lightbulb_outline, '知識補充', context),
|
Container(
|
||||||
_buildGridItem(Icons.monitor_outlined, '切換畫面', context),
|
height: 240,
|
||||||
_buildGridItem(Icons.person_sharp, '個人資料', context),
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
debugPaintSizeEnabled=false;
|
debugPaintSizeEnabled=false;
|
||||||
return Scaffold(
|
//by use PopScope and disable can Pop avoid android user pop back by back button
|
||||||
//appBar: AppBar(
|
return PopScope(
|
||||||
//title: Text('Demo'),
|
child: Scaffold(
|
||||||
//backgroundColor: Color(0xFF81D4FA),
|
//appBar: AppBar(
|
||||||
//),
|
//title: Text('Demo'),
|
||||||
body: SafeArea(
|
//backgroundColor: Color(0xFF81D4FA),
|
||||||
child: Center(
|
//),
|
||||||
child: SingleChildScrollView(
|
body: SafeArea(
|
||||||
child: Padding(
|
child: Center(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 32.0),
|
child: SingleChildScrollView(
|
||||||
child: Column(
|
child: Padding(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
padding: const EdgeInsets.symmetric(horizontal: 32.0),
|
||||||
children: [
|
child: Column(
|
||||||
Container(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
margin: EdgeInsets.only(bottom: 40), // 添加間距
|
children: [
|
||||||
height: 100, // 設置logo高度
|
Container(
|
||||||
child: Icon(
|
margin: EdgeInsets.only(bottom: 40), // 添加間距
|
||||||
Icons.account_circle,
|
height: 100, // 設置logo高度
|
||||||
size: 100, // 設置圖標大小
|
child: Icon(
|
||||||
color: Color(0xFF4FC3F7), // 設置圖標颜色
|
Icons.account_circle,
|
||||||
|
size: 100, // 設置圖標大小
|
||||||
|
color: Color(0xFF4FC3F7), // 設置圖標颜色
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
Text(
|
||||||
Text(
|
'全方位照護守護者',
|
||||||
'全方位照護守護者',
|
style: TextStyle(
|
||||||
style: TextStyle(
|
fontSize: 32,
|
||||||
fontSize: 32,
|
fontWeight: FontWeight.bold,
|
||||||
fontWeight: FontWeight.bold,
|
color: Colors.black,
|
||||||
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, // 去除陰影
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),//全方位照護守護者
|
ElevatedButton(
|
||||||
SizedBox(height: 20),
|
onPressed: () {
|
||||||
TextField(
|
Navigator.push(
|
||||||
controller: _emailController, // 绑定電子信箱输入框的控制器
|
context,
|
||||||
decoration: InputDecoration(
|
MaterialPageRoute(builder: (context) => HomePage(
|
||||||
border: OutlineInputBorder(),
|
email: _emailController.text,
|
||||||
prefixIcon: Icon(Icons.email_outlined),//https://www.fluttericon.cn/v
|
)),
|
||||||
labelText: '電子信箱',
|
);
|
||||||
|
},
|
||||||
|
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 {
|
void loginBtn() async {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user