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/constants.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 createState() => _LatestCommitCardState(); } class _LatestCommitCardState extends State { final GithubAPI _githubAPI = GithubAPI(); @override Widget build(BuildContext context) { return CustomCard( child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ I18nText( 'latestCommitCard.patcherLabel', child: const Text( '', style: TextStyle(fontWeight: FontWeight.bold), ), ), FutureBuilder( future: _githubAPI.latestCommitTime(ghOrg, patcherRepo), builder: (context, snapshot) => Text( snapshot.hasData && snapshot.data!.isNotEmpty ? FlutterI18n.translate( context, 'latestCommitCard.timeagoLabel', translationParams: {'time': snapshot.data!}, ) : FlutterI18n.translate( context, 'latestCommitCard.loadingLabel', ), ), ), ], ), const SizedBox(height: 8), Row( children: [ I18nText( 'latestCommitCard.managerLabel', child: const Text( '', style: TextStyle(fontWeight: FontWeight.bold), ), ), FutureBuilder( future: _githubAPI.latestCommitTime(ghOrg, managerRepo), builder: (context, snapshot) => snapshot.hasData && snapshot.data!.isNotEmpty ? I18nText( 'latestCommitCard.timeagoLabel', translationParams: {'time': snapshot.data!}, ) : I18nText('latestCommitCard.loadingLabel'), ), ], ), ], ), FutureBuilder( future: locator().hasManagerUpdates(), initialData: false, builder: (context, snapshot) => Opacity( opacity: snapshot.hasData && snapshot.data! ? 1.0 : 1.0, child: CustomMaterialButton( isExpanded: false, label: I18nText('latestCommitCard.updateButton'), onPressed: snapshot.hasData && snapshot.data! ? widget.onPressed : () => {}, ), ), ), ], ), ); } }