you can now add accounts/instances
This commit is contained in:
parent
1dee2e21f5
commit
c08e07311a
|
@ -84,7 +84,6 @@ class _AccountsConfig extends HookWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var theme = Theme.of(context);
|
||||
var textFieldController = useTextEditingController();
|
||||
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
|
@ -96,44 +95,12 @@ class _AccountsConfig extends HookWidget {
|
|||
centerTitle: true,
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () async {
|
||||
await showDialog(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text('Add instance'),
|
||||
content: TextField(
|
||||
controller: textFieldController,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: 'Instance url',
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: Text('Add'),
|
||||
onPressed: () async {
|
||||
try {
|
||||
await context
|
||||
.read<AccountsStore>()
|
||||
.addInstance(textFieldController.text);
|
||||
} on Exception catch (err) {
|
||||
_scaffoldKey.currentState.showSnackBar(SnackBar(
|
||||
content: Text(err.toString()),
|
||||
));
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
FlatButton(
|
||||
child: Text('Cancel'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
builder: (_) =>
|
||||
_AccountsConfigAddInstanceDialog(scaffoldKey: _scaffoldKey),
|
||||
);
|
||||
textFieldController.clear();
|
||||
},
|
||||
child: Icon(Icons.add),
|
||||
),
|
||||
|
@ -163,6 +130,19 @@ class _AccountsConfig extends HookWidget {
|
|||
onTap: () {}, // TODO: go to managing account
|
||||
),
|
||||
],
|
||||
ListTile(
|
||||
leading: Icon(Icons.add),
|
||||
title: Text('Add account'),
|
||||
onTap: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => _AccountsConfigAddAccountDialog(
|
||||
scaffoldKey: _scaffoldKey,
|
||||
instanceUrl: entry.key,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
Divider(),
|
||||
]
|
||||
]..removeLast(), // removes trailing Divider
|
||||
|
@ -173,6 +153,137 @@ class _AccountsConfig extends HookWidget {
|
|||
}
|
||||
}
|
||||
|
||||
class _AccountsConfigAddInstanceDialog extends HookWidget {
|
||||
final GlobalKey<ScaffoldState> scaffoldKey;
|
||||
|
||||
const _AccountsConfigAddInstanceDialog({@required this.scaffoldKey})
|
||||
: assert(scaffoldKey != null);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var instanceController = useTextEditingController();
|
||||
useValueListenable(instanceController);
|
||||
|
||||
var loading = useState(false);
|
||||
|
||||
return AlertDialog(
|
||||
title: Text('Add instance'),
|
||||
content: TextField(
|
||||
autofocus: true,
|
||||
controller: instanceController,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: 'Instance url',
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: !loading.value ? Text('Add') : CircularProgressIndicator(),
|
||||
onPressed: instanceController.text.isEmpty
|
||||
? null
|
||||
: () async {
|
||||
try {
|
||||
loading.value = true;
|
||||
await context
|
||||
.read<AccountsStore>()
|
||||
.addInstance(instanceController.text);
|
||||
scaffoldKey.currentState.hideCurrentSnackBar();
|
||||
} on Exception catch (err) {
|
||||
scaffoldKey.currentState.showSnackBar(SnackBar(
|
||||
content: Text(err.toString()),
|
||||
));
|
||||
}
|
||||
loading.value = false;
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
FlatButton(
|
||||
child: Text('Cancel'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AccountsConfigAddAccountDialog extends HookWidget {
|
||||
final GlobalKey<ScaffoldState> scaffoldKey;
|
||||
final String instanceUrl;
|
||||
|
||||
const _AccountsConfigAddAccountDialog(
|
||||
{@required this.scaffoldKey, @required this.instanceUrl})
|
||||
: assert(scaffoldKey != null),
|
||||
assert(instanceUrl != null);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var usernameController = useTextEditingController();
|
||||
var passwordController = useTextEditingController();
|
||||
useValueListenable(usernameController);
|
||||
useValueListenable(passwordController);
|
||||
|
||||
var loading = useState(false);
|
||||
|
||||
return AlertDialog(
|
||||
title: Text('Add account'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
autofocus: true,
|
||||
controller: usernameController,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: 'Username or email',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
TextField(
|
||||
controller: passwordController,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: 'Password',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: !loading.value ? Text('Add') : CircularProgressIndicator(),
|
||||
onPressed:
|
||||
usernameController.text.isEmpty || passwordController.text.isEmpty
|
||||
? null
|
||||
: () async {
|
||||
try {
|
||||
loading.value = true;
|
||||
await context.read<AccountsStore>().addAccount(
|
||||
instanceUrl,
|
||||
usernameController.text,
|
||||
passwordController.text,
|
||||
);
|
||||
} on Exception catch (err) {
|
||||
scaffoldKey.currentState.showSnackBar(SnackBar(
|
||||
content: Text(err.toString()),
|
||||
));
|
||||
}
|
||||
loading.value = false;
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
FlatButton(
|
||||
child: Text('Cancel'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SectionHeading extends StatelessWidget {
|
||||
final String text;
|
||||
|
||||
|
|
Loading…
Reference in New Issue