11import 'dart:io' ;
22
33import 'package:appflowy/generated/locale_keys.g.dart' ;
4+ import 'package:appflowy/plugins/document/presentation/editor_drop_manager.dart' ;
45import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart' ;
56import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_util.dart' ;
67import 'package:appflowy/shared/appflowy_network_image.dart' ;
@@ -17,8 +18,7 @@ import 'package:desktop_drop/desktop_drop.dart';
1718import 'package:dotted_border/dotted_border.dart' ;
1819import 'package:easy_localization/easy_localization.dart' ;
1920import 'package:flowy_infra/file_picker/file_picker_service.dart' ;
20- import 'package:flowy_infra_ui/style_widget/primary_rounded_button.dart' ;
21- import 'package:flowy_infra_ui/style_widget/text.dart' ;
21+ import 'package:flowy_infra_ui/flowy_infra_ui.dart' ;
2222import 'package:flowy_svg/flowy_svg.dart' ;
2323import 'package:flutter/material.dart' ;
2424import 'package:flutter/services.dart' ;
@@ -50,6 +50,8 @@ class _IconUploaderState extends State<IconUploader> {
5050
5151 final List <_Image > pickedImages = [];
5252 final FocusNode focusNode = FocusNode ();
53+ final topEditorDropManagerState = getIt.get <EditorDropManagerState >();
54+ final iconUploaderType = 'iconUploaderType' ;
5355
5456 @override
5557 void initState () {
@@ -63,11 +65,17 @@ class _IconUploaderState extends State<IconUploader> {
6365 focusNode.requestFocus ();
6466 });
6567 }
68+ WidgetsBinding .instance.addPostFrameCallback ((_) {
69+ topEditorDropManagerState.add (iconUploaderType);
70+ });
6671 }
6772
6873 @override
6974 void dispose () {
7075 super .dispose ();
76+ WidgetsBinding .instance.addPostFrameCallback ((_) {
77+ topEditorDropManagerState.remove (iconUploaderType);
78+ });
7179 focusNode.dispose ();
7280 }
7381
@@ -97,27 +105,27 @@ class _IconUploaderState extends State<IconUploader> {
97105 children: [
98106 Expanded (
99107 child: DropTarget (
100- /// there is an issue with multiple DropTargets
101- /// see https://github.com/MixinNetwork/flutter-plugins/issues/2
102- enable: false ,
103108 onDragEntered: (_) => setState (() => isHovering = true ),
104109 onDragExited: (_) => setState (() => isHovering = false ),
105110 onDragDone: (details) => loadImage (details.files),
106111 child: MouseRegion (
107112 cursor: SystemMouseCursors .click,
108113 child: GestureDetector (
109114 behavior: HitTestBehavior .opaque,
110- onTap: () => pickImage () ,
115+ onTap: pickImage,
111116 child: DottedBorder (
112117 dashPattern: const [3 , 3 ],
113118 radius: const Radius .circular (8 ),
114119 borderType: BorderType .RRect ,
115120 color: isHovering
116121 ? Theme .of (context).colorScheme.primary
117122 : Theme .of (context).hintColor,
118- child: Center (
123+ child: Container (
124+ alignment: Alignment .center,
119125 child: pickedImages.isEmpty
120- ? dragHint ()
126+ ? (isHovering
127+ ? hoveringWidget ()
128+ : dragHint (context))
121129 : previewImage (),
122130 ),
123131 ),
@@ -127,12 +135,21 @@ class _IconUploaderState extends State<IconUploader> {
127135 ),
128136 Padding (
129137 padding: const EdgeInsets .only (top: 16 ),
130- child: Align (
131- alignment: Alignment .centerRight,
132- child: _ConfirmButton (
133- onTap: uploadImage,
134- enable: pickedImages.isNotEmpty,
135- ),
138+ child: Row (
139+ children: [
140+ Spacer (),
141+ if (pickedImages.isNotEmpty)
142+ Padding (
143+ padding: EdgeInsets .only (right: 8 ),
144+ child: _ChangeIconButton (
145+ onTap: pickImage,
146+ ),
147+ ),
148+ _ConfirmButton (
149+ onTap: uploadImage,
150+ enable: pickedImages.isNotEmpty,
151+ ),
152+ ],
136153 ),
137154 ),
138155 ],
@@ -143,12 +160,49 @@ class _IconUploaderState extends State<IconUploader> {
143160 );
144161 }
145162
146- Widget dragHint () => FlowyText (
147- LocaleKeys .document_imageBlock_upload_placeholder.tr (),
148- fontSize: 14 ,
149- fontWeight: FontWeight .w500,
150- color: Theme .of (context).hintColor,
151- );
163+ Widget hoveringWidget () {
164+ return Container (
165+ color: Color (0xffE0F8FF ),
166+ child: Center (
167+ child: FlowyText (
168+ LocaleKeys .emojiIconPicker_iconUploader_dropToUpload.tr (),
169+ ),
170+ ),
171+ );
172+ }
173+
174+ Widget dragHint (BuildContext context) {
175+ final style = TextStyle (
176+ fontSize: 14 ,
177+ color: Color (0xff666D76 ),
178+ fontWeight: FontWeight .w500,
179+ );
180+ return Padding (
181+ padding: EdgeInsets .symmetric (horizontal: 32 ),
182+ child: RichText (
183+ textAlign: TextAlign .center,
184+ text: TextSpan (
185+ children: [
186+ TextSpan (
187+ text:
188+ LocaleKeys .emojiIconPicker_iconUploader_placeholderLeft.tr (),
189+ ),
190+ TextSpan (
191+ text: LocaleKeys .emojiIconPicker_iconUploader_placeholderUpload
192+ .tr (),
193+ style: style.copyWith (color: Color (0xff00BCF0 )),
194+ ),
195+ TextSpan (
196+ text:
197+ LocaleKeys .emojiIconPicker_iconUploader_placeholderRight.tr (),
198+ mouseCursor: SystemMouseCursors .click,
199+ ),
200+ ],
201+ style: style,
202+ ),
203+ ),
204+ );
205+ }
152206
153207 Widget previewImage () {
154208 final image = pickedImages.first;
@@ -285,6 +339,41 @@ class _IconUploaderState extends State<IconUploader> {
285339 }
286340}
287341
342+ class _ChangeIconButton extends StatelessWidget {
343+ const _ChangeIconButton ({required this .onTap});
344+
345+ final VoidCallback onTap;
346+
347+ @override
348+ Widget build (BuildContext context) {
349+ final isDark = Theme .of (context).brightness == Brightness .dark;
350+ return SizedBox (
351+ height: 32 ,
352+ width: 84 ,
353+ child: FlowyButton (
354+ text: FlowyText (
355+ LocaleKeys .emojiIconPicker_iconUploader_change.tr (),
356+ fontSize: 14.0 ,
357+ fontWeight: FontWeight .w500,
358+ figmaLineHeight: 20.0 ,
359+ color: isDark ? Colors .white : Color (0xff1F2329 ),
360+ textAlign: TextAlign .center,
361+ overflow: TextOverflow .ellipsis,
362+ ),
363+ margin: const EdgeInsets .symmetric (horizontal: 14.0 ),
364+ backgroundColor: Theme .of (context).colorScheme.surface,
365+ hoverColor:
366+ (isDark ? Colors .white : Color (0xffD1D8E0 )).withValues (alpha: 0.9 ),
367+ decoration: BoxDecoration (
368+ border: Border .all (color: isDark ? Colors .white : Color (0xffD1D8E0 )),
369+ borderRadius: BorderRadius .circular (10 ),
370+ ),
371+ onTap: onTap,
372+ ),
373+ );
374+ }
375+ }
376+
288377class _ConfirmButton extends StatelessWidget {
289378 const _ConfirmButton ({required this .onTap, this .enable = true });
290379
@@ -299,6 +388,7 @@ class _ConfirmButton extends StatelessWidget {
299388 opacity: enable ? 1.0 : 0.5 ,
300389 child: PrimaryRoundedButton (
301390 text: LocaleKeys .button_confirm.tr (),
391+ figmaLineHeight: 20.0 ,
302392 onTap: enable ? onTap : null ,
303393 ),
304394 ),
0 commit comments