openstore/lib/app_page.dart

281 lines
9.7 KiB
Dart
Raw Normal View History

2024-08-06 19:06:38 +03:00
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'package:openstore/get_app_link.dart';
import 'package:url_launcher/url_launcher.dart';
class AppPage extends StatefulWidget {
const AppPage({super.key, required this.packageName});
final String packageName;
@override
State<AppPage> createState() => _AppPageState();
}
String getAndroidVersion(int apiLevel) {
const versions = {
1: '1.0',
2: '1.1',
3: '1.5',
4: '1.6',
5: '2.0',
6: '2.0.1',
7: '2.1',
8: '2.2',
9: '2.3',
10: '2.3.3',
11: '3.0',
12: '3.1',
13: '3.2',
14: '4.0',
15: '4.0.3',
16: '4.1',
17: '4.2',
18: '4.3',
19: '4.4',
20: '4.4W', // Wear-версия
21: '5.0',
22: '5.1',
23: '6.0',
24: '7.0',
25: '7.1',
26: '8.0',
27: '8.1',
28: '9.0',
29: '10',
30: '11',
31: '12',
32: '12L', // Android 12L
33: '13',
34: '14',
};
return versions[apiLevel] ?? '? (API $apiLevel)';
}
2024-08-06 19:06:38 +03:00
class _AppPageState extends State<AppPage> {
Map? _appInfo;
@override
void initState() {
super.initState();
_loadAppInfo();
}
2025-04-27 18:17:40 +03:00
2024-08-06 19:06:38 +03:00
void _loadAppInfo() async {
2025-04-27 18:17:40 +03:00
var rq = await http.get(Uri.https(
"backapi.rustore.ru",
"/applicationData/overallInfo/${widget.packageName}",
));
print(widget.packageName + "PN");
2024-08-06 19:06:38 +03:00
if (rq.statusCode != 200) {
showDialog(
2025-04-27 18:17:40 +03:00
context: context,
builder: (context) => AlertDialog(
title: const Text("Что то пошло не так"),
content: Text("RuStore вернул код ${rq.statusCode}"),
actions: [
FilledButton(
onPressed: () {
Navigator.of(context)
..pop()
..pop();
},
child: const Text("ок"),
)
],
));
2024-08-06 19:06:38 +03:00
}
setState(() {
2025-04-27 18:17:40 +03:00
_appInfo = json.decode(utf8.decode(rq.bodyBytes))["body"] ?? {};
});
2024-08-06 19:06:38 +03:00
}
2025-04-27 18:17:40 +03:00
2024-08-06 19:06:38 +03:00
@override
Widget build(BuildContext context) {
2025-04-27 18:17:40 +03:00
return Scaffold(
appBar: AppBar(),
body: _appInfo != null
? ListView(
padding: const EdgeInsets.fromLTRB(15, 0, 15, 15),
children: [
2025-05-08 14:31:12 +03:00
Card(
margin: const EdgeInsets.fromLTRB(0, 0, 0, 15),
surfaceTintColor: _appInfo?["aggregatorInfo"] == null
? const Color.fromARGB(255, 0, 255, 0)
: const Color.fromARGB(255, 255, 187, 0),
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
spacing: 16,
children: [
const Icon(
Icons.security,
size: 32,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"предоставлено ${_appInfo?["aggregatorInfo"]?["source"] ?? "RuStore"}",
style: TextStyle(fontSize: 16),
),
Text(
_appInfo?["aggregatorInfo"] == null
? (_appInfo?["companyLegalForm"] ==
"INDIVIDUAL"
2025-05-10 13:44:38 +03:00
? "разработчик - частное лицо"
: "разработчик - компания")
: "разработчик: ${_appInfo?["aggregatorInfo"]?["companyName"]}",
2025-05-08 14:31:12 +03:00
style: const TextStyle(fontSize: 14),
)
],
)
],
),
)),
2025-04-27 18:17:40 +03:00
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(25),
child: Image.network(
_appInfo?["iconUrl"] ?? "",
width: 120,
2024-08-06 19:06:38 +03:00
),
),
2025-04-27 18:17:40 +03:00
const SizedBox(
width: 15,
2024-08-06 19:06:38 +03:00
),
2025-04-27 18:17:40 +03:00
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_appInfo?["appName"] ?? "null",
//overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 21,
fontWeight: FontWeight.bold,
),
),
const SizedBox(
height: 10,
),
Text(
_appInfo?["companyName"] ?? "null",
overflow: TextOverflow.ellipsis,
softWrap: false,
),
],
)),
],
),
const SizedBox(
height: 20,
),
FilledButton.icon(
style: FilledButton.styleFrom(
minimumSize: const Size.fromHeight(40),
2024-08-06 19:06:38 +03:00
),
2025-04-27 18:17:40 +03:00
onPressed: () async {
launchUrl(await getAppLink(_appInfo?["appId"], context));
},
label: const Text("Скачать APK"),
2024-08-06 19:06:38 +03:00
),
2025-04-27 18:17:40 +03:00
const SizedBox(height: 15),
SizedBox(
height: 84,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
_InfoCard(
topText:
"${((_appInfo?["fileSize"] ?? 0) / 1024 / 1024).toStringAsFixed(1)} MB",
bottomText: "Размер",
),
_InfoCard(
topText: _appInfo?["versionName"] ?? "0",
bottomText: "Версия",
),
_InfoCard(
topText:
"${getAndroidVersion(_appInfo?["minSdkVersion"] ?? 0)}+",
bottomText: "Android",
2025-04-27 18:17:40 +03:00
),
_InfoCard(
topText:
_appInfo?["ageRestriction"]?["category"] ?? "?",
bottomText: "Возраст",
),
_InfoCard(
topText: _appInfo?["categories"]?[0] ?? "?",
bottomText: "Категория",
)
],
),
),
const SizedBox(height: 15),
SizedBox(
height: 250,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: _appInfo?["fileUrls"]?.length ?? 0,
itemBuilder: (context, i) {
var file = _appInfo?["fileUrls"][i];
if (file["type"] != "SCREENSHOT" &&
file["orientation"] != "PORTRAIT") {
return const SizedBox();
}
//return Text("data${i}");
return Padding(
padding: const EdgeInsets.all(5),
child: ClipRRect(
borderRadius: BorderRadius.circular(15),
child: Image.network(
file["fileUrl"],
),
),
);
}),
),
const SizedBox(height: 15),
const Text(
"Что нового?",
style: TextStyle(fontSize: 21, fontWeight: FontWeight.bold),
),
Text(_appInfo?["whatsNew"] ?? "null"),
const SizedBox(height: 15),
const Text(
"Описание",
style: TextStyle(fontSize: 21, fontWeight: FontWeight.bold),
),
Text(_appInfo?["fullDescription"] ?? "null"),
],
)
: const LinearProgressIndicator());
2024-08-06 19:06:38 +03:00
}
}
class _InfoCard extends StatelessWidget {
2025-04-27 20:21:17 +03:00
const _InfoCard({required this.topText, required this.bottomText});
2024-08-06 19:06:38 +03:00
final String topText;
final String bottomText;
@override
Widget build(BuildContext context) {
return Card(
child: Padding(
padding: const EdgeInsets.all(15),
child: Column(
children: [
Text(
topText,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
Text(bottomText),
],
),
),
);
}
2025-04-27 18:17:40 +03:00
}