Skip to content

Instantly share code, notes, and snippets.

@tranductam2802
Created October 16, 2020 03:37
Show Gist options
  • Save tranductam2802/7c70863790397d65882566e8304804b5 to your computer and use it in GitHub Desktop.
Save tranductam2802/7c70863790397d65882566e8304804b5 to your computer and use it in GitHub Desktop.
Demo loading dialog and controll the back button pressed.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
final title = 'Ignore Pointer';
return MaterialApp(
title: title,
home: WillPopScope(
onWillPop: () async {
// Android側onBackPress()メソッド見たい。
Navigator.pop(context);
return true;
},
child: Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: Text(title),
),
body: Stack(
children: [
Center(
child: RaisedButton(
child: Text('Click me and wait snackbar'),
color: Colors.red,
textColor: Colors.yellow,
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
splashColor: Colors.grey,
onPressed: () {
_scaffoldKey.currentState.showSnackBar(
SnackBar(
content: Text('Hi, I"m coming'),
duration: Duration(seconds: 1),
),
);
},
),
),
AbsorbPointer(
absorbing: true, // ⭐︎既定な値はtrue => 変換して見てください。
child: Container(
width: double.infinity,
height: double.infinity,
child: Center(
child: Container(
width: 100,
height: 100,
child: CircularProgressIndicator(),
),
),
),
),
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment