refactor: improve code readability according to formatter

This commit is contained in:
Pun Butrach 2023-07-10 19:36:50 +07:00
parent b272988929
commit 6a45db8a38
No known key found for this signature in database
GPG Key ID: 5F47D61B676D07F6
9 changed files with 55 additions and 48 deletions

View File

@ -73,20 +73,29 @@ class GithubAPI {
} }
Future<Map<String, dynamic>?> getLatestManagerRelease( Future<Map<String, dynamic>?> getLatestManagerRelease(
String repoName, String repoName,
) async { ) async {
try { try {
final response = await _dio.get( final response = await _dio.get(
'/repos/$repoName/releases', '/repos/$repoName/releases',
); );
final Map<String, dynamic> releases = response.data[0]; final Map<String, dynamic> releases = response.data[0];
int updates = 0; int updates = 0;
final String currentVersion = await ManagerAPI().getCurrentManagerVersion(); final String currentVersion =
await ManagerAPI().getCurrentManagerVersion();
while (response.data[updates]['tag_name'] != 'v$currentVersion') { while (response.data[updates]['tag_name'] != 'v$currentVersion') {
updates++; updates++;
} }
for(int i = 1; i < updates; i++){ for (int i = 1; i < updates; i++) {
releases.update('body', (value) => value + '\n' + '# '+ response.data[i]['tag_name']+'\n' + response.data[i]['body']); releases.update(
'body',
(value) =>
value +
'\n' +
'# ' +
response.data[i]['tag_name'] +
'\n' +
response.data[i]['body']);
} }
return releases; return releases;
} on Exception catch (e) { } on Exception catch (e) {

View File

@ -140,7 +140,8 @@ class RevancedAPI {
return null; return null;
} }
StreamController<double> managerUpdateProgress = StreamController<double>.broadcast(); StreamController<double> managerUpdateProgress =
StreamController<double>.broadcast();
void updateManagerDownloadProgress(int progress) { void updateManagerDownloadProgress(int progress) {
managerUpdateProgress.add(progress.toDouble()); managerUpdateProgress.add(progress.toDouble());

View File

@ -17,8 +17,7 @@ import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart'; import 'package:stacked_services/stacked_services.dart';
class SettingsViewModel extends BaseViewModel { class SettingsViewModel extends BaseViewModel {
final NavigationService _navigationService = final NavigationService _navigationService = locator<NavigationService>();
locator<NavigationService>();
final ManagerAPI _managerAPI = locator<ManagerAPI>(); final ManagerAPI _managerAPI = locator<ManagerAPI>();
final Toast _toast = locator<Toast>(); final Toast _toast = locator<Toast>();
@ -63,11 +62,8 @@ class SettingsViewModel extends BaseViewModel {
try { try {
final File outFile = File(_managerAPI.storedPatchesFile); final File outFile = File(_managerAPI.storedPatchesFile);
if (outFile.existsSync()) { if (outFile.existsSync()) {
final String dateTime = DateTime.now() final String dateTime =
.toString() DateTime.now().toString().replaceAll(' ', '_').split('.').first;
.replaceAll(' ', '_')
.split('.')
.first;
await CRFileSaver.saveFileWithDialog( await CRFileSaver.saveFileWithDialog(
SaveFileDialogParams( SaveFileDialogParams(
sourceFilePath: outFile.path, sourceFilePath: outFile.path,
@ -87,8 +83,7 @@ class SettingsViewModel extends BaseViewModel {
Future<void> importPatches() async { Future<void> importPatches() async {
try { try {
final FilePickerResult? result = final FilePickerResult? result = await FilePicker.platform.pickFiles(
await FilePicker.platform.pickFiles(
type: FileType.custom, type: FileType.custom,
allowedExtensions: ['json'], allowedExtensions: ['json'],
); );
@ -109,7 +104,7 @@ class SettingsViewModel extends BaseViewModel {
} }
} }
Future<void> exportKeystore() async { Future<void> exportKeystore() async {
try { try {
final File outFile = File(_managerAPI.keystoreFile); final File outFile = File(_managerAPI.keystoreFile);
if (outFile.existsSync()) { if (outFile.existsSync()) {
@ -138,7 +133,7 @@ class SettingsViewModel extends BaseViewModel {
if (result != null && result.files.single.path != null) { if (result != null && result.files.single.path != null) {
final File inFile = File(result.files.single.path!); final File inFile = File(result.files.single.path!);
inFile.copySync(_managerAPI.keystoreFile); inFile.copySync(_managerAPI.keystoreFile);
_toast.showBottom('settingsView.importedKeystore'); _toast.showBottom('settingsView.importedKeystore');
} }
} on Exception catch (e) { } on Exception catch (e) {

View File

@ -34,7 +34,8 @@ class AppSkeletonLoader extends StatelessWidget {
style: SkeletonLineStyle( style: SkeletonLineStyle(
height: 20, height: 20,
width: screenWidth * 0.4, width: screenWidth * 0.4,
borderRadius: const BorderRadius.all(Radius.circular(10)), borderRadius:
const BorderRadius.all(Radius.circular(10)),
), ),
), ),
), ),
@ -45,7 +46,8 @@ class AppSkeletonLoader extends StatelessWidget {
style: SkeletonLineStyle( style: SkeletonLineStyle(
height: 15, height: 15,
width: screenWidth * 0.6, width: screenWidth * 0.6,
borderRadius: const BorderRadius.all(Radius.circular(10)), borderRadius:
const BorderRadius.all(Radius.circular(10)),
), ),
), ),
), ),
@ -56,7 +58,8 @@ class AppSkeletonLoader extends StatelessWidget {
style: SkeletonLineStyle( style: SkeletonLineStyle(
height: 15, height: 15,
width: screenWidth * 0.5, width: screenWidth * 0.5,
borderRadius: const BorderRadius.all(Radius.circular(10)), borderRadius:
const BorderRadius.all(Radius.circular(10)),
), ),
), ),
), ),

View File

@ -66,7 +66,7 @@ class _InstalledAppItemState extends State<InstalledAppItem> {
context, context,
'installed', 'installed',
translationParams: { translationParams: {
'version':'v${widget.installedVersion}' 'version': 'v${widget.installedVersion}'
}, },
), ),
), ),
@ -75,8 +75,9 @@ class _InstalledAppItemState extends State<InstalledAppItem> {
I18nText( I18nText(
'suggested', 'suggested',
translationParams: { translationParams: {
'version' : widget.suggestedVersion.isEmpty 'version': widget.suggestedVersion.isEmpty
? FlutterI18n.translate(context, 'appSelectorCard.allVersions') ? FlutterI18n.translate(
context, 'appSelectorCard.allVersions')
: 'v${widget.suggestedVersion}', : 'v${widget.suggestedVersion}',
}, },
), ),

View File

@ -60,8 +60,7 @@ class _NotInstalledAppItem extends State<NotInstalledAppItem> {
child: Text( child: Text(
'', '',
style: TextStyle( style: TextStyle(
color: color: Theme.of(context).textTheme.titleLarge!.color,
Theme.of(context).textTheme.titleLarge!.color,
), ),
), ),
), ),
@ -70,8 +69,9 @@ class _NotInstalledAppItem extends State<NotInstalledAppItem> {
I18nText( I18nText(
'suggested', 'suggested',
translationParams: { translationParams: {
'version' : widget.suggestedVersion.isEmpty 'version': widget.suggestedVersion.isEmpty
? FlutterI18n.translate(context, 'appSelectorCard.allVersions') ? FlutterI18n.translate(
context, 'appSelectorCard.allVersions')
: 'v${widget.suggestedVersion}', : 'v${widget.suggestedVersion}',
}, },
), ),

View File

@ -45,8 +45,7 @@ class UpdateConfirmationDialog extends StatelessWidget {
children: [ children: [
Expanded( Expanded(
child: Column( child: Column(
crossAxisAlignment: crossAxisAlignment: CrossAxisAlignment.start,
CrossAxisAlignment.start,
children: [ children: [
I18nText( I18nText(
'homeView.updateDialogTitle', 'homeView.updateDialogTitle',
@ -63,14 +62,12 @@ class UpdateConfirmationDialog extends StatelessWidget {
children: [ children: [
Icon( Icon(
Icons.new_releases_outlined, Icons.new_releases_outlined,
color: Theme.of(context) color:
.colorScheme Theme.of(context).colorScheme.secondary,
.secondary,
), ),
const SizedBox(width: 8.0), const SizedBox(width: 8.0),
Text( Text(
snapshot.data!['tag_name'] ?? snapshot.data!['tag_name'] ?? 'Unknown',
'Unknown',
style: TextStyle( style: TextStyle(
fontSize: 20, fontSize: 20,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
@ -96,8 +93,7 @@ class UpdateConfirmationDialog extends StatelessWidget {
), ),
), ),
Padding( Padding(
padding: padding: const EdgeInsets.only(left: 24.0, bottom: 12.0),
const EdgeInsets.only(left: 24.0, bottom: 12.0),
child: I18nText( child: I18nText(
'homeView.updateChangelogTitle', 'homeView.updateChangelogTitle',
child: Text( child: Text(
@ -113,12 +109,9 @@ class UpdateConfirmationDialog extends StatelessWidget {
), ),
), ),
Container( Container(
margin: margin: const EdgeInsets.symmetric(horizontal: 24.0),
const EdgeInsets.symmetric(horizontal: 24.0),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context) color: Theme.of(context).colorScheme.secondaryContainer,
.colorScheme
.secondaryContainer,
borderRadius: BorderRadius.circular(12.0), borderRadius: BorderRadius.circular(12.0),
), ),
child: Markdown( child: Markdown(

View File

@ -42,7 +42,9 @@ class PatchItem extends StatefulWidget {
class _PatchItemState extends State<PatchItem> { class _PatchItemState extends State<PatchItem> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
widget.isSelected = widget.isSelected && (!widget.isUnsupported || widget._managerAPI.areExperimentalPatchesEnabled()); widget.isSelected = widget.isSelected &&
(!widget.isUnsupported ||
widget._managerAPI.areExperimentalPatchesEnabled());
return Padding( return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0), padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Opacity( child: Opacity(
@ -117,7 +119,7 @@ class _PatchItemState extends State<PatchItem> {
value: widget.isSelected, value: widget.isSelected,
activeColor: Theme.of(context).colorScheme.primary, activeColor: Theme.of(context).colorScheme.primary,
checkColor: checkColor:
Theme.of(context).colorScheme.secondaryContainer, Theme.of(context).colorScheme.secondaryContainer,
side: BorderSide( side: BorderSide(
width: 2.0, width: 2.0,
color: Theme.of(context).colorScheme.primary, color: Theme.of(context).colorScheme.primary,
@ -128,14 +130,15 @@ class _PatchItemState extends State<PatchItem> {
!widget._managerAPI !widget._managerAPI
.areExperimentalPatchesEnabled()) { .areExperimentalPatchesEnabled()) {
widget.isSelected = false; widget.isSelected = false;
widget.toast widget.toast.showBottom(
.showBottom('patchItem.unsupportedPatchVersion'); 'patchItem.unsupportedPatchVersion');
} else { } else {
widget.isSelected = newValue!; widget.isSelected = newValue!;
} }
if (widget.isUnsupported && if (widget.isUnsupported &&
widget.isSelected && widget.isSelected &&
!selectedUnsupportedPatches.contains(widget.name)) { !selectedUnsupportedPatches
.contains(widget.name)) {
selectedUnsupportedPatches.add(widget.name); selectedUnsupportedPatches.add(widget.name);
} }
}); });

View File

@ -34,9 +34,11 @@ class _SExperimentalPatchesState extends State<SExperimentalPatches> {
setState(() { setState(() {
_settingsViewModel.useExperimentalPatches(value); _settingsViewModel.useExperimentalPatches(value);
}); });
if(!value) { if (!value) {
for (final patch in selectedUnsupportedPatches) { for (final patch in selectedUnsupportedPatches) {
PatchesSelectorViewModel().selectedPatches.removeWhere((element) => patch == element.name); PatchesSelectorViewModel()
.selectedPatches
.removeWhere((element) => patch == element.name);
} }
selectedUnsupportedPatches.clear(); selectedUnsupportedPatches.clear();
} }