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

134 lines
4.9 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2022-08-07 00:37:12 +01:00
import 'package:flutter_i18n/flutter_i18n.dart';
2022-08-18 17:32:58 +01: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_card.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
2022-08-01 23:45:55 +05:30
class LatestCommitCard extends StatefulWidget {
2022-08-12 01:47:10 +05:30
const LatestCommitCard({
2023-11-11 19:07:32 +07:00
super.key,
required this.model,
required this.parentContext,
2023-11-11 19:07:32 +07:00
});
final HomeViewModel model;
final BuildContext parentContext;
@override
2022-08-01 23:45:55 +05:30
State<LatestCommitCard> createState() => _LatestCommitCardState();
}
2022-08-01 23:45:55 +05:30
class _LatestCommitCardState extends State<LatestCommitCard> {
final HomeViewModel model = locator<HomeViewModel>();
@override
Widget build(BuildContext context) {
return Column(
children: [
// ReVanced Manager
CustomCard(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
2023-08-03 14:38:38 -07:00
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Text('ReVanced Manager'),
const SizedBox(height: 4),
Row(
children: <Widget>[
FutureBuilder<String?>(
future: model.getLatestManagerReleaseTime(),
builder: (context, snapshot) => snapshot.hasData &&
snapshot.data!.isNotEmpty
? I18nText(
'latestCommitCard.timeagoLabel',
translationParams: {'time': snapshot.data!},
)
: I18nText('latestCommitCard.loadingLabel'),
),
],
),
],
),
),
FutureBuilder<bool>(
future: model.hasManagerUpdates(),
initialData: false,
builder: (context, snapshot) => Opacity(
opacity: snapshot.hasData && snapshot.data! ? 1.0 : 0.25,
child: CustomMaterialButton(
label: I18nText('updateButton'),
onPressed: snapshot.hasData && snapshot.data!
? () => widget.model.showUpdateConfirmationDialog(
widget.parentContext,
false,
)
: () => {},
),
),
2022-08-01 14:08:22 +05:30
),
],
),
),
const SizedBox(height: 16),
// Patches
CustomCard(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
2023-08-03 14:38:38 -07:00
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Text('Patches'),
2023-08-03 14:38:38 -07:00
const SizedBox(height: 4),
Row(
children: <Widget>[
FutureBuilder<String?>(
future: model.getLatestPatchesReleaseTime(),
builder: (context, snapshot) => Text(
snapshot.hasData && snapshot.data!.isNotEmpty
? FlutterI18n.translate(
context,
'latestCommitCard.timeagoLabel',
translationParams: {'time': snapshot.data!},
)
: FlutterI18n.translate(
context,
'latestCommitCard.loadingLabel',
),
),
),
2023-08-03 14:38:38 -07:00
],
),
],
),
2022-08-18 17:32:58 +01:00
),
FutureBuilder<bool>(
future: locator<HomeViewModel>().hasPatchesUpdates(),
initialData: false,
builder: (context, snapshot) => Opacity(
opacity: snapshot.hasData && snapshot.data! ? 1.0 : 0.25,
child: CustomMaterialButton(
label: I18nText('updateButton'),
onPressed: snapshot.hasData && snapshot.data!
? () => widget.model.showUpdateConfirmationDialog(
widget.parentContext,
true,
)
: () => {},
),
),
),
],
2022-08-01 14:08:22 +05:30
),
),
],
);
}
}