Comments (2)
Short answer is: yes.
Note I'd recommend using latest version from master branch for the following.
You'd need to implement your own ZefyrImageDelegate
which looks like this:
abstract class ZefyrImageDelegate<S> {
/// Builds image widget for specified [imageSource] and [context].
Widget buildImage(BuildContext context, String imageSource);
/// Picks an image from specified [source].
///
/// Returns unique string key for the selected image. Returned key is stored
/// in the document.
Future<String> pickImage(S source);
}
There is default implementation which only handles local File
and exists mostly as an example. In your app you'd definitely want roll your own. Here is how default delegate looks like:
class ZefyrDefaultImageDelegate implements ZefyrImageDelegate<ImageSource> {
@override
Widget buildImage(BuildContext context, String imageSource) {
final file = new File.fromUri(Uri.parse(imageSource));
final image = new FileImage(file);
return new Image(image: image);
}
@override
Future<String> pickImage(ImageSource source) async {
final file = await ImagePicker.pickImage(source: source);
if (file == null) return null;
return file.uri.toString();
}
}
As you can see it uses image_picker
plugin. In your own version you are free to use whichever plugin suites your needs.
Now, the main thing to know here is how image information is stored in produced Delta. In short,
- The string returned from
pickImage
gets stored in your document. It is up to you to define how this string looks like. It can be an absolute file path, an HTTP link or some unique key. - When editor needs to render the image it calls
buildImage
of your delegate with the string key you previously returned frompickImage
. Here you simply need to return anImage
widget configured with appropriateImageProvider
. So, if you used HTTP link you can useNetworkImage
.
You can have more complex flows here as well. For instance, in my project I use Firebase Storage to upload images. When user picks a new image I return unique ID of that image generated by Firebase Storage. Then in buildImage
I create a custom Image widget which is responsible for caching images locally and showing simple upload progress indicator for newly added images.
Hope this helps.
from zefyr.
thank you!
from zefyr.
Related Issues (20)
- toolbar missing when click "Normal text" HOT 1
- inner list support required. HOT 3
- Chinese input method with word candidate box the wrong place and typing characters recognized the wrong way. HOT 5
- can ZefyrController provide a reset method, which reset to a new delta and clear old changes?
- Exception when moving caret to end of line using physical keyboard (Cmd+Right)
- How to add image picker
- Text loss with some Android keyboards HOT 5
- showing list after writing "@" HOT 4
- How to add image?
- Error: The getter 'textEditingActionTarget' isn't defined for the class '_ToggleInlineStyleAction'. HOT 1
- Dynamically Scroll to a particular heading in zefyr TextEditor.
- Flutter 2.10 upgrade copy/cut/paste not working
- The word selection always in bottom or some strange place when input chinese
- Feature request: ZefyrEmbedBuilder add ZefyrController parameter HOT 3
- Almost all controls in toolbar gone
- Detection of keypress
- Feature request: Removal of word as a whole
- Try correcting the name to the name of an existing setter, or defining a setter or field named 'textEditingValue'. HOT 5
- Change default text style
- 📣 Announcing Alternative Package
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zefyr.