Skip to content

Commit

Permalink
AndroidとiOSではDelayedを使う
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Oct 19, 2023
1 parent bc9e303 commit 61f0fc6
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 68 deletions.
126 changes: 74 additions & 52 deletions lib/view/settings_page/account_settings_page/account_list.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'dart:io';

import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:miria/model/account.dart';
import 'package:miria/providers.dart';
import 'package:miria/router/app_router.dart';
import 'package:miria/view/common/avatar_icon.dart';
Expand Down Expand Up @@ -34,58 +37,19 @@ class AccountListPage extends ConsumerWidget {
itemCount: accounts.length,
itemBuilder: (context, index) {
final account = accounts[index];
return ReorderableDragStartListener(
key: Key("$index"),
index: index,
child: ListTile(
leading: AvatarIcon.fromIResponse(account.i),
title: Text(
account.i.name ?? account.i.username,
style: Theme.of(context).textTheme.titleMedium,
),
subtitle: Text(
account.acct,
style: Theme.of(context).textTheme.bodySmall,
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: const Icon(Icons.delete),
onPressed: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
content: const Text("ほんまに削除してええな?"),
actions: [
OutlinedButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text("やっぱりせえへん"),
),
ElevatedButton(
onPressed: () async {
await ref
.read(
accountRepositoryProvider.notifier,
)
.remove(account);
if (!context.mounted) return;
Navigator.of(context).pop();
},
child: const Text("ええで"),
),
],
),
);
},
),
const Icon(Icons.drag_handle),
],
),
),
);
if (Platform.isAndroid || Platform.isIOS) {
return ReorderableDelayedDragStartListener(
key: Key("$index"),
index: index,
child: AccountListItem(account),
);
} else {
return ReorderableDragStartListener(
key: Key("$index"),
index: index,
child: AccountListItem(account),
);
}
},
onReorder: ref.read(accountRepositoryProvider.notifier).reorder,
),
Expand All @@ -109,3 +73,61 @@ class AccountListPage extends ConsumerWidget {
);
}
}

class AccountListItem extends ConsumerWidget {
const AccountListItem(this.account, {super.key});

final Account account;

@override
Widget build(BuildContext context, WidgetRef ref) {
return ListTile(
leading: AvatarIcon.fromIResponse(account.i),
title: Text(
account.i.name ?? account.i.username,
style: Theme.of(context).textTheme.titleMedium,
),
subtitle: Text(
account.acct.toString(),
style: Theme.of(context).textTheme.bodySmall,
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: const Icon(Icons.delete),
onPressed: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
content: const Text("ほんまに削除してええな?"),
actions: [
OutlinedButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text("やっぱりせえへん"),
),
ElevatedButton(
onPressed: () async {
await ref
.read(
accountRepositoryProvider.notifier,
)
.remove(account);
if (!context.mounted) return;
Navigator.of(context).pop();
},
child: const Text("ええで"),
),
],
),
);
},
),
const Icon(Icons.drag_handle),
],
),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'dart:io';

import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:miria/model/tab_setting.dart';
import 'package:miria/providers.dart';
import 'package:miria/router/app_router.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand Down Expand Up @@ -41,24 +44,25 @@ class TabSettingsListPage extends ConsumerWidget {
itemCount: tabSettings.length,
itemBuilder: (context, index) {
final tabSetting = tabSettings[index];
final account = ref.watch(accountProvider(tabSetting.acct));
return ReorderableDragStartListener(
key: Key("$index"),
index: index,
child: ListTile(
leading: AccountScope(
account: account,
child: TabIconView(icon: tabSetting.icon),
if (Platform.isAndroid || Platform.isIOS) {
return ReorderableDelayedDragStartListener(
key: Key("$index"),
index: index,
child: TabSettingsListItem(
tabSetting: tabSetting,
index: index,
),
title: Text(tabSetting.name),
subtitle: Text(
"${tabSetting.tabType.displayName} / ${account.acct}",
);
} else {
return ReorderableDragStartListener(
key: Key("$index"),
index: index,
child: TabSettingsListItem(
tabSetting: tabSetting,
index: index,
),
trailing: const Icon(Icons.drag_handle),
onTap: () =>
context.pushRoute(TabSettingsRoute(tabIndex: index)),
),
);
);
}
},
onReorder: (oldIndex, newIndex) {
if (oldIndex < newIndex) {
Expand Down Expand Up @@ -89,3 +93,31 @@ class TabSettingsListPage extends ConsumerWidget {
);
}
}

class TabSettingsListItem extends ConsumerWidget {
const TabSettingsListItem({
super.key,
required this.tabSetting,
required this.index,
});

final TabSetting tabSetting;
final int index;

@override
Widget build(BuildContext context, WidgetRef ref) {
final account = ref.watch(accountProvider(tabSetting.acct));
return ListTile(
leading: AccountScope(
account: account,
child: TabIconView(icon: tabSetting.icon),
),
title: Text(tabSetting.name),
subtitle: Text(
"${tabSetting.tabType.displayName} / ${tabSetting.acct}",
),
trailing: const Icon(Icons.drag_handle),
onTap: () => context.pushRoute(TabSettingsRoute(tabIndex: index)),
);
}
}

0 comments on commit 61f0fc6

Please sign in to comment.