Files
venera/lib/pages/settings/about.dart
2024-10-11 21:47:50 +08:00

122 lines
3.8 KiB
Dart

part of 'settings_page.dart';
class AboutSettings extends StatefulWidget {
const AboutSettings({super.key});
@override
State<AboutSettings> createState() => _AboutSettingsState();
}
class _AboutSettingsState extends State<AboutSettings> {
bool isCheckingUpdate = false;
@override
Widget build(BuildContext context) {
return SmoothCustomScrollView(
slivers: [
SliverAppbar(title: Text("About".tl)),
SizedBox(
height: 136,
width: double.infinity,
child: Center(
child: Container(
width: 136,
height: 136,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(136),
),
clipBehavior: Clip.antiAlias,
child: const Image(
image: AssetImage("assets/app_icon.png"),
filterQuality: FilterQuality.medium,
),
),
),
).paddingTop(16).toSliver(),
Column(
children: [
const SizedBox(height: 8),
Text(
"V${App.version}",
style: const TextStyle(fontSize: 16),
),
Text("Venera is a free and open-source app for comic reading.".tl),
const SizedBox(height: 8),
],
).toSliver(),
ListTile(
title: Text("Check for updates".tl),
trailing: Button.filled(
isLoading: isCheckingUpdate,
child: Text("Check".tl),
onPressed: () {
setState(() {
isCheckingUpdate = true;
});
checkUpdate().then((value) {
if (value) {
showDialog(
context: App.rootContext,
builder: (context) {
return ContentDialog(
title: "New version available".tl,
content: Text(
"A new version is available. Do you want to update now?"
.tl),
actions: [
Button.text(
onPressed: () {
Navigator.pop(context);
launchUrlString(
"https://github.com/venera-app/venera/releases");
},
child: Text("Update".tl),
),
]);
});
} else {
context.showMessage(message: "No new version available".tl);
}
setState(() {
isCheckingUpdate = false;
});
});
},
).fixHeight(32),
).toSliver(),
ListTile(
title: const Text("Github"),
trailing: const Icon(Icons.open_in_new),
onTap: () {
launchUrlString("https://github.com/venera-app/venera");
},
).toSliver(),
],
);
}
}
Future<bool> checkUpdate() async {
var res = await AppDio().get(
"https://raw.githubusercontent.com/venera-app/venera/refs/heads/master/pubspec.yaml");
if (res.statusCode == 200) {
var data = loadYaml(res.data);
if (data["version"] != null) {
return _compareVersion(data["version"].split("+")[0], App.version);
}
}
return false;
}
/// return true if version1 > version2
bool _compareVersion(String version1, String version2) {
var v1 = version1.split(".");
var v2 = version2.split(".");
for (var i = 0; i < v1.length; i++) {
if (int.parse(v1[i]) > int.parse(v2[i])) {
return true;
}
}
return false;
}