mirror of
https://github.com/Auties00/Reboot-Launcher.git
synced 2026-01-14 11:39:17 +01:00
9.0.2
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:markdown_widget/config/markdown_generator.dart';
|
||||
import 'package:reboot_launcher/src/controller/info_controller.dart';
|
||||
import 'package:fluent_ui/fluent_ui.dart' hide FluentIcons;
|
||||
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:reboot_launcher/src/page/abstract/page.dart';
|
||||
import 'package:reboot_launcher/src/page/abstract/page_setting.dart';
|
||||
import 'package:reboot_launcher/src/page/abstract/page_type.dart';
|
||||
import 'package:reboot_launcher/src/util/translations.dart';
|
||||
import 'package:reboot_launcher/src/widget/common/setting_tile.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:reboot_launcher/src/util/tutorial.dart';
|
||||
import 'package:reboot_launcher/src/widget/setting_tile.dart';
|
||||
|
||||
class InfoPage extends RebootPage {
|
||||
const InfoPage({Key? key}) : super(key: key);
|
||||
@@ -24,105 +20,68 @@ class InfoPage extends RebootPage {
|
||||
String get iconAsset => "assets/images/info.png";
|
||||
|
||||
@override
|
||||
bool get hasButton => false;
|
||||
bool hasButton(String? routeName) => false;
|
||||
|
||||
@override
|
||||
RebootPageType get type => RebootPageType.info;
|
||||
|
||||
@override
|
||||
List<PageSetting> get settings => [];
|
||||
}
|
||||
|
||||
class _InfoPageState extends RebootPageState<InfoPage> {
|
||||
final InfoController _infoController = Get.find<InfoController>();
|
||||
late Future<List<String>> _fetchFuture;
|
||||
late double _height;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_fetchFuture = _infoController.links != null
|
||||
? Future.value(_infoController.links)
|
||||
: _initQuery();
|
||||
super.initState();
|
||||
}
|
||||
List<SettingTile> get settings => [
|
||||
_documentation,
|
||||
_discord,
|
||||
_youtubeTutorial,
|
||||
_reportBug
|
||||
];
|
||||
|
||||
Future<List<String>> _initQuery() async {
|
||||
var response = await http.get(Uri.parse("https://api.github.com/repos/Auties00/reboot_launcher/contents/documentation/$currentLocale"));
|
||||
List results = jsonDecode(response.body);
|
||||
results.sort((first, second) {
|
||||
var firstIndex = int.parse(first["name"][0]);
|
||||
var secondIndex = int.parse(second["name"][0]);
|
||||
return firstIndex > secondIndex ? 1 : firstIndex == secondIndex ? 0 : -1;
|
||||
});
|
||||
List<String> parsed = results.map<String>((entry) => entry["download_url"] as String).toList();
|
||||
return _infoController.links = parsed;
|
||||
}
|
||||
|
||||
Future<String> _readLink(String url) async {
|
||||
var known = _infoController.linksData[url];
|
||||
if(known != null) {
|
||||
return known;
|
||||
}
|
||||
|
||||
var response = await http.get(Uri.parse(url));
|
||||
return _infoController.linksData[url] = response.body;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
_height = MediaQuery.of(context).size.height / 3;
|
||||
return FutureBuilder(
|
||||
future: _fetchFuture,
|
||||
builder: (context, linksSnapshot) {
|
||||
var linksData = linksSnapshot.data;
|
||||
if(linksData == null) {
|
||||
return const Center(
|
||||
child: ProgressRing()
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
maxWidth: 1000
|
||||
),
|
||||
child: ListView.separated(
|
||||
shrinkWrap: true,
|
||||
separatorBuilder: (context, index) => const SizedBox(
|
||||
height: 16.0
|
||||
),
|
||||
itemBuilder: (context, index) => Card(
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(4.0)),
|
||||
child: _buildBody(linksData, index)
|
||||
),
|
||||
itemCount: linksData.length
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(List<String> linksData, int index) => FutureBuilder(
|
||||
future: _readLink(linksData[index]),
|
||||
builder: (context, linkDataSnapshot) {
|
||||
var markdownGenerator = MarkdownGenerator();
|
||||
var result = markdownGenerator.buildWidgets(linkDataSnapshot.data ?? "");
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: result
|
||||
);
|
||||
}
|
||||
SettingTile get _reportBug => SettingTile(
|
||||
icon: Icon(
|
||||
FluentIcons.bug_24_regular
|
||||
),
|
||||
title: Text(translations.settingsUtilsBugReportName),
|
||||
subtitle: Text(translations.settingsUtilsBugReportSubtitle) ,
|
||||
content: Button(
|
||||
onPressed: openBugReport,
|
||||
child: Text(translations.settingsUtilsBugReportContent),
|
||||
)
|
||||
);
|
||||
|
||||
@override
|
||||
List<SettingTile> get settings => [];
|
||||
SettingTile get _youtubeTutorial => SettingTile(
|
||||
icon: Icon(
|
||||
FluentIcons.video_24_regular
|
||||
),
|
||||
title: Text(translations.infoVideoName),
|
||||
subtitle: Text(translations.infoVideoDescription),
|
||||
content: Button(
|
||||
onPressed: openYoutubeTutorial,
|
||||
child: Text(translations.infoVideoContent)
|
||||
)
|
||||
);
|
||||
|
||||
SettingTile get _discord => SettingTile(
|
||||
icon: Icon(
|
||||
Icons.discord_outlined
|
||||
),
|
||||
title: Text(translations.infoDiscordName),
|
||||
subtitle: Text(translations.infoDiscordDescription),
|
||||
content: Button(
|
||||
onPressed: openDiscordServer,
|
||||
child: Text(translations.infoDiscordContent)
|
||||
)
|
||||
);
|
||||
|
||||
SettingTile get _documentation => SettingTile(
|
||||
icon: Icon(
|
||||
FluentIcons.document_24_regular
|
||||
),
|
||||
title: Text(translations.infoDocumentationName),
|
||||
subtitle: Text(translations.infoDocumentationDescription),
|
||||
content: Button(
|
||||
onPressed: openTutorials,
|
||||
child: Text(translations.infoDocumentationContent)
|
||||
)
|
||||
);
|
||||
|
||||
@override
|
||||
Widget? get button => null;
|
||||
|
||||
Reference in New Issue
Block a user