Skip to content

Commit

Permalink
🖥️ wip: ui for send
Browse files Browse the repository at this point in the history
  • Loading branch information
tom8zds committed Jul 16, 2024
1 parent 311523e commit 77c7a3a
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 0 deletions.
96 changes: 96 additions & 0 deletions lib/view/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:filesize/filesize.dart';
import 'package:flutter/material.dart';

import '../../core/rust/bridge.dart';
Expand Down Expand Up @@ -26,6 +30,9 @@ class _HomePageState extends State<HomePage> {
});
}

List<File> selectedFiles = [];
int selectedFileSize = 0;

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -35,6 +42,95 @@ class _HomePageState extends State<HomePage> {
constraints: const BoxConstraints(maxWidth: 800),
child: Column(
children: [
SizedBox(
height: kToolbarHeight,
child: Row(
children: [
ElevatedButton(
onPressed: () async {
FilePickerResult? result = await FilePicker.platform
.pickFiles(allowMultiple: true);

if (result != null) {
setState(() {
selectedFiles = result.paths
.map((path) => File(path!))
.toList();
selectedFiles.forEach((element) =>
selectedFileSize += element.lengthSync());
});
} else {
// User canceled the picker
}
},
child: Text("Send File")),
SizedBox(
width: 8,
),
ElevatedButton(
onPressed: () async {
String? selectedDirectory =
await FilePicker.platform.getDirectoryPath();

if (selectedDirectory == null) {
// User canceled the picker
}
},
child: Text("Send Folder")),
],
),
),
SizedBox(
height: 120,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'文件: ${selectedFiles.length} 大小: ${filesize(selectedFileSize)}'),
SizedBox(
height: 8,
),
Row(
children: [
for (final (index, file) in selectedFiles.indexed)
Padding(
padding: const EdgeInsets.all(4.0),
child: Container(
decoration: BoxDecoration(
color: Theme.of(context)
.colorScheme
.secondaryContainer,
borderRadius: BorderRadius.circular(12)),
height: 40,
width: 40,
child: Icon(Icons.file_present),
),
)
],
),
SizedBox(
height: 12,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton.icon(
onPressed: () {},
icon: Icon(Icons.info_outline),
label: Text("详情")),
SizedBox(
width: 8,
),
FilledButton.icon(
onPressed: () {},
icon: Icon(Icons.add),
label: Text("添加"),
),
],
),
],
),
),
SizedBox(
height: 8,
),
Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

#include "generated_plugin_registrant.h"

#include <desktop_drop/desktop_drop_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <window_manager/window_manager_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) desktop_drop_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "DesktopDropPlugin");
desktop_drop_plugin_register_with_registrar(desktop_drop_registrar);
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
Expand Down
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
desktop_drop
screen_retriever
window_manager
)
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import FlutterMacOS
import Foundation

import desktop_drop
import device_info_plus
import path_provider_foundation
import screen_retriever
import shared_preferences_foundation
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DesktopDropPlugin.register(with: registry.registrar(forPlugin: "DesktopDropPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.3.6"
desktop_drop:
dependency: "direct main"
description:
name: desktop_drop
sha256: d55a010fe46c8e8fcff4ea4b451a9ff84a162217bdb3b2a0aa1479776205e15d
url: "https://pub.dev"
source: hosted
version: "0.4.4"
device_info_plus:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
uuid: '^4.4.0'
window_manager: '^0.3.9'
simple_icons: ^10.1.3
desktop_drop: ^0.4.4
dev_dependencies:
build_runner: '^2.4.8'
custom_lint: '^0.6.4'
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

#include "generated_plugin_registrant.h"

#include <desktop_drop/desktop_drop_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <window_manager/window_manager_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
DesktopDropPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("DesktopDropPlugin"));
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
WindowManagerPluginRegisterWithRegistrar(
Expand Down
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
desktop_drop
screen_retriever
window_manager
)
Expand Down

0 comments on commit 77c7a3a

Please sign in to comment.