@@ -2,14 +2,17 @@ import 'dart:convert';
22import 'dart:math' ;
33import 'dart:ui' ;
44
5+ import 'package:flutter/cupertino.dart' ;
56import 'package:flutter/material.dart' ;
67import 'package:flutter/services.dart' ;
78import 'package:flutter_markdown/flutter_markdown.dart' ;
89import 'package:pub_semver/pub_semver.dart' ;
910import 'package:sentinelx/channels/api_channel.dart' ;
1011import 'package:sentinelx/channels/system_channel.dart' ;
12+ import 'package:sentinelx/models/db/prefs_store.dart' ;
1113import 'package:sentinelx/shared_state/app_state.dart' ;
1214import 'package:sentinelx/widgets/appbar_bottom_progress.dart' ;
15+ import 'package:sentinelx/widgets/circular_check_box.dart' ;
1316import 'package:sentinelx/widgets/confirm_modal.dart' ;
1417
1518class UpdateCheck extends StatefulWidget {
@@ -26,6 +29,7 @@ class _UpdateCheckState extends State<UpdateCheck> {
2629 bool isUpToDate = false ;
2730 List <Assets > downloadAssets = [];
2831 GlobalKey <ScaffoldState > _scaffoldKey = GlobalKey ();
32+ bool showUpdateNotification = false ;
2933
3034 @override
3135 Widget build (BuildContext context) {
@@ -44,11 +48,37 @@ class _UpdateCheckState extends State<UpdateCheck> {
4448 title: Text ("Version: $version " ),
4549 subtitle: Text ("Build: $buildNumber " , style: Theme .of (context).textTheme.caption),
4650 ),
51+ Divider (),
4752 ListTile (
4853 onTap: this .checkVersion,
4954 title: Text ("Check for Update" ),
5055 subtitle: Text ("This action will use github api to check new releases" , style: Theme .of (context).textTheme.caption),
5156 ),
57+ Divider (),
58+ ListTile (
59+ onTap: () async {
60+ bool val = ! showUpdateNotification;
61+ await PrefsStore ().put (PrefsStore .SHOW_UPDATE_NOTIFICATION , val);
62+ setState (() {
63+ showUpdateNotification = val;
64+ });
65+ },
66+ title: Text ("Notify new updates" ),
67+ trailing: Switch (
68+ value: showUpdateNotification,
69+ onChanged: (val) async {
70+ await PrefsStore ().put (PrefsStore .SHOW_UPDATE_NOTIFICATION , val);
71+ setState (() {
72+ showUpdateNotification = val;
73+ });
74+ },
75+ ),
76+ subtitle: Text (
77+ "Show notification when new update released.\n "
78+ "note: app will only check updates every start up" ,
79+ style: Theme .of (context).textTheme.caption),
80+ ),
81+ Divider (),
5282 ListTile (
5383 onTap: () async {
5484 await SystemChannel ().openURL ("https://github.com/InvertedX/sentinelx" );
@@ -58,7 +88,19 @@ class _UpdateCheckState extends State<UpdateCheck> {
5888 style: Theme .of (context).textTheme.subhead,
5989 ),
6090 subtitle: Text ("github.com/InvertedX/sentinelx" , style: Theme .of (context).textTheme.caption),
61- )
91+ ),
92+ (changeLog.isNotEmpty && downloadAssets.length == 0 )
93+ ? ListTile (
94+ onTap: () async {
95+ this .showChangeLog (version);
96+ },
97+ title: Text (
98+ "Show Change Log" ,
99+ style: Theme .of (context).textTheme.subhead,
100+ ),
101+ subtitle: Text ("View current change log" , style: Theme .of (context).textTheme.caption),
102+ )
103+ : SizedBox .shrink ()
62104 ]),
63105 ),
64106 SliverToBoxAdapter (
@@ -111,7 +153,7 @@ class _UpdateCheckState extends State<UpdateCheck> {
111153 "Open change log" ,
112154 style: Theme .of (context).textTheme.subtitle,
113155 ),
114- onTap: this .showChangeLog,
156+ onTap: () => this .showChangeLog (newVersion) ,
115157 ),
116158 Divider (
117159 thickness: 2 ,
@@ -126,17 +168,17 @@ class _UpdateCheckState extends State<UpdateCheck> {
126168 children: < Widget > [
127169 Divider (),
128170 Padding (
129- padding: EdgeInsets .all (12 ),
171+ padding: EdgeInsets .all (9 ),
130172 ),
131173 ClipRRect (
132174 child: Container (
133175 child: Icon (
134176 Icons .check,
135177 color: Colors .white,
136- size: 24 ,
178+ size: 22 ,
137179 ),
138180 padding: EdgeInsets .all (12 ),
139- color: Colors .greenAccent[700 ],
181+ color: Colors .greenAccent[700 ]. withOpacity ( 0.8 ) ,
140182 ),
141183 borderRadius: BorderRadius .circular (50 ),
142184 ),
@@ -168,10 +210,13 @@ class _UpdateCheckState extends State<UpdateCheck> {
168210
169211 void init () async {
170212 Map <String , dynamic > packageInfo = await SystemChannel ().getPackageInfo ();
213+ bool enabledNotifications = await PrefsStore ().getBool (PrefsStore .SHOW_UPDATE_NOTIFICATION , defaultValue: true );
171214 setState (() {
172215 version = packageInfo["version" ];
216+ showUpdateNotification = enabledNotifications;
173217 buildNumber = packageInfo['buildNumber' ];
174218 });
219+ checkVersion ();
175220 }
176221
177222 void checkVersion () async {
@@ -245,14 +290,15 @@ class _UpdateCheckState extends State<UpdateCheck> {
245290 }
246291 }
247292
248- void showChangeLog () {
293+ void showChangeLog (String version) {
294+ String log = "## version $version \n\n ${changeLog }" ;
249295 showModalBottomSheet (
250296 context: context,
251297 builder: (context) {
252298 return Card (
253299 child: Container (
254300 child: Markdown (
255- data: changeLog ,
301+ data: log ,
256302 ),
257303 ),
258304 );
0 commit comments