Broke GeneratedFormItem into sub-types

Prep for "chips" input type
This commit is contained in:
Imran Remtulla
2022-12-21 18:23:25 -05:00
parent 3cbaac2f5d
commit 9072862862
21 changed files with 238 additions and 188 deletions

View File

@@ -27,7 +27,7 @@ class _AddAppPageState extends State<AddAppPage> {
String userInput = '';
String searchQuery = '';
AppSource? pickedSource;
Map<String, String> additionalSettings = {};
Map<String, dynamic> additionalSettings = {};
bool additionalSettingsValid = true;
@override
@@ -66,9 +66,9 @@ class _AddAppPageState extends State<AddAppPage> {
});
var settingsProvider = context.read<SettingsProvider>();
() async {
var userPickedTrackOnly = additionalSettings['trackOnly'] == 'true';
var userPickedTrackOnly = additionalSettings['trackOnly'] == true;
var userPickedNoVersionDetection =
additionalSettings['noVersionDetection'] == 'true';
additionalSettings['noVersionDetection'] == true;
var cont = true;
if ((userPickedTrackOnly || pickedSource!.enforceTrackOnly) &&
await showDialog(
@@ -113,7 +113,7 @@ class _AddAppPageState extends State<AddAppPage> {
}
// Only download the APK here if you need to for the package ID
if (sourceProvider.isTempId(app.id) &&
app.additionalSettings['trackOnly'] != 'true') {
app.additionalSettings['trackOnly'] != true) {
// ignore: use_build_context_synchronously
var apkUrl = await appsProvider.confirmApkUrl(app, context);
if (apkUrl == null) {
@@ -128,7 +128,7 @@ class _AddAppPageState extends State<AddAppPage> {
if (appsProvider.apps.containsKey(app.id)) {
throw ObtainiumError(tr('appAlreadyAdded'));
}
if (app.additionalSettings['trackOnly'] == 'true') {
if (app.additionalSettings['trackOnly'] == true) {
app.installedVersion = app.latestVersion;
}
await appsProvider.saveApps([app]);
@@ -169,7 +169,7 @@ class _AddAppPageState extends State<AddAppPage> {
child: GeneratedForm(
items: [
[
GeneratedFormItem('appSourceURL',
GeneratedFormTextField('appSourceURL',
label: tr('appSourceURL'),
additionalValidators: [
(value) {
@@ -231,7 +231,8 @@ class _AddAppPageState extends State<AddAppPage> {
child: GeneratedForm(
items: [
[
GeneratedFormItem('searchSomeSources',
GeneratedFormTextField(
'searchSomeSources',
label: tr('searchSomeSourcesLabel'),
required: false),
]

View File

@@ -42,7 +42,7 @@ class _AppPageState extends State<AppPage> {
prevApp = app;
getUpdate(app.app.id);
}
var trackOnly = app?.app.additionalSettings['trackOnly'] == 'true';
var trackOnly = app?.app.additionalSettings['trackOnly'] == true;
return Scaffold(
appBar: settingsProvider.showAppWebpage ? AppBar() : null,
backgroundColor: Theme.of(context).colorScheme.surface,
@@ -170,7 +170,7 @@ class _AppPageState extends State<AppPage> {
children: [
TextButton(
onPressed: () {
showDialog<Map<String, String>?>(
showDialog<Map<String, dynamic>?>(
context: context,
builder: (BuildContext ctx) {
return GeneratedFormModal(
@@ -273,7 +273,7 @@ class _AppPageState extends State<AppPage> {
onPressed: app?.downloadProgress != null
? null
: () {
showDialog<Map<String, String>>(
showDialog<Map<String, dynamic>?>(
context: context,
builder: (BuildContext ctx) {
var items = source
@@ -301,7 +301,7 @@ class _AppPageState extends State<AppPage> {
values;
if (source.enforceTrackOnly) {
changedApp.additionalSettings[
'trackOnly'] = 'true';
'trackOnly'] = true;
showError(
tr('appsFromSourceAreTrackOnly'),
context);
@@ -327,7 +327,7 @@ class _AppPageState extends State<AppPage> {
() async {
if (app?.app.additionalSettings[
'trackOnly'] !=
'true') {
true) {
await settingsProvider
.getInstallPermission();
}

View File

@@ -142,16 +142,14 @@ class AppsPageState extends State<AppsPage> {
List<String> trackOnlyUpdateIdsAllOrSelected = [];
existingUpdateIdsAllOrSelected = existingUpdateIdsAllOrSelected.where((id) {
if (appsProvider.apps[id]!.app.additionalSettings['trackOnly'] ==
'true') {
if (appsProvider.apps[id]!.app.additionalSettings['trackOnly'] == true) {
trackOnlyUpdateIdsAllOrSelected.add(id);
return false;
}
return true;
}).toList();
newInstallIdsAllOrSelected = newInstallIdsAllOrSelected.where((id) {
if (appsProvider.apps[id]!.app.additionalSettings['trackOnly'] ==
'true') {
if (appsProvider.apps[id]!.app.additionalSettings['trackOnly'] == true) {
trackOnlyUpdateIdsAllOrSelected.add(id);
return false;
}
@@ -286,7 +284,7 @@ class AppsPageState extends State<AppsPage> {
SizedBox(
width: 100,
child: Text(
'${sortedApps[index].app.installedVersion ?? tr('notInstalled')}${sortedApps[index].app.additionalSettings['trackOnly'] == 'true' ? ' ${tr('estimateInBrackets')}' : ''}',
'${sortedApps[index].app.installedVersion ?? tr('notInstalled')}${sortedApps[index].app.additionalSettings['trackOnly'] == true ? ' ${tr('estimateInBrackets')}' : ''}',
overflow: TextOverflow.fade,
textAlign: TextAlign.end,
)),
@@ -310,7 +308,7 @@ class AppsPageState extends State<AppsPage> {
.areDownloadsRunning()
? Text(tr('pleaseWait'))
: Text(
'${tr('updateAvailable')}${sortedApps[index].app.additionalSettings['trackOnly'] == 'true' ? ' ${tr('estimateInBracketsShort')}' : ''}',
'${tr('updateAvailable')}${sortedApps[index].app.additionalSettings['trackOnly'] == true ? ' ${tr('estimateInBracketsShort')}' : ''}',
style: TextStyle(
fontStyle:
FontStyle.italic,
@@ -366,7 +364,7 @@ class AppsPageState extends State<AppsPage> {
: IconButton(
visualDensity: VisualDensity.compact,
onPressed: () {
showDialog<Map<String, String>?>(
showDialog<Map<String, dynamic>?>(
context: context,
builder: (BuildContext ctx) {
return GeneratedFormModal(
@@ -400,40 +398,33 @@ class AppsPageState extends State<AppsPage> {
HapticFeedback.heavyImpact();
List<GeneratedFormItem> formItems = [];
if (existingUpdateIdsAllOrSelected.isNotEmpty) {
formItems.add(GeneratedFormItem('updates',
formItems.add(GeneratedFormSwitch('updates',
label: tr('updateX', args: [
plural('apps',
existingUpdateIdsAllOrSelected.length)
]),
type: FormItemType.bool,
defaultValue: 'true'));
defaultValue: true));
}
if (newInstallIdsAllOrSelected.isNotEmpty) {
formItems.add(GeneratedFormItem('installs',
formItems.add(GeneratedFormSwitch('installs',
label: tr('installX', args: [
plural('apps',
newInstallIdsAllOrSelected.length)
]),
type: FormItemType.bool,
defaultValue:
existingUpdateIdsAllOrSelected.isNotEmpty
? 'true'
: ''));
defaultValue: existingUpdateIdsAllOrSelected
.isNotEmpty));
}
if (trackOnlyUpdateIdsAllOrSelected.isNotEmpty) {
formItems.add(GeneratedFormItem('trackonlies',
formItems.add(GeneratedFormSwitch('trackonlies',
label: tr('markXTrackOnlyAsUpdated', args: [
plural('apps',
trackOnlyUpdateIdsAllOrSelected.length)
]),
type: FormItemType.bool,
defaultValue: existingUpdateIdsAllOrSelected
.isNotEmpty ||
newInstallIdsAllOrSelected.isNotEmpty
? 'true'
: ''));
.isNotEmpty ||
newInstallIdsAllOrSelected.isNotEmpty));
}
showDialog<Map<String, String>?>(
showDialog<Map<String, dynamic>?>(
context: context,
builder: (BuildContext ctx) {
var totalApps = existingUpdateIdsAllOrSelected
@@ -453,11 +444,11 @@ class AppsPageState extends State<AppsPage> {
[formItems]);
}
bool shouldInstallUpdates =
values['updates'] == 'true';
values['updates'] == true;
bool shouldInstallNew =
values['installs'] == 'true';
values['installs'] == true;
bool shouldMarkTrackOnlies =
values['trackonlies'] == 'true';
values['trackonlies'] == true;
(() async {
if (shouldInstallNew ||
shouldInstallUpdates) {
@@ -699,7 +690,7 @@ class AppsPageState extends State<AppsPage> {
: FontWeight.bold),
),
onPressed: () {
showDialog<Map<String, String>?>(
showDialog<Map<String, dynamic>?>(
context: context,
builder: (BuildContext ctx) {
var vals = filter == null
@@ -709,25 +700,23 @@ class AppsPageState extends State<AppsPage> {
title: tr('filterApps'),
items: [
[
GeneratedFormItem('appName',
GeneratedFormTextField('appName',
label: tr('appName'),
required: false,
defaultValue: vals['appName']),
GeneratedFormItem('author',
GeneratedFormTextField('author',
label: tr('author'),
required: false,
defaultValue: vals['author'])
],
[
GeneratedFormItem('upToDateApps',
GeneratedFormSwitch('upToDateApps',
label: tr('upToDateApps'),
type: FormItemType.bool,
defaultValue: vals['upToDateApps'])
],
[
GeneratedFormItem('nonInstalledApps',
GeneratedFormSwitch('nonInstalledApps',
label: tr('nonInstalledApps'),
type: FormItemType.bool,
defaultValue: vals['nonInstalledApps'])
],
[
@@ -768,21 +757,21 @@ class AppsFilter {
this.includeNonInstalled = true,
this.categoryFilter = ''});
Map<String, String> toValuesMap() {
Map<String, dynamic> toValuesMap() {
return {
'appName': nameFilter,
'author': authorFilter,
'upToDateApps': includeUptodate ? 'true' : '',
'nonInstalledApps': includeNonInstalled ? 'true' : '',
'upToDateApps': includeUptodate,
'nonInstalledApps': includeNonInstalled,
'category': categoryFilter
};
}
AppsFilter.fromValuesMap(Map<String, String> values) {
AppsFilter.fromValuesMap(Map<String, dynamic> values) {
nameFilter = values['appName']!;
authorFilter = values['author']!;
includeUptodate = values['upToDateApps'] == 'true';
includeNonInstalled = values['nonInstalledApps'] == 'true';
includeUptodate = values['upToDateApps'];
includeNonInstalled = values['nonInstalledApps'];
categoryFilter = values['category']!;
}

View File

@@ -138,18 +138,19 @@ class _ImportExportPageState extends State<ImportExportPage> {
onPressed: importInProgress
? null
: () {
showDialog(
showDialog<Map<String, dynamic>?>(
context: context,
builder: (BuildContext ctx) {
return GeneratedFormModal(
title: tr('importFromURLList'),
items: [
[
GeneratedFormItem('appURLList',
GeneratedFormTextField(
'appURLList',
label: tr('appURLList'),
max: 7,
additionalValidators: [
(String? value) {
(dynamic value) {
if (value != null &&
value.isNotEmpty) {
var lines = value
@@ -176,7 +177,8 @@ class _ImportExportPageState extends State<ImportExportPage> {
}).then((values) {
if (values != null) {
var urls =
(values[0] as String).split('\n');
(values['appURLList'] as String)
.split('\n');
setState(() {
importInProgress = true;
});
@@ -224,7 +226,8 @@ class _ImportExportPageState extends State<ImportExportPage> {
: () {
() async {
var values = await showDialog<
List<String>>(
Map<String,
dynamic>?>(
context: context,
builder:
(BuildContext ctx) {
@@ -235,7 +238,7 @@ class _ImportExportPageState extends State<ImportExportPage> {
]),
items: [
[
GeneratedFormItem(
GeneratedFormTextField(
'searchQuery',
label: tr(
'searchQuery'))
@@ -244,13 +247,17 @@ class _ImportExportPageState extends State<ImportExportPage> {
);
});
if (values != null &&
values[0].isNotEmpty) {
(values['searchQuery']
as String?)
?.isNotEmpty ==
true) {
setState(() {
importInProgress = true;
});
var urlsWithDescriptions =
await source
.search(values[0]);
await source.search(
values['searchQuery']
as String);
if (urlsWithDescriptions
.isNotEmpty) {
var selectedUrls =
@@ -345,7 +352,7 @@ class _ImportExportPageState extends State<ImportExportPage> {
.requiredArgs
.map(
(e) => [
GeneratedFormItem(e,
GeneratedFormTextField(e,
label: e)
])
.toList(),

View File

@@ -158,9 +158,10 @@ class _SettingsPageState extends State<SettingsPage> {
var sourceSpecificFields = sourceProvider.sources.map((e) {
if (e.additionalSourceSpecificSettingFormItems.isNotEmpty) {
return GeneratedForm(
items: e.additionalSourceSpecificSettingFormItems
.map((e) => [e])
.toList(),
items: e.additionalSourceSpecificSettingFormItems.map((e) {
e.defaultValue = settingsProvider.getSettingString(e.key);
return [e];
}).toList(),
onValueChanges: (values, valid, isBuilding) {
if (valid) {
values.forEach((key, value) {
@@ -274,7 +275,7 @@ class _SettingsPageState extends State<SettingsPage> {
backgroundColor: Color(e.value),
visualDensity: VisualDensity.compact,
onDeleted: () {
showDialog<Map<String, String>?>(
showDialog<Map<String, dynamic>?>(
context: context,
builder: (BuildContext ctx) {
return GeneratedFormModal(
@@ -311,14 +312,15 @@ class _SettingsPageState extends State<SettingsPage> {
horizontal: 4),
child: IconButton(
onPressed: () {
showDialog<Map<String, String>?>(
showDialog<Map<String, dynamic>?>(
context: context,
builder: (BuildContext ctx) {
return GeneratedFormModal(
title: tr('addCategory'),
items: [
[
GeneratedFormItem('label',
GeneratedFormTextField(
'label',
label: tr('label'))
]
]);