You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hi,bro, thanks for such a great extension that saves me a lot of development time.
In the process of using it I found a problem and need your help.
When I use FleatherTheme to set up fleather, I found that it doesn't work as expected, please see the screenshot I uploaded:
It looks a lot like a certain page without Scaffold, I've searched the community and found that other people can use it fine, I'm wondering if it's a difference caused by the flutter version?
This is my full code.
import'dart:convert';
import'dart:io';
import'package:parchment/codecs.dart';
import'package:fleather/fleather.dart';
import'package:flutter/foundation.dart';
import'package:flutter/material.dart';
import'package:flutter/services.dart';
import'package:flutter_localizations/flutter_localizations.dart';
import'package:image_picker/image_picker.dart';
import'package:url_launcher/url_launcher.dart';
voidmain() {
runApp(constFleatherApp());
}
classFleatherAppextendsStatelessWidget {
constFleatherApp({super.key});
@overrideWidgetbuild(BuildContext context) =>MaterialApp(
localizationsDelegates:const [
FleatherLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
supportedLocales:FleatherLocalizations.supportedLocales,
debugShowCheckedModeBanner:false,
theme:ThemeData.light(
useMaterial3:false,
),
darkTheme:ThemeData.dark(
useMaterial3:false,
),
title:'Fleather - rich-text editor for Flutter',
home:constHomePage(),
);
}
classHomePageextendsStatefulWidget {
constHomePage({super.key});
@overrideState<HomePage> createState() =>_HomePageState();
}
class_HomePageStateextendsState<HomePage> {
finalFocusNode _focusNode =FocusNode();
finalGlobalKey<EditorState> _editorKey =GlobalKey();
FleatherController? _controller;
@overridevoidinitState() {
super.initState();
if (kIsWeb) BrowserContextMenu.disableContextMenu();
_initController();
}
@overridevoiddispose() {
super.dispose();
if (kIsWeb) BrowserContextMenu.enableContextMenu();
}
Future<void> _initController() async {
try {
final result =await rootBundle.loadString('assets/welcome.json');
final heuristics =ParchmentHeuristics(
formatRules: [],
insertRules: [
ForceNewlineForInsertsAroundInlineImageRule(),
],
deleteRules: [],
).merge(ParchmentHeuristics.fallback);
final doc =ParchmentDocument.fromJson(
jsonDecode(result),
heuristics: heuristics,
);
// final doc = ParchmentMarkdownCodec().decode(_markdown);
_controller =FleatherController(document: doc);
} catch (err, st) {
if (kDebugMode) {
print('Cannot read welcome.json: $err\n$st');
}
_controller =FleatherController();
}
setState(() {});
}
@overrideWidgetbuild(BuildContext context) {
final fleatherThemeFallback =FleatherThemeData.fallback(context);
returnScaffold(
appBar:AppBar(elevation:0, title:constText('Fleather Demo')),
body: _controller ==null?constCenter(child:CircularProgressIndicator())
:Column(
children: [
FleatherToolbar.basic(
controller: _controller!, editorKey: _editorKey),
Divider(height:1, thickness:1, color:Colors.grey.shade200),
Expanded(
child:FleatherTheme(
data: fleatherThemeFallback,
child:FleatherEditor(
controller: _controller!,
focusNode: _focusNode,
editorKey: _editorKey,
padding:EdgeInsets.only(
left:16,
right:16,
bottom:MediaQuery.of(context).padding.bottom,
),
onLaunchUrl: _launchUrl,
maxContentWidth:800,
embedBuilder: _embedBuilder,
spellCheckConfiguration:SpellCheckConfiguration(
spellCheckService:DefaultSpellCheckService(),
misspelledSelectionColor:Colors.red,
misspelledTextStyle:DefaultTextStyle.of(context).style),
)),
),
],
),
);
}
Widget_embedBuilder(BuildContext context, EmbedNode node) {
if (node.value.type =='icon') {
final data = node.value.data;
// Icons.rocket_launch_outlinedreturnIcon(
IconData(int.parse(data['codePoint']), fontFamily: data['fontFamily']),
color:Color(int.parse(data['color'])),
size:18,
);
}
if (node.value.type =='image') {
final sourceType = node.value.data['source_type'];
ImageProvider? image;
if (sourceType =='assets') {
image =AssetImage(node.value.data['source']);
} elseif (sourceType =='file') {
image =FileImage(File(node.value.data['source']));
} elseif (sourceType =='url') {
image =NetworkImage(node.value.data['source']);
}
if (image !=null) {
returnPadding(
// Caret takes 2 pixels, hence not symmetric padding values.
padding:constEdgeInsets.only(left:4, right:2, top:2, bottom:2),
child:Container(
width:300,
height:300,
decoration:BoxDecoration(
image:DecorationImage(image: image, fit:BoxFit.cover),
),
),
);
}
}
returndefaultFleatherEmbedBuilder(context, node);
}
void_launchUrl(String? url) async {
if (url ==null) return;
final uri =Uri.parse(url);
final canLaunch =awaitcanLaunchUrl(uri);
if (canLaunch) {
awaitlaunchUrl(uri);
}
}
}
/// This is an example insert rule that will insert a new line before and/// after inline image embed.classForceNewlineForInsertsAroundInlineImageRuleextendsInsertRule {
@overrideDelta?apply(Delta document, int index, Object data) {
if (data is!String) returnnull;
final iter =DeltaIterator(document);
final previous = iter.skip(index);
final target = iter.next();
final cursorBeforeInlineEmbed =_isInlineImage(target.data);
final cursorAfterInlineEmbed =
previous !=null&&_isInlineImage(previous.data);
if (cursorBeforeInlineEmbed || cursorAfterInlineEmbed) {
final delta =Delta()..retain(index);
if (cursorAfterInlineEmbed &&!data.startsWith('\n')) {
delta.insert('\n');
}
delta.insert(data);
if (cursorBeforeInlineEmbed &&!data.endsWith('\n')) {
delta.insert('\n');
}
return delta;
}
returnnull;
}
bool_isInlineImage(Object data) {
if (data isEmbeddableObject) {
return data.type =='image'&& data.inline;
}
if (data isMap) {
return data[EmbeddableObject.kTypeKey] =='image'&&
data[EmbeddableObject.kInlineKey];
}
returnfalse;
}
}
Environment
OS [Mac OS 13.6]
Flutter version [3.24.2]
Fleather version [1.9.0]
The text was updated successfully, but these errors were encountered:
Steps to Reproduce
hi,bro, thanks for such a great extension that saves me a lot of development time.
In the process of using it I found a problem and need your help.
When I use FleatherTheme to set up fleather, I found that it doesn't work as expected, please see the screenshot I uploaded:
It looks a lot like a certain page without Scaffold, I've searched the community and found that other people can use it fine, I'm wondering if it's a difference caused by the flutter version?
This is my full code.
Environment
The text was updated successfully, but these errors were encountered: