2022-08-07 20:05:44 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-31 12:05:38 +02:00
|
|
|
import 'package:flutter_i18n/flutter_i18n.dart';
|
2022-08-07 20:05:44 +02:00
|
|
|
import 'package:google_fonts/google_fonts.dart';
|
2022-09-01 02:25:19 +02:00
|
|
|
import 'package:revanced_manager/ui/widgets/shared/patch_text_button.dart';
|
2022-08-07 20:05:44 +02:00
|
|
|
|
2022-08-09 01:01:06 +02:00
|
|
|
// ignore: must_be_immutable
|
2022-08-07 21:15:52 +02:00
|
|
|
class PatchItem extends StatefulWidget {
|
2022-08-07 20:05:44 +02:00
|
|
|
final String name;
|
2022-08-09 03:30:12 +02:00
|
|
|
final String simpleName;
|
2022-08-07 20:05:44 +02:00
|
|
|
final String description;
|
|
|
|
final String version;
|
2022-08-31 12:05:38 +02:00
|
|
|
final String packageVersion;
|
|
|
|
final List<String> supportedPackageVersions;
|
|
|
|
final bool isUnsupported;
|
2022-08-07 21:15:52 +02:00
|
|
|
bool isSelected;
|
2022-08-18 16:33:33 +02:00
|
|
|
final Function(bool) onChanged;
|
2022-08-07 20:05:44 +02:00
|
|
|
|
|
|
|
PatchItem({
|
|
|
|
Key? key,
|
|
|
|
required this.name,
|
2022-08-09 03:30:12 +02:00
|
|
|
required this.simpleName,
|
2022-08-07 20:05:44 +02:00
|
|
|
required this.description,
|
|
|
|
required this.version,
|
2022-08-31 12:05:38 +02:00
|
|
|
required this.packageVersion,
|
|
|
|
required this.supportedPackageVersions,
|
|
|
|
required this.isUnsupported,
|
2022-08-07 20:05:44 +02:00
|
|
|
required this.isSelected,
|
2022-08-18 16:33:33 +02:00
|
|
|
required this.onChanged,
|
2022-08-07 20:05:44 +02:00
|
|
|
}) : super(key: key);
|
|
|
|
|
2022-08-07 21:15:52 +02:00
|
|
|
@override
|
|
|
|
State<PatchItem> createState() => _PatchItemState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PatchItemState extends State<PatchItem> {
|
2022-08-07 20:05:44 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-13 11:56:30 +02:00
|
|
|
return InkWell(
|
2022-08-18 00:06:02 +02:00
|
|
|
onTap: () {
|
|
|
|
setState(() => widget.isSelected = !widget.isSelected);
|
2022-08-18 16:33:33 +02:00
|
|
|
widget.onChanged(widget.isSelected);
|
2022-08-18 00:06:02 +02:00
|
|
|
},
|
2022-08-13 11:56:30 +02:00
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
),
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 12),
|
|
|
|
margin: const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
|
|
|
|
child: Column(
|
2022-09-02 15:35:25 +02:00
|
|
|
children: <Widget>[
|
2022-08-13 11:56:30 +02:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2022-09-02 15:35:25 +02:00
|
|
|
children: <Widget>[
|
2022-08-13 11:56:30 +02:00
|
|
|
Flexible(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2022-09-02 15:35:25 +02:00
|
|
|
children: <Widget>[
|
2022-08-13 11:56:30 +02:00
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
2022-09-02 15:35:25 +02:00
|
|
|
children: <Widget>[
|
2022-08-13 11:56:30 +02:00
|
|
|
Text(
|
|
|
|
widget.simpleName,
|
|
|
|
style: GoogleFonts.inter(
|
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
),
|
2022-08-07 20:05:44 +02:00
|
|
|
),
|
2022-08-13 11:56:30 +02:00
|
|
|
const SizedBox(width: 4),
|
|
|
|
Text(widget.version)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
Text(
|
|
|
|
widget.description,
|
|
|
|
softWrap: true,
|
|
|
|
maxLines: 3,
|
|
|
|
overflow: TextOverflow.visible,
|
|
|
|
style: GoogleFonts.roboto(
|
|
|
|
fontSize: 14,
|
2022-08-07 20:05:44 +02:00
|
|
|
),
|
|
|
|
),
|
2022-08-13 11:56:30 +02:00
|
|
|
],
|
|
|
|
),
|
2022-08-07 20:05:44 +02:00
|
|
|
),
|
2022-08-13 11:56:30 +02:00
|
|
|
Transform.scale(
|
|
|
|
scale: 1.2,
|
|
|
|
child: Checkbox(
|
|
|
|
value: widget.isSelected,
|
2022-09-01 02:25:19 +02:00
|
|
|
activeColor: Theme.of(context).colorScheme.secondary,
|
2022-08-13 11:56:30 +02:00
|
|
|
onChanged: (newValue) {
|
2022-08-18 00:06:02 +02:00
|
|
|
setState(() => widget.isSelected = newValue!);
|
2022-08-18 16:33:33 +02:00
|
|
|
widget.onChanged(widget.isSelected);
|
2022-08-13 11:56:30 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
2022-08-31 12:05:38 +02:00
|
|
|
),
|
|
|
|
widget.isUnsupported
|
|
|
|
? Row(
|
2022-09-02 15:35:25 +02:00
|
|
|
children: <Widget>[
|
2022-08-31 12:05:38 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8),
|
|
|
|
child: TextButton.icon(
|
|
|
|
label: I18nText('patchItem.unsupportedWarningButton'),
|
|
|
|
icon: const Icon(Icons.warning),
|
|
|
|
onPressed: () => _showUnsupportedWarningDialog(),
|
|
|
|
style: ButtonStyle(
|
|
|
|
shape: MaterialStateProperty.all(
|
|
|
|
RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
side: BorderSide(
|
|
|
|
width: 1,
|
|
|
|
color:
|
|
|
|
Theme.of(context).colorScheme.secondary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
backgroundColor: MaterialStateProperty.all(
|
2022-09-01 02:25:19 +02:00
|
|
|
Colors.transparent,
|
2022-08-31 12:05:38 +02:00
|
|
|
),
|
|
|
|
foregroundColor: MaterialStateProperty.all(
|
|
|
|
Theme.of(context).colorScheme.secondary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
: Container(),
|
2022-08-13 11:56:30 +02:00
|
|
|
],
|
|
|
|
),
|
2022-08-07 20:05:44 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-08-31 12:05:38 +02:00
|
|
|
|
|
|
|
Future<void> _showUnsupportedWarningDialog() {
|
2022-09-02 01:10:41 +02:00
|
|
|
return showDialog(
|
2022-08-31 12:05:38 +02:00
|
|
|
context: context,
|
2022-09-02 01:10:41 +02:00
|
|
|
builder: (context) => AlertDialog(
|
|
|
|
title: I18nText('patchItem.alertDialogTitle'),
|
|
|
|
content: I18nText(
|
|
|
|
'patchItem.alertDialogText',
|
|
|
|
translationParams: {
|
|
|
|
'packageVersion': widget.packageVersion,
|
|
|
|
'supportedVersions':
|
|
|
|
'\u2022 ${widget.supportedPackageVersions.join('\n\u2022 ')}',
|
|
|
|
},
|
2022-09-01 02:25:19 +02:00
|
|
|
),
|
2022-09-02 01:10:41 +02:00
|
|
|
actions: [
|
|
|
|
PatchTextButton(
|
|
|
|
text: FlutterI18n.translate(context, 'okButton'),
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.secondary,
|
|
|
|
borderColor: Theme.of(context).colorScheme.secondary,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
2022-09-01 02:25:19 +02:00
|
|
|
),
|
2022-08-31 12:05:38 +02:00
|
|
|
);
|
|
|
|
}
|
2022-08-07 20:05:44 +02:00
|
|
|
}
|