Add `flutter_slidable` and use it for deleting accounts and instances

This commit is contained in:
krawieck 2020-09-22 00:34:45 +02:00
parent 377db0908b
commit 22fa916fbf
3 changed files with 79 additions and 14 deletions

View File

@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import '../hooks/stores.dart';
import '../util/goto.dart';
@ -114,10 +115,36 @@ class AccountsConfigPage extends HookWidget {
),
) ??
false) {
print('delete $instanceUrl');
accountsStore.removeInstance(instanceUrl);
}
}
Future<bool> removeUserDialog(String instanceUrl, String username) async {
if (await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text('Remove user?'),
content: Text(
'Are you sure you want to remove $username@$instanceUrl?'),
actions: [
FlatButton(
child: Text('yes'),
onPressed: () => Navigator.of(context).pop(true),
),
FlatButton(
child: Text('no'),
onPressed: () => Navigator.of(context).pop(false),
)
],
),
) ??
false) {
accountsStore.removeAccount(instanceUrl, username);
return true;
}
return false;
}
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
@ -143,27 +170,57 @@ class AccountsConfigPage extends HookWidget {
children: [
for (final entry in accountsStore.users.entries) ...[
SizedBox(height: 40),
ListTile(
dense: true,
contentPadding: EdgeInsets.only(left: 0, top: 0),
onLongPress: () => deleteInstanceDialog(entry.key),
title: _SectionHeading(entry.key),
Slidable(
actionPane: SlidableBehindActionPane(),
secondaryActions: [
IconSlideAction(
closeOnTap: true,
onTap: () => deleteInstanceDialog(entry.key),
icon: Icons.delete_sweep,
color: Colors.red,
),
],
key: Key(entry.key),
child: Container(
color: theme.canvasColor,
child: ListTile(
dense: true,
contentPadding: EdgeInsets.only(left: 0, top: 0),
title: _SectionHeading(entry.key),
),
),
),
for (final username in entry.value.keys) ...[
ListTile(
trailing:
username == accountsStore.defaultUserFor(entry.key).name
Slidable(
actionPane: SlidableBehindActionPane(),
key: Key('$username@${entry.key}'),
secondaryActions: [
IconSlideAction(
closeOnTap: true,
onTap: () => removeUserDialog(entry.key, username),
icon: Icons.delete_sweep,
color: Colors.red,
),
],
child: Container(
decoration: BoxDecoration(color: theme.canvasColor),
child: ListTile(
trailing: username ==
accountsStore.defaultUserFor(entry.key).name
? Icon(
Icons.check_circle_outline,
color: theme.accentColor,
)
: null,
title: Text(username),
onLongPress: () {
accountsStore.setDefaultAccountFor(entry.key, username);
},
title: Text(username),
onLongPress: () {
accountsStore.setDefaultAccountFor(
entry.key, username);
},
onTap: () {}, // TODO: go to managing account
onTap: () {}, // TODO: go to managing account
),
),
),
],
ListTile(

View File

@ -265,6 +265,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0+2"
flutter_slidable:
dependency: "direct main"
description:
name: flutter_slidable
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.7"
flutter_test:
dependency: "direct dev"
description: flutter

View File

@ -21,6 +21,7 @@ environment:
sdk: '>=2.7.0 <3.0.0'
dependencies:
flutter_slidable: ^0.5.7
photo_view: ^0.10.2
url_launcher: ^5.5.1
markdown: ^2.1.8