11import 'package:flutter/material.dart' ;
2+ import 'package:memno/functionality/check_update.dart' ;
23import 'package:memno/theme/app_colors.dart' ;
34import 'package:provider/provider.dart' ;
5+ import 'package:url_launcher/url_launcher.dart' ;
6+ import 'package:package_info_plus/package_info_plus.dart' ;
47
58class SettingsPage extends StatelessWidget {
69 const SettingsPage ({super .key});
710
11+ void _showDialog (
12+ BuildContext context, String title, String content, AppColors colors) {
13+ showDialog (
14+ context: context,
15+ builder: (context) => AlertDialog (
16+ backgroundColor: colors.box,
17+ title: Text (title,
18+ style: TextStyle (
19+ fontFamily: 'Product' , fontSize: 20 , color: colors.textClr)),
20+ content: Text (content,
21+ style: TextStyle (
22+ fontFamily: 'Product' , fontSize: 18 , color: colors.textClr)),
23+ actions: [
24+ TextButton (
25+ onPressed: () {
26+ Navigator .of (context).pop ();
27+ },
28+ child: Text (
29+ "OK" ,
30+ style: TextStyle (
31+ fontFamily: 'Product' , fontSize: 16 , color: colors.textClr),
32+ ),
33+ ),
34+ ],
35+ ),
36+ );
37+ }
38+
839 @override
940 Widget build (BuildContext context) {
1041 final colors = Provider .of <AppColors >(context);
@@ -18,22 +49,9 @@ class SettingsPage extends StatelessWidget {
1849 ),
1950 body: ListView (
2051 children: [
21- Padding (
22- padding: const EdgeInsets .fromLTRB (32 , 16 , 0 , 16 ),
23- child: Text ("Settings" ,
24- style: TextStyle (
25- fontFamily: 'Product' ,
26- fontSize: 28 ,
27- color: colors.textClr)),
28- ),
29- Container (
30- height: 100 ,
31- padding: const EdgeInsets .all (16 ),
32- margin: const EdgeInsets .fromLTRB (2 , 4 , 2 , 4 ),
33- alignment: Alignment .center,
34- decoration: BoxDecoration (
35- borderRadius: BorderRadius .circular (50 ), color: colors.box),
36- child: SwitchListTile (
52+ settingsTitle ("Settings" , colors),
53+ settingsContainer (
54+ SwitchListTile (
3755 title: Text ("Dark Mode" ,
3856 style: TextStyle (
3957 fontFamily: 'Product' ,
@@ -44,9 +62,109 @@ class SettingsPage extends StatelessWidget {
4462 await colors.toggleTheme ();
4563 },
4664 ),
65+ colors,
4766 ),
67+ settingsTitle ("About" , colors),
68+ settingsContainer (
69+ ListTile (
70+ onTap: () async {
71+ final info = await PackageInfo .fromPlatform ();
72+ final currVer = info.version;
73+ if (currVer.isEmpty) {
74+ _showDialog (
75+ context.mounted ? context : context,
76+ "Version Check Failed" ,
77+ "Could not retrieve current version." ,
78+ colors);
79+ return ;
80+ }
81+ // Get latest release data from GitHub
82+ final release = await getLatestGitHubRelease ();
83+ if (release == null ) {
84+ _showDialog (
85+ context.mounted ? context : context,
86+ "Update Check Failed" ,
87+ "Could not check for updates." ,
88+ colors);
89+ return ;
90+ }
91+
92+ final latestVer = release['tag_name' ]
93+ as String ; // Obtain latest version on GitHub
94+ final browserUrl = release['assets' ][0 ]
95+ ['browser_download_url' ]
96+ as String ; // Obtain download link for the latest version
97+ if (browserUrl.isEmpty || latestVer.isEmpty) {
98+ _showDialog (
99+ context.mounted ? context : context,
100+ "Update Check Failed" ,
101+ "Could not find download link for the latest version." ,
102+ colors);
103+ return ;
104+ }
105+ if (isNewerVersion (latestVer, currVer)) {
106+ _showDialog (
107+ context.mounted ? context : context,
108+ "Update Available" ,
109+ "A new version ($latestVer ) is available. Please update to enjoy the latest features." ,
110+ colors);
111+ } else {
112+ _showDialog (
113+ context.mounted ? context : context,
114+ "No Updates" ,
115+ "You are using the latest version ($currVer )." ,
116+ colors);
117+ }
118+ },
119+ trailing: Icon (Icons .file_download_outlined,
120+ color: colors.textClr),
121+ title: Text (
122+ "Check for updates" ,
123+ style: TextStyle (
124+ fontFamily: 'Product' ,
125+ fontSize: 18 ,
126+ color: colors.textClr),
127+ )),
128+ colors),
129+ settingsContainer (
130+ ListTile (
131+ onTap: () {
132+ launchUrl (
133+ Uri .parse ("https://github.com/jydv402/memno" ));
134+ },
135+ trailing: Icon (Icons .arrow_outward_rounded,
136+ color: colors.textClr),
137+ title: Text (
138+ "Find us on GitHub" ,
139+ style: TextStyle (
140+ fontFamily: 'Product' ,
141+ fontSize: 18 ,
142+ color: colors.textClr),
143+ )),
144+ colors),
48145 ],
49146 )),
50147 );
51148 }
149+
150+ Padding settingsTitle (String title, AppColors colors) {
151+ return Padding (
152+ padding: const EdgeInsets .fromLTRB (32 , 16 , 0 , 16 ),
153+ child: Text (title,
154+ style: TextStyle (
155+ fontFamily: 'Product' , fontSize: 28 , color: colors.textClr)),
156+ );
157+ }
158+
159+ Container settingsContainer (Widget child, AppColors colors) {
160+ return Container (
161+ height: 100 ,
162+ padding: const EdgeInsets .all (16 ),
163+ margin: const EdgeInsets .fromLTRB (2 , 4 , 2 , 4 ),
164+ alignment: Alignment .center,
165+ decoration: BoxDecoration (
166+ borderRadius: BorderRadius .circular (50 ), color: colors.box),
167+ child: child,
168+ );
169+ }
52170}
0 commit comments