-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5afcf78
commit 6052890
Showing
2 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class UpdateDialog extends StatefulWidget { | ||
final key; | ||
final version; | ||
final Function onClickWhenDownload; | ||
final Function onClickWhenNotDownload; | ||
|
||
UpdateDialog({ | ||
this.key, | ||
this.version, | ||
this.onClickWhenDownload, | ||
this.onClickWhenNotDownload, | ||
}); | ||
|
||
@override | ||
State<StatefulWidget> createState() => new UpdateDialogState(); | ||
} | ||
|
||
class UpdateDialogState extends State<UpdateDialog> { | ||
var _downloadProgress = 0.0; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
var _textStyle = | ||
new TextStyle(color: Theme.of(context).textTheme.body1.color); | ||
|
||
return new AlertDialog( | ||
title: new Text( | ||
"有新的更新", | ||
style: _textStyle, | ||
), | ||
content: _downloadProgress == 0.0 | ||
? new Text( | ||
"版本${widget.version}", | ||
style: _textStyle, | ||
) | ||
: new LinearProgressIndicator( | ||
value: _downloadProgress, | ||
), | ||
actions: <Widget>[ | ||
new FlatButton( | ||
child: new Text( | ||
'更新', | ||
style: _textStyle, | ||
), | ||
onPressed: () { | ||
if (_downloadProgress != 0.0) { | ||
widget.onClickWhenDownload("正在更新中"); | ||
return; | ||
} | ||
widget.onClickWhenNotDownload(); | ||
// Navigator.of(context).pop(); | ||
}, | ||
), | ||
new FlatButton( | ||
child: new Text('取消'), | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
], | ||
); | ||
} | ||
|
||
set progress(_progress) { | ||
setState(() { | ||
_downloadProgress = _progress; | ||
if (_downloadProgress == 1) { | ||
Navigator.of(context).pop(); | ||
_downloadProgress = 0.0; | ||
} | ||
}); | ||
} | ||
} |