mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-07-22 17:19:42 +02:00
Removed redundant code
This commit is contained in:
@@ -4,8 +4,9 @@ import 'package:flutter/services.dart';
|
|||||||
class GeneratedFormItem {
|
class GeneratedFormItem {
|
||||||
late String message;
|
late String message;
|
||||||
late bool required;
|
late bool required;
|
||||||
|
late int lines;
|
||||||
|
|
||||||
GeneratedFormItem(this.message, this.required);
|
GeneratedFormItem(this.message, this.required, this.lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
class GeneratedFormModal extends StatefulWidget {
|
class GeneratedFormModal extends StatefulWidget {
|
||||||
@@ -33,6 +34,8 @@ class _GeneratedFormModalState extends State<GeneratedFormModal> {
|
|||||||
TextFormField(
|
TextFormField(
|
||||||
decoration: InputDecoration(helperText: e.message),
|
decoration: InputDecoration(helperText: e.message),
|
||||||
controller: controller,
|
controller: controller,
|
||||||
|
minLines: e.lines <= 1 ? null : e.lines,
|
||||||
|
maxLines: e.lines <= 1 ? 1 : e.lines,
|
||||||
validator: e.required
|
validator: e.required
|
||||||
? (value) {
|
? (value) {
|
||||||
if (value == null || value.isEmpty) {
|
if (value == null || value.isEmpty) {
|
||||||
|
@@ -73,74 +73,30 @@ class _ImportExportPageState extends State<ImportExportPage> {
|
|||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext ctx) {
|
builder: (BuildContext ctx) {
|
||||||
final formKey = GlobalKey<FormState>();
|
return GeneratedFormModal(
|
||||||
final jsonInputController = TextEditingController();
|
title: 'Obtainium Import',
|
||||||
|
items: [
|
||||||
return AlertDialog(
|
GeneratedFormItem(
|
||||||
scrollable: true,
|
'Obtainium Export JSON Data', true, 7)
|
||||||
title: const Text('Import App List'),
|
]);
|
||||||
content: Column(children: [
|
}).then((values) {
|
||||||
const Text(
|
if (values != null) {
|
||||||
'Copy the contents of the Obtainium export file and paste them into the field below:'),
|
|
||||||
Form(
|
|
||||||
key: formKey,
|
|
||||||
child: TextFormField(
|
|
||||||
minLines: 7,
|
|
||||||
maxLines: 7,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
helperText: 'Obtainium export data'),
|
|
||||||
controller: jsonInputController,
|
|
||||||
validator: (value) {
|
|
||||||
if (value == null || value.isEmpty) {
|
|
||||||
return 'Please enter your Obtainium export data';
|
|
||||||
}
|
|
||||||
bool isJSON = true;
|
|
||||||
try {
|
try {
|
||||||
jsonDecode(value);
|
jsonDecode(values[0]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
isJSON = false;
|
throw 'Invalid input';
|
||||||
}
|
}
|
||||||
if (!isJSON) {
|
appsProvider.importApps(values[0]).then((value) {
|
||||||
return 'Invalid input';
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
]),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
HapticFeedback.lightImpact();
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
child: const Text('Cancel')),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
HapticFeedback.heavyImpact();
|
|
||||||
if (formKey.currentState!.validate()) {
|
|
||||||
appsProvider
|
|
||||||
.importApps(
|
|
||||||
jsonInputController.value.text)
|
|
||||||
.then((value) {
|
|
||||||
ScaffoldMessenger.of(context)
|
|
||||||
.showSnackBar(
|
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
'$value App${value == 1 ? '' : 's'} Imported')),
|
'$value App${value == 1 ? '' : 's'} Imported')),
|
||||||
);
|
);
|
||||||
}).catchError((e) {
|
|
||||||
ScaffoldMessenger.of(context)
|
|
||||||
.showSnackBar(
|
|
||||||
SnackBar(content: Text(e.toString())),
|
|
||||||
);
|
|
||||||
}).whenComplete(() {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
}).catchError((e) {
|
||||||
child: const Text('Import')),
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
],
|
SnackBar(content: Text(e.toString())),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -157,7 +113,7 @@ class _ImportExportPageState extends State<ImportExportPage> {
|
|||||||
return GeneratedFormModal(
|
return GeneratedFormModal(
|
||||||
title: 'Import ${source.name}',
|
title: 'Import ${source.name}',
|
||||||
items: source.requiredArgs
|
items: source.requiredArgs
|
||||||
.map((e) => GeneratedFormItem(e, true))
|
.map((e) => GeneratedFormItem(e, true, 1))
|
||||||
.toList());
|
.toList());
|
||||||
}).then((values) {
|
}).then((values) {
|
||||||
if (values != null) {
|
if (values != null) {
|
||||||
|
Reference in New Issue
Block a user