(add) awareness of other versions

This commit is contained in:
Erfan Rahmati
2022-09-14 08:51:36 +04:30
parent f6b3655ab2
commit 07f490fbef
8 changed files with 76 additions and 28 deletions

2
.gitignore vendored
View File

@@ -1,5 +1,3 @@
lib/modules/api/key_getter.dart
.VSCodeCounter/
# Miscellaneous

5
lib/constants/app.dart Normal file
View File

@@ -0,0 +1,5 @@
const String appVersion = "v3.0.1";
String? latestVersion;
List<String>? supportedVersions;
String? secureUrl;

View File

@@ -9,7 +9,9 @@ enum RequestResult {
SUCCESS,
FAILURE,
FAILURE_USER_PROBLEM,
FAILURE_SERVER_PROBLEM
FAILURE_SERVER_PROBLEM,
FAILURE_IMDB_PROBLEM,
FAILURE_VERSION_PROBLEM,
}
enum ListName {

View File

@@ -276,7 +276,7 @@ class APIRequester {
(apiKeys.length == 1 && apiKeys[0] == "XXXXXXXXXX")) {
var response;
await key_getter().then((result) async {
if (!result) {
if (result == RequestResult.FAILURE) {
if (kDebugMode) {
print(
"You haven't add any api key to the app, so it won't work!\nFor more information check out the documentation at https://github.com/ErfanRht/MovieLab#getting-started");

View File

@@ -3,17 +3,29 @@ import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:movielab/.api.dart';
import 'package:movielab/constants/app.dart';
import 'package:movielab/constants/types.dart';
Future<bool> key_getter() async {
Future<RequestResult> key_getter() async {
const String url = "";
if (url != "") {
var response = await http.get(Uri.parse(url)).timeout(
const Duration(seconds: 10),
);
if (kDebugMode) {
print(jsonDecode(response.body).length);
print(
"${jsonDecode(response.body)['keys'].length} api keys has been added.");
}
apiKeys = [for (dynamic key in jsonDecode(response.body)) key.toString()];
apiKeys = [
for (dynamic key in jsonDecode(response.body)['keys']) key.toString()
];
supportedVersions = [
for (dynamic version in jsonDecode(response.body)['supported_versions'])
version.toString()
];
latestVersion = jsonDecode(response.body)['latest_version'].toString();
secureUrl = jsonDecode(response.body)['secure_url'].toString();
return RequestResult.SUCCESS;
}
return true;
return RequestResult.FAILURE;
}

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:movielab/constants/app.dart';
import 'package:movielab/constants/colors.dart';
import 'package:movielab/pages/shared/app_name.dart';
import 'package:movielab/widgets/buttons/social_media_button.dart';
@@ -37,7 +38,7 @@ class AboutPage extends StatelessWidget {
height: 10,
),
Text(
"Version 2.0.7",
"Version ${appVersion.replaceAll('v', '')}",
style: TextStyle(
fontSize: 17.5,
color: Colors.white.withOpacity(0.5),

View File

@@ -1,9 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:movielab/constants/app.dart';
import 'package:movielab/modules/Recommender/Recommender.dart';
import 'package:movielab/modules/tools/navigate.dart';
import 'package:movielab/pages/main/main_page.dart';
import 'package:movielab/widgets/error.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../constants/colors.dart';
import '../../constants/types.dart';
import '../../modules/tools/system_ui_overlay_style.dart';
@@ -27,6 +29,10 @@ class _SplashScreenState extends State<SplashScreen> {
_loadData();
}
void _launchUrl(final String url) async {
if (!await launchUrl(Uri.parse(url))) throw 'Could not launch $url';
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -67,6 +73,15 @@ class _SplashScreenState extends State<SplashScreen> {
borderWidth: 10,
),
);
case RequestResult.FAILURE_VERSION_PROBLEM:
return ConnectionErrorWidget(
isItTryAgain: false,
tryAgain: () {
_launchUrl("https://erfanrht.github.io/MovieLab-Intro");
},
errorText:
'The version of MovieLab that you are using is outdated.\nFor more information check out:\n${secureUrl ?? "erfanrht.github.io/movielab-intro"}',
);
default:
return ConnectionErrorWidget(
tryAgain: () {
@@ -87,7 +102,17 @@ class _SplashScreenState extends State<SplashScreen> {
if (result == RequestResult.SUCCESS) {
recommender();
getUserData();
Navigate.replaceTo(context, const MainPage());
if (supportedVersions != null && supportedVersions!.isNotEmpty) {
if (supportedVersions!.contains(appVersion)) {
Navigate.replaceTo(context, const MainPage());
} else {
setState(() {
_loadingStatus = RequestResult.FAILURE_VERSION_PROBLEM;
});
}
} else {
Navigate.replaceTo(context, const MainPage());
}
} else {
setState(() {
_loadingStatus = result;

View File

@@ -1,14 +1,15 @@
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:movielab/constants/colors.dart';
class ConnectionErrorWidget extends StatelessWidget {
final String errorText;
final VoidCallback tryAgain;
final bool isItTryAgain;
final VoidCallback? tryAgain;
const ConnectionErrorWidget(
{this.errorText = 'An unexpected error occurred while loading data.',
required this.tryAgain,
Key? key})
Key? key,
this.isItTryAgain = true})
: super(key: key);
@override
@@ -25,6 +26,7 @@ class ConnectionErrorWidget extends StatelessWidget {
onTap: tryAgain,
borderRadius: BorderRadius.circular(10),
child: Container(
// width: MediaQuery.of(context).size.width,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
@@ -34,24 +36,27 @@ class ConnectionErrorWidget extends StatelessWidget {
children: [
Text(
errorText,
style: TextStyle(
textAlign: TextAlign.center,
softWrap: true,
style: const TextStyle(
fontSize: 12.5, fontWeight: FontWeight.w600),
),
const SizedBox(height: 5),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Try again',
style: TextStyle(
fontSize: 12.5,
fontWeight: FontWeight.w600),
),
const Icon(
Icons.refresh,
size: 15,
)
])
if (isItTryAgain)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text(
'Try again',
style: TextStyle(
fontSize: 12.5,
fontWeight: FontWeight.w600),
),
Icon(
Icons.refresh,
size: 15,
)
])
],
),
)),