fix: swipe to remove account

This commit is contained in:
Rongjian Zhang 2022-10-07 16:34:55 +08:00
parent fddf67d518
commit b65ce98077
2 changed files with 20 additions and 20 deletions

View File

@ -10,7 +10,6 @@ import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/action_button.dart'; import 'package:git_touch/widgets/action_button.dart';
import 'package:git_touch/widgets/app_bar_title.dart'; import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/avatar.dart'; import 'package:git_touch/widgets/avatar.dart';
import 'package:git_touch/widgets/link.dart';
import 'package:git_touch/widgets/loading.dart'; import 'package:git_touch/widgets/loading.dart';
import 'package:git_touch/widgets/text_field.dart'; import 'package:git_touch/widgets/text_field.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -29,20 +28,27 @@ class _LoginScreenState extends State<LoginScreen> {
final _passwordController = TextEditingController(); final _passwordController = TextEditingController();
Widget _buildAccountItem(int index) { Widget _buildAccountItem(int index) {
final theme = Provider.of<ThemeModel>(context);
final auth = Provider.of<AuthModel>(context); final auth = Provider.of<AuthModel>(context);
final account = auth.accounts![index]; final account = auth.accounts![index];
return LinkWidget( return Dismissible(
onLongPress: () { key: ValueKey(index),
theme.showActions(context, [ direction: DismissDirection.endToStart,
ActionItem( background: Container(
text: AppLocalizations.of(context)!.removeAccount, color: AntTheme.of(context).colorDanger,
danger: true, padding: const EdgeInsets.only(right: 12),
onTap: (_) { child: Align(
auth.removeAccount(index); alignment: Alignment.centerRight,
}, child: Text(
AppLocalizations.of(context)!.removeAccount,
style: TextStyle(
fontSize: 16,
color: AntTheme.of(context).colorBackground,
),
), ),
]); ),
),
onDismissed: (_) {
auth.removeAccount(index);
}, },
child: AntListItem( child: AntListItem(
onClick: () { onClick: () {
@ -354,7 +360,7 @@ class _LoginScreenState extends State<LoginScreen> {
Container( Container(
padding: CommonStyle.padding, padding: CommonStyle.padding,
child: Text( child: Text(
AppLocalizations.of(context)!.longPressToRemoveAccount, 'Swipe to left to remove account',
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
color: AntTheme.of(context).colorTextSecondary, color: AntTheme.of(context).colorTextSecondary,

View File

@ -6,16 +6,14 @@ class LinkWidget extends StatelessWidget {
required this.child, required this.child,
this.url, this.url,
this.onTap, this.onTap,
this.onLongPress,
}); });
final Widget child; final Widget child;
final String? url; final String? url;
final Function? onTap; final Function? onTap;
final Function? onLongPress;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget w = CupertinoButton( final Widget w = CupertinoButton(
minSize: 0, minSize: 0,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
onPressed: () async { onPressed: () async {
@ -24,10 +22,6 @@ class LinkWidget extends StatelessWidget {
}, },
child: child, child: child,
); );
if (onLongPress != null) {
w = GestureDetector(
onLongPress: onLongPress as void Function()?, child: w);
}
return w; return w;
} }
} }