Migrated to Material You

This commit is contained in:
Imran Remtulla
2022-08-20 16:31:52 -04:00
parent 6b43d4ed60
commit ce98c5b2ec
9 changed files with 267 additions and 157 deletions

View File

@@ -18,78 +18,72 @@ class _AddAppPageState extends State<AddAppPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Obtainium - Add App'),
),
body: Center(
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Spacer(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: TextFormField(
decoration: const InputDecoration(
border: OutlineInputBorder(),
hintText: 'https://github.com/Author/Project',
helperText: 'Enter the App source URL'),
controller: urlInputController,
validator: (value) {
if (value == null ||
value.isEmpty ||
Uri.tryParse(value) == null) {
return 'Please enter a supported source URL';
}
return null;
},
)),
Padding(
padding:
const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
child: ElevatedButton(
onPressed: gettingAppInfo
? null
: () {
if (_formKey.currentState!.validate()) {
return Center(
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Spacer(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: TextFormField(
decoration: const InputDecoration(
hintText: 'https://github.com/Author/Project',
helperText: 'Enter the App source URL'),
controller: urlInputController,
validator: (value) {
if (value == null ||
value.isEmpty ||
Uri.tryParse(value) == null) {
return 'Please enter a supported source URL';
}
return null;
},
)),
Padding(
padding:
const EdgeInsets.symmetric(vertical: 16.0, horizontal: 16.0),
child: ElevatedButton(
onPressed: gettingAppInfo
? null
: () {
if (_formKey.currentState!.validate()) {
setState(() {
gettingAppInfo = true;
});
SourceService()
.getApp(urlInputController.value.text)
.then((app) {
var appsProvider = context.read<AppsProvider>();
if (appsProvider.apps.containsKey(app.id)) {
throw 'App already added';
}
appsProvider.saveApp(app).then((_) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
AppPage(appId: app.id)));
});
}).catchError((e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.toString())),
);
}).whenComplete(() {
setState(() {
gettingAppInfo = true;
gettingAppInfo = false;
});
SourceService()
.getApp(urlInputController.value.text)
.then((app) {
var appsProvider = context.read<AppsProvider>();
if (appsProvider.apps.containsKey(app.id)) {
throw 'App already added';
}
appsProvider.saveApp(app).then((_) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
AppPage(appId: app.id)));
});
}).catchError((e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.toString())),
);
}).whenComplete(() {
setState(() {
gettingAppInfo = false;
});
});
}
},
child: const Text('Add'),
),
});
}
},
child: const Text('Add'),
),
const Spacer(),
if (gettingAppInfo) const LinearProgressIndicator(),
],
),
)),
);
),
const Spacer(),
if (gettingAppInfo) const LinearProgressIndicator(),
],
),
));
}
}