Skip to content

An open-source cross-platform alternative to AirDrop

feat: update scan UI

Tien Do Namf4bef71632d6
diff --git a/assets/CHANGELOG.md b/assets/CHANGELOG.md
index 0ff70c20..503a6f54 100644
--- a/assets/CHANGELOG.md
+++ b/assets/CHANGELOG.md
@@ -1,8 +1,9 @@
## 1.8.0 (2023-)
+- feat: add troubleshoot page
+- feat: cleanup scan UI by hiding multiple network interfaces inside the scan button
- feat(android): share apk
- feat(android): Android TV support
-- feat: add troubleshoot page
- feat(windows): left click on tray icon opens app
- feat(linux): add Control+Q shortcut to exit app
- fix: also scan multicast when pressing on a subnet sync button
diff --git a/lib/pages/tabs/send_tab.dart b/lib/pages/tabs/send_tab.dart
index db4f2769..b9d08ad3 100644
--- a/lib/pages/tabs/send_tab.dart
+++ b/lib/pages/tabs/send_tab.dart
@@ -23,7 +23,7 @@ import 'package:localsend_app/widget/file_thumbnail.dart';
import 'package:localsend_app/widget/list_tile/device_list_tile.dart';
import 'package:localsend_app/widget/responsive_builder.dart';
import 'package:localsend_app/widget/responsive_list_view.dart';
-import 'package:localsend_app/widget/rotating_widget.dart';
+import 'package:localsend_app/widget/scan_button.dart';
import 'package:routerino/routerino.dart';
const _horizontalPadding = 15.0;
@@ -176,19 +176,13 @@ class _SendTabState extends ConsumerState<SendTab> {
),
),
const SizedBox(width: 10),
- if (networkInfo.localIps.length == 1)
- Tooltip(
- message: t.sendTab.scan,
- child: RotatingWidget(
- duration: const Duration(seconds: 2),
- spinning: nearbyDevicesState.runningIps.isNotEmpty,
- reverse: true,
- child: CustomIconButton(
- onPressed: () => ref.read(scanProvider).startLegacySubnetScan(networkInfo.localIps.first),
- child: const Icon(Icons.sync),
- ),
- ),
+ Tooltip(
+ message: t.sendTab.scan,
+ child: ScanButton(
+ ips: networkInfo.localIps,
+ onSelect: (ip) => ref.read(scanProvider).startLegacySubnetScan(ip),
),
+ ),
Tooltip(
message: t.dialogs.addressInput.title,
child: CustomIconButton(
@@ -214,38 +208,6 @@ class _SendTabState extends ConsumerState<SendTab> {
),
],
),
- if (networkInfo.localIps.length > 1)
- Padding(
- padding: const EdgeInsets.only(bottom: 15, left: _horizontalPadding, right: _horizontalPadding),
- child: Wrap(
- spacing: 15,
- runSpacing: 15,
- children: networkInfo.localIps.map((ip) {
- return Card(
- margin: EdgeInsets.zero,
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Tooltip(
- message: t.sendTab.scan,
- child: RotatingWidget(
- duration: const Duration(seconds: 2),
- spinning: nearbyDevicesState.runningIps.contains(ip),
- reverse: true,
- child: CustomIconButton(
- onPressed: () => ref.read(scanProvider).startLegacySubnetScan(ip),
- child: const Icon(Icons.sync),
- ),
- ),
- ),
- Text(ip),
- const SizedBox(width: 8),
- ],
- ),
- );
- }).toList(),
- ),
- ),
Padding(
padding: const EdgeInsets.symmetric(horizontal: _horizontalPadding),
child: Hero(
diff --git a/lib/widget/scan_button.dart b/lib/widget/scan_button.dart
new file mode 100644
index 00000000..36798abe
--- /dev/null
+++ b/lib/widget/scan_button.dart
@@ -0,0 +1,86 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_riverpod/flutter_riverpod.dart';
+import 'package:localsend_app/provider/network/nearby_devices_provider.dart';
+import 'package:localsend_app/widget/custom_icon_button.dart';
+import 'package:localsend_app/widget/rotating_widget.dart';
+
+class ScanButton extends ConsumerWidget {
+ final List<String> ips;
+ final void Function(String ip) onSelect;
+
+ const ScanButton({
+ required this.ips,
+ required this.onSelect,
+ });
+
+ @override
+ Widget build(BuildContext context, WidgetRef ref) {
+ final scanningIps = ref.watch(nearbyDevicesProvider.select((s) => s.runningIps));
+
+ if (ips.length <= 1) {
+ return RotatingWidget(
+ duration: const Duration(seconds: 2),
+ spinning: scanningIps.isNotEmpty,
+ reverse: true,
+ child: CustomIconButton(
+ onPressed: () => onSelect(ips.first),
+ child: const Icon(Icons.sync),
+ ),
+ );
+ }
+
+ return ClipRRect(
+ borderRadius: BorderRadius.circular(9999),
+ child: Material(
+ type: MaterialType.transparency,
+ child: PopupMenuButton(
+ offset: const Offset(60, 40),
+ onSelected: (ip) => onSelect(ip),
+ itemBuilder: (_) {
+ return [
+ ...ips.map(
+ (ip) => PopupMenuItem(
+ value: ip,
+ child: Row(
+ children: [
+ _RotatingSyncIcon(ip),
+ const SizedBox(width: 10),
+ Text(ip),
+ ],
+ ),
+ ),
+ ),
+ ];
+ },
+ child: RotatingWidget(
+ duration: const Duration(seconds: 2),
+ spinning: scanningIps.isNotEmpty,
+ reverse: true,
+ child: const Padding(
+ padding: EdgeInsets.all(8),
+ child: Icon(Icons.sync),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+/// A separate widget, so it gets the latest data from provider.
+class _RotatingSyncIcon extends ConsumerWidget {
+ final String ip;
+
+ const _RotatingSyncIcon(this.ip);
+
+ @override
+ Widget build(BuildContext context, WidgetRef ref) {
+ final scanningIps = ref.watch(nearbyDevicesProvider.select((s) => s.runningIps));
+ return RotatingWidget(
+ duration: const Duration(seconds: 2),
+ spinning: scanningIps.contains(ip),
+ reverse: true,
+ child: const Icon(Icons.sync),
+ );
+ }
+}