Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
FarzinNs83 committed Oct 1, 2024
1 parent 5d474eb commit e06781c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 86 deletions.
2 changes: 1 addition & 1 deletion lib/view/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class _HomePageState extends State<HomePage> {
}
},
),
const SettingsPage(),
SettingsPage(),
];
}

Expand Down
125 changes: 40 additions & 85 deletions lib/view/settings_page.dart
Original file line number Diff line number Diff line change
@@ -1,67 +1,10 @@
// ignore_for_file: deprecated_member_use

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:dns_changer/theme/theme_provider.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:url_launcher/url_launcher.dart';

class SettingsPage extends StatelessWidget {
const SettingsPage({super.key});


Future<bool> _checkForUpdate() async {
const apiUrl =
'https://api.mrsf.ir/api/update/check/?id=1005';

try {
final response = await http.get(Uri.parse(apiUrl));

if (response.statusCode == 200) {
final responseData = jsonDecode(response.body);
if (responseData['updateAvailable'] == true) {
return true;
}
}
} catch (e) {
debugPrint('Error checking for update: $e');
}

return false;
}


Future<String?> _getDownloadLink() async {
const apiUrl =
'https://api.mrsf.ir/api/update/download/?id=1005';

try {
final response = await http.get(Uri.parse(apiUrl));

if (response.statusCode == 200) {
final responseData = jsonDecode(response.body);
return responseData['downloadUrl'];
}
} catch (e) {
debugPrint('Error getting download link: $e');
}

return null;
}

Future<void> _downloadUpdate() async {
final downloadLink = await _getDownloadLink();

if (downloadLink != null && downloadLink.isNotEmpty) {
if (await canLaunch(downloadLink)) {
await launch(downloadLink);
} else {
throw 'Could not launch $downloadLink';
}
}
}

@override
Widget build(BuildContext context) {
final themeProvider = Provider.of<ThemeProvider>(context);
Expand All @@ -80,40 +23,53 @@ class SettingsPage extends StatelessWidget {
_buildSettingTile(
context,
title: 'Dark Mode',
icon: theme.brightness == Brightness.dark
? Icons.nightlight_round
: Icons.wb_sunny,
iconColor: theme.brightness == Brightness.dark
? Colors.yellow
: Colors.orange,
icon: theme.brightness == Brightness.dark ? Icons.nightlight_round : Icons.wb_sunny,
iconColor: theme.brightness == Brightness.dark ? Colors.yellow : Colors.orange,
onTap: () {
themeProvider.toggleTheme();
},
),
_buildSettingTile(
context,
title: 'Check for Updates',
icon: Icons.system_update,
onTap: () async {
bool updateAvailable = await _checkForUpdate();
if (updateAvailable) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('Update available! Click to download.'),
action: SnackBarAction(
label: 'Download',
onPressed: _downloadUpdate,
),
),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('No updates available.')),
);
}
title: 'Version Info',
subtitle: '1.0.2',
icon: Icons.info_outline,
onTap: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('App version 1.0.2')),
);
},
),
_buildSettingTile(
context,
title: 'Contact Us',
icon: Icons.email_outlined,
onTap: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Contacs will be availabe soon.')),
);
},
),
_buildSettingTile(
context,
title: 'Privacy Policy',
icon: Icons.lock_outline,
onTap: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Privacy policy link will be available soon.')),
);
},
),
_buildSettingTile(
context,
title: 'Terms of Service',
icon: Icons.description_outlined,
onTap: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Terms of service link will be available soon.')),
);
},
),

],
),
);
Expand Down Expand Up @@ -145,8 +101,7 @@ class SettingsPage extends StatelessWidget {
],
),
child: ListTile(
contentPadding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
title: Text(
title,
style: TextStyle(
Expand Down
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.8"
dio:
dependency: "direct main"
description:
name: dio
sha256: "5598aa796bbf4699afd5c67c0f5f6e2ed542afc956884b9cd58c306966efc260"
url: "https://pub.dev"
source: hosted
version: "5.7.0"
dio_web_adapter:
dependency: transitive
description:
name: dio_web_adapter
sha256: "33259a9276d6cea88774a0000cfae0d861003497755969c92faa223108620dc8"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
fake_async:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies:
package_info_plus: ^8.0.2
http: ^1.2.2
url_launcher: ^6.3.0
dio: ^5.7.0


dev_dependencies:
Expand Down

0 comments on commit e06781c

Please sign in to comment.