revanced-manager/lib/ui/widgets/homeView/latest_commit_card.dart

89 lines
3.2 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2022-08-07 01:37:12 +02:00
import 'package:flutter_i18n/flutter_i18n.dart';
2022-08-18 18:32:58 +02:00
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/ui/views/home/home_viewmodel.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
2022-08-01 20:15:55 +02:00
class LatestCommitCard extends StatefulWidget {
2022-08-18 16:33:33 +02:00
final Function() onPressed;
2022-08-11 22:17:10 +02:00
const LatestCommitCard({
Key? key,
2022-08-18 16:33:33 +02:00
required this.onPressed,
2022-08-11 22:17:10 +02:00
}) : super(key: key);
@override
2022-08-01 20:15:55 +02:00
State<LatestCommitCard> createState() => _LatestCommitCardState();
}
2022-08-01 20:15:55 +02:00
class _LatestCommitCardState extends State<LatestCommitCard> {
final HomeViewModel model = locator<HomeViewModel>();
@override
Widget build(BuildContext context) {
return CustomCard(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
I18nText('latestCommitCard.patcherLabel'),
FutureBuilder<String?>(
future: model.getLatestPatcherReleaseTime(),
builder: (context, snapshot) => Text(
snapshot.hasData && snapshot.data!.isNotEmpty
2022-08-17 14:25:08 +02:00
? FlutterI18n.translate(
context,
'latestCommitCard.timeagoLabel',
translationParams: {'time': snapshot.data!},
)
2022-08-17 14:18:08 +02:00
: FlutterI18n.translate(
context,
'latestCommitCard.loadingLabel',
),
),
),
],
),
const SizedBox(height: 4),
Row(
children: <Widget>[
I18nText('latestCommitCard.managerLabel'),
FutureBuilder<String?>(
future: model.getLatestManagerReleaseTime(),
builder: (context, snapshot) =>
snapshot.hasData && snapshot.data!.isNotEmpty
? I18nText(
'latestCommitCard.timeagoLabel',
translationParams: {'time': snapshot.data!},
)
: I18nText('latestCommitCard.loadingLabel'),
),
],
2022-08-01 10:38:22 +02:00
),
],
),
2022-08-18 18:32:58 +02:00
FutureBuilder<bool>(
future: locator<HomeViewModel>().hasManagerUpdates(),
initialData: false,
builder: (context, snapshot) => Opacity(
2022-09-17 10:02:49 +02:00
opacity: snapshot.hasData && snapshot.data! ? 1.0 : 0.25,
child: CustomMaterialButton(
isExpanded: false,
label: I18nText('latestCommitCard.updateButton'),
2022-08-18 18:32:58 +02:00
onPressed: snapshot.hasData && snapshot.data!
? widget.onPressed
: () => {},
),
2022-08-07 01:37:12 +02:00
),
2022-08-01 10:38:22 +02:00
),
],
),
);
}
}