Skip to content

An open-source cross-platform alternative to AirDrop

feat: make selected files list a sliver

Tien Do Nam37ce7541ca6c
diff --git a/lib/pages/apk_picker_page.dart b/lib/pages/apk_picker_page.dart
index 5483baf7..b5f83162 100644
--- a/lib/pages/apk_picker_page.dart
+++ b/lib/pages/apk_picker_page.dart
@@ -67,6 +67,7 @@ class _ApkPickerPageState extends ConsumerState<ApkPickerPage> {
),
body: ResponsiveListView.single(
padding: const EdgeInsets.symmetric(horizontal: 15),
+ tabletPadding: const EdgeInsets.symmetric(horizontal: 15),
child: CustomScrollView(
slivers: [
const SliverToBoxAdapter(
@@ -102,6 +103,7 @@ class _ApkPickerPageState extends ConsumerState<ApkPickerPage> {
data: (appList) {
return SliverList(
delegate: SliverChildBuilderDelegate(
+ childCount: appList.length,
(context, index) {
final app = appList[index];
final thumbnail = (app as ApplicationWithIcon).icon;
@@ -156,7 +158,6 @@ class _ApkPickerPageState extends ConsumerState<ApkPickerPage> {
),
);
},
- childCount: appList.length,
),
);
},
diff --git a/lib/pages/selected_files_page.dart b/lib/pages/selected_files_page.dart
index a55d7295..80734d6d 100644
--- a/lib/pages/selected_files_page.dart
+++ b/lib/pages/selected_files_page.dart
@@ -1,6 +1,5 @@
import 'dart:convert';
-import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:localsend_app/gen/strings.g.dart';
@@ -24,105 +23,124 @@ class SelectedFilesPage extends ConsumerWidget {
appBar: AppBar(
title: Text(t.sendTab.selection.title),
),
- body: ResponsiveListView(
- padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 15),
- children: [
- Row(
- children: [
- const SizedBox(width: 5),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(t.sendTab.selection.files(files: selectedFiles.length)),
- Text(t.sendTab.selection.size(size: selectedFiles.fold(0, (prev, curr) => prev + curr.size).asReadableFileSize)),
- ],
- ),
- ),
- ElevatedButton(
- onPressed: () {
- ref.read(selectedSendingFilesProvider.notifier).reset();
- context.popUntilRoot();
- },
- child: Text(t.selectedFilesPage.deleteAll),
+ body: ResponsiveListView.single(
+ padding: const EdgeInsets.symmetric(horizontal: 15),
+ tabletPadding: const EdgeInsets.symmetric(horizontal: 15),
+ child: CustomScrollView(
+ slivers: [
+ const SliverToBoxAdapter(
+ child: SizedBox(height: 15),
+ ),
+ SliverToBoxAdapter(
+ child: Row(
+ children: [
+ const SizedBox(width: 5),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(t.sendTab.selection.files(files: selectedFiles.length)),
+ Text(t.sendTab.selection.size(size: selectedFiles.fold(0, (prev, curr) => prev + curr.size).asReadableFileSize)),
+ ],
+ ),
+ ),
+ ElevatedButton(
+ onPressed: () {
+ ref.read(selectedSendingFilesProvider.notifier).reset();
+ context.popUntilRoot();
+ },
+ child: Text(t.selectedFilesPage.deleteAll),
+ ),
+ ],
),
- ],
- ),
- const SizedBox(height: 10),
- ...selectedFiles.mapIndexed(
- (index, file) {
- final String? message;
- if (file.fileType == FileType.text && file.bytes != null) {
- message = utf8.decode(file.bytes!);
- } else {
- message = null;
- }
+ ),
+ const SliverToBoxAdapter(
+ child: SizedBox(height: 10),
+ ),
+ SliverList(
+ delegate: SliverChildBuilderDelegate(
+ childCount: selectedFiles.length,
+ (context, index) {
+ final file = selectedFiles[index];
+
+ final String? message;
+ if (file.fileType == FileType.text && file.bytes != null) {
+ message = utf8.decode(file.bytes!);
+ } else {
+ message = null;
+ }
- return Padding(
- padding: const EdgeInsets.only(bottom: 10),
- child: InkWell(
- splashColor: Colors.transparent,
- splashFactory: NoSplash.splashFactory,
- highlightColor: Colors.transparent,
- hoverColor: Colors.transparent,
- onTap: file.path != null ? () async => openFile(context, file.fileType, file.path!) : null,
- child: Card(
- child: Padding(
- padding: const EdgeInsets.all(10),
- child: Row(
- children: [
- CrossFileThumbnail(file),
- const SizedBox(width: 10),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- message != null ? '"${message.replaceAll('\n', ' ')}"' : file.name,
- maxLines: 1,
- overflow: TextOverflow.fade,
- softWrap: false,
+ return Padding(
+ padding: const EdgeInsets.only(bottom: 10),
+ child: InkWell(
+ splashColor: Colors.transparent,
+ splashFactory: NoSplash.splashFactory,
+ highlightColor: Colors.transparent,
+ hoverColor: Colors.transparent,
+ onTap: file.path != null ? () async => openFile(context, file.fileType, file.path!) : null,
+ child: Card(
+ child: Padding(
+ padding: const EdgeInsets.all(10),
+ child: Row(
+ children: [
+ CrossFileThumbnail(file),
+ const SizedBox(width: 10),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ message != null ? '"${message.replaceAll('\n', ' ')}"' : file.name,
+ maxLines: 1,
+ overflow: TextOverflow.fade,
+ softWrap: false,
+ ),
+ Text(file.size.asReadableFileSize, style: Theme.of(context).textTheme.bodySmall),
+ ],
),
- Text(file.size.asReadableFileSize, style: Theme.of(context).textTheme.bodySmall),
- ],
- ),
- ),
- if (file.fileType == FileType.text && file.bytes != null)
- TextButton(
- style: TextButton.styleFrom(
- foregroundColor: Theme.of(context).colorScheme.onSurface,
),
- onPressed: () async {
- final result = await showDialog<String>(context: context, builder: (_) => MessageInputDialog(initialText: message));
- if (result != null) {
+ if (file.fileType == FileType.text && file.bytes != null)
+ TextButton(
+ style: TextButton.styleFrom(
+ foregroundColor: Theme.of(context).colorScheme.onSurface,
+ ),
+ onPressed: () async {
+ final result =
+ await showDialog<String>(context: context, builder: (_) => MessageInputDialog(initialText: message));
+ if (result != null) {
+ ref.read(selectedSendingFilesProvider.notifier).removeAt(index);
+ ref.read(selectedSendingFilesProvider.notifier).addMessage(result, index: index);
+ }
+ },
+ child: const Icon(Icons.edit),
+ ),
+ TextButton(
+ style: TextButton.styleFrom(
+ foregroundColor: Theme.of(context).colorScheme.onSurface,
+ ),
+ onPressed: () {
+ final currCount = ref.read(selectedSendingFilesProvider).length;
ref.read(selectedSendingFilesProvider.notifier).removeAt(index);
- ref.read(selectedSendingFilesProvider.notifier).addMessage(result, index: index);
- }
- },
- child: const Icon(Icons.edit),
- ),
- TextButton(
- style: TextButton.styleFrom(
- foregroundColor: Theme.of(context).colorScheme.onSurface,
- ),
- onPressed: () {
- final currCount = ref.read(selectedSendingFilesProvider).length;
- ref.read(selectedSendingFilesProvider.notifier).removeAt(index);
- if (currCount == 1) {
- context.popUntilRoot();
- }
- },
- child: const Icon(Icons.delete),
+ if (currCount == 1) {
+ context.popUntilRoot();
+ }
+ },
+ child: const Icon(Icons.delete),
+ ),
+ ],
),
- ],
+ ),
),
),
- ),
- ),
- );
- },
- ),
- ],
+ );
+ },
+ ),
+ ),
+ const SliverToBoxAdapter(
+ child: SizedBox(height: 15),
+ ),
+ ],
+ ),
),
);
}