refactor: apply suggestions from analyser

Signed-off-by: validcube <pun.butrach@gmail.com>
This commit is contained in:
validcube
2023-12-23 10:47:12 +07:00
parent c56c445fb7
commit a0b673c138
18 changed files with 120 additions and 79 deletions

View File

@ -25,7 +25,8 @@ class DynamicThemeBuilder extends StatefulWidget {
State<DynamicThemeBuilder> createState() => _DynamicThemeBuilderState();
}
class _DynamicThemeBuilderState extends State<DynamicThemeBuilder> with WidgetsBindingObserver {
class _DynamicThemeBuilderState extends State<DynamicThemeBuilder>
with WidgetsBindingObserver {
Brightness brightness = PlatformDispatcher.instance.platformBrightness;
final ManagerAPI _managerAPI = locator<ManagerAPI>();
@ -43,8 +44,9 @@ class _DynamicThemeBuilderState extends State<DynamicThemeBuilder> with WidgetsB
if (_managerAPI.getThemeMode() < 2) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
systemNavigationBarIconBrightness:
brightness == Brightness.light ? Brightness.dark : Brightness.light,
systemNavigationBarIconBrightness: brightness == Brightness.light
? Brightness.dark
: Brightness.light,
),
);
}
@ -83,24 +85,31 @@ class _DynamicThemeBuilderState extends State<DynamicThemeBuilder> with WidgetsB
return DynamicTheme(
themeCollection: ThemeCollection(
themes: {
0: brightness == Brightness.light ? lightCustomTheme : darkCustomTheme,
1: brightness == Brightness.light ? lightDynamicTheme : darkDynamicTheme,
0: brightness == Brightness.light
? lightCustomTheme
: darkCustomTheme,
1: brightness == Brightness.light
? lightDynamicTheme
: darkDynamicTheme,
2: lightCustomTheme,
3: lightDynamicTheme,
4: darkCustomTheme,
5: darkDynamicTheme,
},
fallbackTheme: PlatformDispatcher.instance.platformBrightness == Brightness.light ? lightCustomTheme : darkCustomTheme,
fallbackTheme: PlatformDispatcher.instance.platformBrightness ==
Brightness.light
? lightCustomTheme
: darkCustomTheme,
),
builder: (context, theme) => MaterialApp(
debugShowCheckedModeBanner: false,
title: widget.title,
navigatorKey: StackedService.navigatorKey,
onGenerateRoute: StackedRouter().onGenerateRoute,
theme: theme,
home: widget.home,
localizationsDelegates: widget.localizationsDelegates,
),
debugShowCheckedModeBanner: false,
title: widget.title,
navigatorKey: StackedService.navigatorKey,
onGenerateRoute: StackedRouter().onGenerateRoute,
theme: theme,
home: widget.home,
localizationsDelegates: widget.localizationsDelegates,
),
);
},
);

View File

@ -40,8 +40,8 @@ class _AppSelectorViewState extends State<AppSelectorView> {
),
titleTextStyle: TextStyle(
fontSize: 22.0,
color: Theme.of(context).textTheme.titleLarge!.color,
),
color: Theme.of(context).textTheme.titleLarge!.color,
),
leading: IconButton(
icon: Icon(
Icons.arrow_back,
@ -94,9 +94,7 @@ class _AppSelectorViewState extends State<AppSelectorView> {
),
child: Column(
children: [
...model
.getFilteredApps(_query)
.map(
...model.getFilteredApps(_query).map(
(app) => InstalledAppItem(
name: app.appName,
pkgName: app.packageName,
@ -117,11 +115,8 @@ class _AppSelectorViewState extends State<AppSelectorView> {
packageName: app.packageName,
),
),
)
,
...model
.getFilteredAppsNames(_query)
.map(
),
...model.getFilteredAppsNames(_query).map(
(app) => NotInstalledAppItem(
name: app,
patchesCount: model.patchesCount(app),
@ -135,8 +130,7 @@ class _AppSelectorViewState extends State<AppSelectorView> {
packageName: app,
),
),
)
,
),
const SizedBox(height: 70.0),
],
),

View File

@ -83,7 +83,6 @@ class HomeViewModel extends BaseViewModel {
_managerAPI.reAssessSavedApps().then((_) => _getPatchedApps());
}
void navigateToAppInfo(PatchedApplication app) {
_navigationService.navigateTo(
Routes.appInfoView,
@ -366,7 +365,10 @@ class HomeViewModel extends BaseViewModel {
alignment: Alignment.centerRight,
child: FilledButton(
onPressed: () async {
await _patcherAPI.installApk(context, downloadedApk!.path);
await _patcherAPI.installApk(
context,
downloadedApk!.path,
);
},
child: I18nText('updateButton'),
),

View File

@ -183,7 +183,9 @@ class InstallerViewModel extends BaseViewModel {
final index = logLines.indexWhere((line) => line.endsWith(keyword));
if (newString != null && lineCount > 0) {
logLines.insert(
index, newString.replaceAll('{lineCount}', lineCount.toString()));
index,
newString.replaceAll('{lineCount}', lineCount.toString()),
);
}
logLines.removeWhere((lines) => lines.endsWith(keyword));
}
@ -203,11 +205,13 @@ class InstallerViewModel extends BaseViewModel {
return 'None';
}
return patches
.map((p) =>
p.name +
(p.options.isEmpty
? ''
: ' [${p.options.map((o) => '${o.title}: ${_getPatchOptionValue(p.name, o)}').join(", ")}]'))
.map(
(p) =>
p.name +
(p.options.isEmpty
? ''
: ' [${p.options.map((o) => '${o.title}: ${_getPatchOptionValue(p.name, o)}').join(", ")}]'),
)
.toList()
.join(', ');
}
@ -242,9 +246,11 @@ class InstallerViewModel extends BaseViewModel {
// Options changed
final patchesChanged = defaultPatches
.where((p) =>
_patches.contains(p) &&
p.options.any((o) => _getPatchOptionValue(p.name, o) != o.value))
.where(
(p) =>
_patches.contains(p) &&
p.options.any((o) => _getPatchOptionValue(p.name, o) != o.value),
)
.toList();
// Add Info
@ -453,9 +459,7 @@ class InstallerViewModel extends BaseViewModel {
update(
1.0,
'Installing...',
_app.isRooted
? 'Mounting patched app'
: 'Installing patched app',
_app.isRooted ? 'Mounting patched app' : 'Installing patched app',
);
}
final int response = await _patcherAPI.installPatchedFile(context, _app);

View File

@ -22,7 +22,7 @@ class PatcherView extends StatelessWidget {
child: FloatingActionButton.extended(
label: I18nText('patcherView.patchButton'),
icon: const Icon(Icons.build),
onPressed: () async{
onPressed: () async {
if (model.checkRequiredPatchOption(context)) {
final bool proceed = model.showRemovedPatchesDialog(context);
if (proceed && context.mounted) {

View File

@ -180,11 +180,16 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
),
],
),
if (model.getQueriedPatches(_query).any((patch) => model.isPatchNew(patch)))
if (model
.getQueriedPatches(_query)
.any((patch) => model.isPatchNew(patch)))
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
model.getPatchCategory(context, 'patchesSelectorView.newPatches'),
model.getPatchCategory(
context,
'patchesSelectorView.newPatches',
),
...model.getQueriedPatches(_query).map((patch) {
if (model.isPatchNew(patch)) {
return model.getPatchItem(context, patch);
@ -192,26 +197,40 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
return Container();
}
}),
if (model.getQueriedPatches(_query).any((patch) => !model.isPatchNew(patch) && patch.compatiblePackages.isNotEmpty))
model.getPatchCategory(context, 'patchesSelectorView.patches'),
if (model.getQueriedPatches(_query).any(
(patch) =>
!model.isPatchNew(patch) &&
patch.compatiblePackages.isNotEmpty,
))
model.getPatchCategory(
context,
'patchesSelectorView.patches',
),
],
),
...model.getQueriedPatches(_query).map(
(patch) {
if (patch.compatiblePackages.isNotEmpty && !model.isPatchNew(patch)) {
if (patch.compatiblePackages.isNotEmpty &&
!model.isPatchNew(patch)) {
return model.getPatchItem(context, patch);
} else {
return Container();
}
},
),
if (model.getQueriedPatches(_query).any((patch) => patch.compatiblePackages.isEmpty))
if (model
.getQueriedPatches(_query)
.any((patch) => patch.compatiblePackages.isEmpty))
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
model.getPatchCategory(context, 'patchesSelectorView.universalPatches'),
model.getPatchCategory(
context,
'patchesSelectorView.universalPatches',
),
...model.getQueriedPatches(_query).map((patch) {
if (patch.compatiblePackages.isEmpty && !model.isPatchNew(patch)) {
if (patch.compatiblePackages.isEmpty &&
!model.isPatchNew(patch)) {
return model.getPatchItem(context, patch);
} else {
return Container();

View File

@ -58,7 +58,8 @@ class PatchSelectorCard extends StatelessWidget {
String _getPatchesSelection() {
String text = '';
final List<Patch> selectedPatches = locator<PatcherViewModel>().selectedPatches;
final List<Patch> selectedPatches =
locator<PatcherViewModel>().selectedPatches;
selectedPatches.sort((a, b) => a.name.compareTo(b.name));
for (final Patch p in selectedPatches) {
text += '${p.getSimpleName()}\n';

View File

@ -400,7 +400,9 @@ class _TextFieldForPatchOptionState extends State<TextFieldForPatchOption> {
final bool isStringOption = widget.optionType.contains('String');
final bool isArrayOption = widget.optionType.contains('Array');
selectedKey ??= widget.selectedKey;
controller.text = !isStringOption && isArrayOption && selectedKey == '' &&
controller.text = !isStringOption &&
isArrayOption &&
selectedKey == '' &&
(widget.value != null && widget.value.toString().startsWith('['))
? ''
: widget.value ?? '';
@ -519,7 +521,8 @@ class _TextFieldForPatchOptionState extends State<TextFieldForPatchOption> {
}
break;
case 'patchOptionsView.selectFolder':
final DirectoryLocation? result = await FlutterFileDialog.pickDirectory();
final DirectoryLocation? result =
await FlutterFileDialog.pickDirectory();
if (result != null) {
controller.text = result.toString();
widget.onChanged(controller.text);

View File

@ -10,7 +10,6 @@ import 'package:revanced_manager/ui/widgets/settingsView/settings_section.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_universal_patches.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_version_compatibility_check.dart';
class SAdvancedSection extends StatelessWidget {
const SAdvancedSection({super.key});

View File

@ -6,7 +6,8 @@ class SEnablePatchesSelection extends StatefulWidget {
const SEnablePatchesSelection({super.key});
@override
State<SEnablePatchesSelection> createState() => _SEnablePatchesSelectionState();
State<SEnablePatchesSelection> createState() =>
_SEnablePatchesSelectionState();
}
final _settingsViewModel = SettingsViewModel();

View File

@ -6,12 +6,14 @@ class SRequireSuggestedAppVersion extends StatefulWidget {
const SRequireSuggestedAppVersion({super.key});
@override
State<SRequireSuggestedAppVersion> createState() => _SRequireSuggestedAppVersionState();
State<SRequireSuggestedAppVersion> createState() =>
_SRequireSuggestedAppVersionState();
}
final _settingsViewModel = SettingsViewModel();
class _SRequireSuggestedAppVersionState extends State<SRequireSuggestedAppVersion> {
class _SRequireSuggestedAppVersionState
extends State<SRequireSuggestedAppVersion> {
@override
Widget build(BuildContext context) {
return SwitchListTile(
@ -29,8 +31,11 @@ class _SRequireSuggestedAppVersionState extends State<SRequireSuggestedAppVersio
subtitle: I18nText('settingsView.requireSuggestedAppVersionHint'),
value: _settingsViewModel.isRequireSuggestedAppVersionEnabled(),
onChanged: (value) async {
await _settingsViewModel.showRequireSuggestedAppVersionDialog(context, value,);
setState(() {});
await _settingsViewModel.showRequireSuggestedAppVersionDialog(
context,
value,
);
setState(() {});
},
);
}

View File

@ -8,16 +8,14 @@ class SUniversalPatches extends StatefulWidget {
const SUniversalPatches({super.key});
@override
State<SUniversalPatches> createState() =>
_SUniversalPatchesState();
State<SUniversalPatches> createState() => _SUniversalPatchesState();
}
final _settingsViewModel = SettingsViewModel();
final _patchesSelectorViewModel = PatchesSelectorViewModel();
final _patcherViewModel = PatcherViewModel();
class _SUniversalPatchesState
extends State<SUniversalPatches> {
class _SUniversalPatchesState extends State<SUniversalPatches> {
@override
Widget build(BuildContext context) {
return SwitchListTile(

View File

@ -9,14 +9,16 @@ class SVersionCompatibilityCheck extends StatefulWidget {
const SVersionCompatibilityCheck({super.key});
@override
State<SVersionCompatibilityCheck> createState() => _SVersionCompatibilityCheckState();
State<SVersionCompatibilityCheck> createState() =>
_SVersionCompatibilityCheckState();
}
final _settingsViewModel = SettingsViewModel();
final _patchesSelectorViewModel = PatchesSelectorViewModel();
final _patcherViewModel = PatcherViewModel();
class _SVersionCompatibilityCheckState extends State<SVersionCompatibilityCheck> {
class _SVersionCompatibilityCheckState
extends State<SVersionCompatibilityCheck> {
@override
Widget build(BuildContext context) {
return SwitchListTile(