fix: 修正安卓用戶使用返回鍵退回不正當頁面

This commit is contained in:
JingChiang 2024-09-03 01:24:05 +08:00
parent 939d8ddef0
commit dc1a6534bc
2 changed files with 183 additions and 176 deletions

View File

@ -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,
); );
} }

View File

@ -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 {