network check wooo

also funny disclaimers at the bottom of settings lul
This commit is contained in:
Mercurio 2023-11-13 23:47:01 +01:00
parent e56f61f078
commit 4c2ff57ad3
3 changed files with 68 additions and 1 deletions

56
lib/netcheck.dart Normal file
View file

@ -0,0 +1,56 @@
import 'package:shared_preferences/shared_preferences.dart';
import 'package:http/http.dart' as http;
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter/material.dart';
class NetCheck {
static Future<void> runChecks() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String apiKey = prefs.getString('apiKey') ?? '';
http.Response response1 = await http.get(
Uri.parse('https://api.shocklink.net/1/shockers/own'),
headers: {
'accept': 'application/json',
'OpenShockToken': apiKey,
},
);
if (response1.statusCode == 200) {
String shockerId = prefs.getString('shockerId') ?? '';
http.Response response2 = await http.get(
Uri.parse('https://api.shocklink.net/1/shockers/$shockerId'),
headers: {
'accept': 'application/json',
'OpenShockToken': apiKey,
},
);
if (response2.statusCode == 200) {
showSuccessToast('Information is correct');
} else {
showToast('Incorrect Shocker ID');
}
} else {
showToast('Incorrect API Key');
}
}
static void showToast(String message) {
Fluttertoast.showToast(
msg: message,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
);
}
static void showSuccessToast(String message) {
Fluttertoast.showToast(
msg: message,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.green,
textColor: Colors.white,
);
}
}

View file

@ -6,6 +6,7 @@ import 'bottom_bar.dart';
import 'app_state.dart';
import 'LogsPage.dart';
import 'package:provider/provider.dart';
import 'netcheck.dart' show NetCheck, runChecks;
class SettingsPage extends StatefulWidget {
const SettingsPage({Key? key});
@ -46,6 +47,7 @@ class _SettingsPageState extends State<SettingsPage> {
prefs.setString('shockerId', shockerIdController.text);
intensityLimitController.text = prefs.getString('intensityLimit') ?? '100';
durationLimitController.text = prefs.getString('durationLimit') ?? '30';
// await NetCheck.runChecks();
Navigator.pop(context);
}
@ -118,6 +120,15 @@ class _SettingsPageState extends State<SettingsPage> {
onPressed: saveSettings,
child: const Text('Save'),
),
const SizedBox(height: 15),
// Add the new text below the Save button
const Text(
'App Version: 0.2-beta5 - Build Date: Nov. 13, 2023\n'
'This application is in no way, shape, or form affiliated with the openshock team.\n'
'(C) Mercury -as- olbiaphlee 2023. Reproduction and modification is allowed in accordance with the license found in the app\'s git ',
textAlign: TextAlign.left,
style: TextStyle(fontSize: 12),
),
],
),
),

View file

@ -4,7 +4,7 @@ description: Companion app for managing openshock-compatible devices
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none'
version: 0.2.4
version: 0.2.5
environment:
sdk: '>=3.1.2 <4.0.0'