import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:http/http.dart' as http; class AboutPage extends StatefulWidget { const AboutPage({super.key}); @override State createState() => _AboutPageState(); } class _AboutPageState extends State { final String _currentVersion = '0.9.8-beta.2'; bool _isChecking = false; Future _checkUpdate() async { setState(() => _isChecking = true); try { final response = await http .get( Uri.parse( 'https://api.github.com/repos/Ujwal223/FocusGram/releases/latest', ), ) .timeout(const Duration(seconds: 10)); if (response.statusCode == 200) { final data = json.decode(response.body); final latestVersion = data['tag_name'].toString().replaceAll('v', ''); final downloadUrl = data['html_url']; if (latestVersion != _currentVersion) { _showUpdateDialog(latestVersion, downloadUrl); } else { _showSnackBar('You are up to date! 🎉'); } } else { _showSnackBar('Could not check for updates.'); } } catch (_) { _showSnackBar('Connectivity issue. Try again later.'); } finally { if (mounted) setState(() => _isChecking = false); } } void _showUpdateDialog(String version, String url) { showDialog( context: context, builder: (ctx) => AlertDialog( backgroundColor: const Color(0xFF1A1A1A), title: const Text( 'Update Available!', style: TextStyle(color: Colors.white), ), content: Text( 'A new version ($version) is available on GitHub.', style: const TextStyle(color: Colors.white70), ), actions: [ TextButton( onPressed: () => Navigator.pop(ctx), child: const Text('Later', style: TextStyle(color: Colors.white38)), ), ElevatedButton( onPressed: () { Navigator.pop(ctx); _launchURL(url); }, style: ElevatedButton.styleFrom(backgroundColor: Colors.blue), child: const Text('Download'), ), ], ), ); } void _showSnackBar(String msg) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text(msg), duration: const Duration(seconds: 2)), ); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.black, appBar: AppBar( backgroundColor: Colors.black, title: const Text( 'About FocusGram', style: TextStyle(fontSize: 17, fontWeight: FontWeight.bold), ), leading: IconButton( icon: const Icon(Icons.arrow_back_ios_new, size: 18), onPressed: () => Navigator.pop(context), ), ), body: Center( child: Padding( padding: const EdgeInsets.symmetric(horizontal: 40.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( width: 100, height: 100, decoration: BoxDecoration( color: Colors.blue.withValues(alpha: 0.1), shape: BoxShape.circle, ), child: ClipOval( child: Image.asset( 'assets/images/focusgram.png', width: 60, height: 60, fit: BoxFit.cover, ), ), ), const SizedBox(height: 24), const Text( 'FocusGram', style: TextStyle( color: Colors.white, fontSize: 24, fontWeight: FontWeight.bold, ), ), const SizedBox(height: 8), Text( 'Version $_currentVersion', style: const TextStyle(color: Colors.white38, fontSize: 13), ), const SizedBox(height: 40), const Text( 'Developed with passion for digital discipline by', textAlign: TextAlign.center, style: TextStyle(color: Colors.white70, fontSize: 14), ), const SizedBox(height: 4), const Text( 'Ujwal Chapagain', style: TextStyle( color: Colors.white, fontSize: 16, fontWeight: FontWeight.w600, ), ), const SizedBox(height: 40), ElevatedButton.icon( onPressed: _isChecking ? null : _checkUpdate, icon: _isChecking ? const SizedBox( width: 14, height: 14, child: CircularProgressIndicator( strokeWidth: 2, color: Colors.white, ), ) : const Icon(Icons.update), label: Text(_isChecking ? 'Checking...' : 'Check for Update'), style: ElevatedButton.styleFrom( backgroundColor: Colors.blueAccent.withValues(alpha: 0.2), foregroundColor: Colors.white, minimumSize: const Size(200, 45), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), ), ), const SizedBox(height: 16), ElevatedButton.icon( onPressed: () => _launchURL('https://github.com/Ujwal223/FocusGram'), icon: const Icon(Icons.code), label: const Text('View on GitHub'), style: ElevatedButton.styleFrom( backgroundColor: Colors.white10, foregroundColor: Colors.white, minimumSize: const Size(200, 45), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), ), ), const SizedBox(height: 20), const Text( 'FocusGram is not affiliated with Instagram.', style: TextStyle( color: Color.fromARGB(48, 255, 255, 255), fontSize: 10, ), ), ], ), ), ), ); } Future _launchURL(String url) async { final uri = Uri.tryParse(url); if (uri == null) return; try { await launchUrl(uri, mode: LaunchMode.externalApplication); } catch (_) {} } }