2022-08-17 18:07:00 +02:00
|
|
|
import 'dart:typed_data';
|
2022-08-02 10:33:46 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-07 01:37:12 +02:00
|
|
|
import 'package:flutter_i18n/flutter_i18n.dart';
|
2022-08-09 01:01:06 +02:00
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
2022-08-18 16:33:33 +02:00
|
|
|
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
2022-09-05 04:32:36 +02:00
|
|
|
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
|
2022-08-02 10:33:46 +02:00
|
|
|
|
|
|
|
class AppSelectorCard extends StatelessWidget {
|
2022-08-18 16:33:33 +02:00
|
|
|
const AppSelectorCard({
|
2023-11-11 13:07:32 +01:00
|
|
|
super.key,
|
2022-08-18 16:33:33 +02:00
|
|
|
required this.onPressed,
|
2023-11-11 13:07:32 +01:00
|
|
|
});
|
2023-11-21 15:33:21 +01:00
|
|
|
|
2023-01-30 13:35:06 +01:00
|
|
|
final Function() onPressed;
|
2022-08-02 10:33:46 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-01-22 09:20:17 +01:00
|
|
|
final vm = locator<PatcherViewModel>();
|
|
|
|
|
|
|
|
|
|
|
|
String? suggestedVersion;
|
|
|
|
if (vm.selectedApp != null) {
|
|
|
|
suggestedVersion = vm.getSuggestedVersionString(context);
|
|
|
|
}
|
|
|
|
|
2022-09-19 18:55:44 +02:00
|
|
|
return CustomCard(
|
2022-08-02 10:33:46 +02:00
|
|
|
onTap: onPressed,
|
2022-09-19 18:55:44 +02:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
I18nText(
|
2024-01-22 09:20:17 +01:00
|
|
|
vm.selectedApp == null
|
2022-09-19 18:55:44 +02:00
|
|
|
? 'appSelectorCard.widgetTitle'
|
|
|
|
: 'appSelectorCard.widgetTitleSelected',
|
|
|
|
child: const Text(
|
|
|
|
'',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 18,
|
|
|
|
fontWeight: FontWeight.w500,
|
2022-08-02 10:33:46 +02:00
|
|
|
),
|
|
|
|
),
|
2022-09-19 18:55:44 +02:00
|
|
|
),
|
2022-09-25 14:43:37 +02:00
|
|
|
const SizedBox(height: 8),
|
2024-01-22 09:20:17 +01:00
|
|
|
if (vm.selectedApp == null)
|
2023-01-30 13:35:06 +01:00
|
|
|
I18nText('appSelectorCard.widgetSubtitle')
|
|
|
|
else
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
SizedBox(
|
|
|
|
height: 18.0,
|
|
|
|
child: ClipOval(
|
|
|
|
child: Image.memory(
|
2024-01-22 09:20:17 +01:00
|
|
|
vm.selectedApp == null
|
2023-01-30 13:35:06 +01:00
|
|
|
? Uint8List(0)
|
2024-01-22 09:20:17 +01:00
|
|
|
: vm.selectedApp!.icon,
|
2023-01-30 13:35:06 +01:00
|
|
|
fit: BoxFit.cover,
|
2022-09-19 18:55:44 +02:00
|
|
|
),
|
2023-01-30 13:35:06 +01:00
|
|
|
),
|
2022-09-19 18:55:44 +02:00
|
|
|
),
|
2023-01-30 13:35:06 +01:00
|
|
|
const SizedBox(width: 6),
|
2023-08-03 23:38:38 +02:00
|
|
|
Flexible(
|
|
|
|
child: Text(
|
2024-01-22 09:20:17 +01:00
|
|
|
vm.getAppSelectionString(),
|
2023-08-03 23:38:38 +02:00
|
|
|
style: const TextStyle(fontWeight: FontWeight.w600),
|
|
|
|
),
|
2022-09-19 18:55:44 +02:00
|
|
|
),
|
2023-01-30 13:35:06 +01:00
|
|
|
],
|
|
|
|
),
|
2024-01-22 09:20:17 +01:00
|
|
|
if (vm.selectedApp == null)
|
2023-01-30 13:35:06 +01:00
|
|
|
Container()
|
|
|
|
else
|
|
|
|
Column(
|
2023-11-21 15:33:21 +01:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
2023-01-30 13:35:06 +01:00
|
|
|
children: [
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
Text(
|
2024-01-22 09:20:17 +01:00
|
|
|
vm.selectedApp!.packageName,
|
2023-11-21 15:33:21 +01:00
|
|
|
),
|
2024-01-22 09:20:17 +01:00
|
|
|
if (suggestedVersion!.isNotEmpty &&
|
|
|
|
suggestedVersion != vm.selectedApp!.version) ...[
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Material(
|
|
|
|
color: Theme.of(context).colorScheme.secondaryContainer,
|
2023-11-21 15:33:21 +01:00
|
|
|
borderRadius:
|
|
|
|
const BorderRadius.all(Radius.circular(8)),
|
2024-01-22 09:20:17 +01:00
|
|
|
child: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
vm.queryVersion(suggestedVersion!);
|
|
|
|
},
|
|
|
|
borderRadius:
|
|
|
|
const BorderRadius.all(Radius.circular(8)),
|
|
|
|
child: Container(
|
|
|
|
padding: const EdgeInsets.fromLTRB(8, 4, 8, 4),
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
I18nText(
|
|
|
|
'suggested',
|
|
|
|
translationParams: {
|
|
|
|
'version': suggestedVersion,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
Icon(
|
|
|
|
Icons.search,
|
|
|
|
size: 16,
|
2023-11-21 15:33:21 +01:00
|
|
|
color: Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.onSecondaryContainer,
|
|
|
|
),
|
2024-01-22 09:20:17 +01:00
|
|
|
],
|
|
|
|
),
|
2023-11-21 15:33:21 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-01-22 09:20:17 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
]
|
2023-01-30 13:35:06 +01:00
|
|
|
],
|
|
|
|
),
|
2022-09-19 18:55:44 +02:00
|
|
|
],
|
2022-08-02 10:33:46 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|