revanced-manager/lib/ui/widgets/homeView/latest_commit_card.dart
2022-09-07 12:01:04 +01:00

131 lines
4.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/services/github_api.dart';
import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/ui/views/home/home_viewmodel.dart';
import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
class LatestCommitCard extends StatefulWidget {
final Function() onPressed;
const LatestCommitCard({
Key? key,
required this.onPressed,
}) : super(key: key);
@override
State<LatestCommitCard> createState() => _LatestCommitCardState();
}
class _LatestCommitCardState extends State<LatestCommitCard> {
final ManagerAPI _managerAPI = locator<ManagerAPI>();
final GithubAPI _githubAPI = GithubAPI();
@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',
child: Text(
'',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.secondary,
),
),
),
FutureBuilder<String>(
future: _githubAPI.latestCommitTime(
_managerAPI.getPatcherRepo(),
),
builder: (context, snapshot) => Text(
snapshot.hasData && snapshot.data!.isNotEmpty
? FlutterI18n.translate(
context,
'latestCommitCard.timeagoLabel',
translationParams: {'time': snapshot.data!},
)
: FlutterI18n.translate(
context,
'latestCommitCard.loadingLabel',
),
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
),
),
),
],
),
const SizedBox(height: 8),
Row(
children: <Widget>[
I18nText(
'latestCommitCard.managerLabel',
child: Text(
'',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.secondary,
),
),
),
FutureBuilder<String>(
future: _githubAPI.latestCommitTime(
_managerAPI.getManagerRepo(),
),
builder: (context, snapshot) => snapshot.hasData &&
snapshot.data!.isNotEmpty
? I18nText(
'latestCommitCard.timeagoLabel',
translationParams: {'time': snapshot.data!},
child: Text(
'',
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
),
),
)
: I18nText(
'latestCommitCard.loadingLabel',
child: Text(
'',
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
),
),
),
),
],
),
],
),
FutureBuilder<bool>(
future: locator<HomeViewModel>().hasManagerUpdates(),
initialData: false,
builder: (context, snapshot) => Opacity(
opacity: snapshot.hasData && snapshot.data! ? 1.0 : 0.5,
child: CustomMaterialButton(
isExpanded: false,
label: I18nText('latestCommitCard.updateButton'),
onPressed: snapshot.hasData && snapshot.data!
? widget.onPressed
: () => {},
),
),
),
],
),
);
}
}