UpdateDialog.dart 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import 'package:flutter/material.dart';
  2. class UpdateDialog extends StatefulWidget {
  3. final key;
  4. final version;
  5. final Function onClickWhenDownload;
  6. final Function onClickWhenNotDownload;
  7. UpdateDialog(
  8. this.key,
  9. this.version,
  10. this.onClickWhenDownload,
  11. this.onClickWhenNotDownload,
  12. );
  13. @override
  14. State<StatefulWidget> createState() => UpdateDialogState();
  15. }
  16. class UpdateDialogState extends State<UpdateDialog> {
  17. var _downloadProgress = 0.0;
  18. @override
  19. Widget build(BuildContext context) {
  20. var _textStyle = TextStyle(color: Theme.of(context).textTheme.body1.color);
  21. return AlertDialog(
  22. title: Text(
  23. "有新的更新",
  24. style: _textStyle,
  25. ),
  26. content: _downloadProgress == 0.0
  27. ? Text(
  28. "版本${widget.version}",
  29. style: _textStyle,
  30. )
  31. : LinearProgressIndicator(
  32. value: _downloadProgress,
  33. ),
  34. actions: <Widget>[
  35. FlatButton(
  36. child: Text(
  37. '更新',
  38. style: _textStyle,
  39. ),
  40. onPressed: () {
  41. if (_downloadProgress != 0.0) {
  42. widget.onClickWhenDownload("正在更新中");
  43. return;
  44. }
  45. widget.onClickWhenNotDownload();
  46. // Navigator.of(context).pop();
  47. },
  48. ),
  49. FlatButton(
  50. child: new Text('取消'),
  51. onPressed: () {
  52. Navigator.of(context).pop();
  53. },
  54. ),
  55. ],
  56. );
  57. }
  58. set progress(_progress) {
  59. setState(() {
  60. _downloadProgress = _progress;
  61. if (_downloadProgress == 1) {
  62. Navigator.of(context).pop();
  63. _downloadProgress = 0.0;
  64. }
  65. });
  66. }
  67. }