openstore/lib/app_page.dart

204 lines
7.2 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();
}
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: [
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: _appInfo?["minSdkVersion"].toString() ?? "",
bottomText: "minSdkVersion",
),
_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
}