tempaltes
This commit is contained in:
parent
2fb77ea7e8
commit
5c3cb6c87a
@ -12,6 +12,7 @@ import 'package:flutter_localizations/flutter_localizations.dart';
|
|||||||
import 'package:flutter_quill/flutter_quill_internal.dart';
|
import 'package:flutter_quill/flutter_quill_internal.dart';
|
||||||
import 'package:flutter_quill/quill_delta.dart';
|
import 'package:flutter_quill/quill_delta.dart';
|
||||||
import 'package:flutter_quill_extensions/flutter_quill_extensions.dart';
|
import 'package:flutter_quill_extensions/flutter_quill_extensions.dart';
|
||||||
|
import 'package:frontend/Screens/myTemplates/quill_delta_sample.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:responsive_builder/responsive_builder.dart';
|
import 'package:responsive_builder/responsive_builder.dart';
|
||||||
@ -22,11 +23,6 @@ import '../../services/apiService.dart';
|
|||||||
import '../../utils/auth_utils.dart';
|
import '../../utils/auth_utils.dart';
|
||||||
import '../../widgets/custom_user_travel.dart';
|
import '../../widgets/custom_user_travel.dart';
|
||||||
|
|
||||||
/// Custom Embed Definition
|
|
||||||
class TimeStampEmbed {
|
|
||||||
static const String type = 'timeStamp';
|
|
||||||
}
|
|
||||||
|
|
||||||
class Template extends StatefulWidget {
|
class Template extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
TemplateState createState() => TemplateState();
|
TemplateState createState() => TemplateState();
|
||||||
@ -35,23 +31,27 @@ class Template extends StatefulWidget {
|
|||||||
class TemplateState extends State<Template> {
|
class TemplateState extends State<Template> {
|
||||||
final ApiService apiService = ApiService();
|
final ApiService apiService = ApiService();
|
||||||
|
|
||||||
|
final FocusNode _editorFocusNode = FocusNode();
|
||||||
|
final ScrollController _editorScrollController = ScrollController();
|
||||||
|
final QuillController _controller = QuillController.basic();
|
||||||
Color layoutColor = Colors.redAccent;
|
Color layoutColor = Colors.redAccent;
|
||||||
Color bodyColor = Colors.white;
|
Color bodyColor = Colors.white;
|
||||||
|
|
||||||
QuillController _controller = QuillController.basic();
|
|
||||||
final FocusNode _focusNode = FocusNode();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_controller = QuillController.basic(); // starts with empty document
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
_editorFocusNode.requestFocus(); // ✅ Ensure focus is requested
|
||||||
|
});
|
||||||
|
// _controller.document = Document.fromJson(kQuillDefaultSample);
|
||||||
loadInitialData();
|
loadInitialData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_focusNode.dispose();
|
|
||||||
_controller.dispose();
|
_controller.dispose();
|
||||||
|
_editorScrollController.dispose();
|
||||||
|
_editorFocusNode.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,30 +185,130 @@ class TemplateState extends State<Template> {
|
|||||||
controller: _controller,
|
controller: _controller,
|
||||||
config: QuillSimpleToolbarConfig(
|
config: QuillSimpleToolbarConfig(
|
||||||
embedButtons: FlutterQuillEmbeds.toolbarButtons(),
|
embedButtons: FlutterQuillEmbeds.toolbarButtons(),
|
||||||
|
showClipboardPaste: true,
|
||||||
|
customButtons: [
|
||||||
|
QuillToolbarCustomButtonOptions(
|
||||||
|
icon: const Icon(Icons.add_alarm_rounded),
|
||||||
|
onPressed: () {
|
||||||
|
_controller.document.insert(
|
||||||
|
_controller.selection.extentOffset,
|
||||||
|
TimeStampEmbed(
|
||||||
|
DateTime.now().toString(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
_controller.updateSelection(
|
||||||
|
TextSelection.collapsed(
|
||||||
|
offset: _controller.selection.extentOffset + 1,
|
||||||
|
),
|
||||||
|
ChangeSource.local,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
buttonOptions: QuillSimpleToolbarButtonOptions(
|
||||||
|
base: QuillToolbarBaseButtonOptions(
|
||||||
|
afterButtonPressed: () {
|
||||||
|
final isDesktop = {
|
||||||
|
TargetPlatform.linux,
|
||||||
|
TargetPlatform.windows,
|
||||||
|
TargetPlatform.macOS
|
||||||
|
}.contains(defaultTargetPlatform);
|
||||||
|
if (isDesktop) {
|
||||||
|
_editorFocusNode.requestFocus();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
linkStyle: QuillToolbarLinkStyleButtonOptions(
|
||||||
|
validateLink: (link) {
|
||||||
|
// Treats all links as valid. When launching the URL,
|
||||||
|
// `https://` is prefixed if the link is incomplete (e.g., `google.com` → `https://google.com`)
|
||||||
|
// however this happens only within the editor.
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
|
|
||||||
// ✅ Modern editor
|
// ✅ Modern editor
|
||||||
// Container(
|
Container(
|
||||||
// height: 300,
|
height: 300,
|
||||||
// decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
// border: Border.all(color: Colors.grey),
|
border: Border.all(color: Colors.grey),
|
||||||
// borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
// ),
|
),
|
||||||
// child: QuillEditor(
|
child: QuillEditor.basic(
|
||||||
// focusNode: _focusNode,
|
focusNode: _editorFocusNode,
|
||||||
// scrollController: ScrollController(),
|
scrollController: _editorScrollController,
|
||||||
// controller: _controller,
|
controller: _controller,
|
||||||
// config: QuillEditorConfig(
|
config: QuillEditorConfig(
|
||||||
// padding: const EdgeInsets.all(8),
|
requestKeyboardFocusOnCheckListChanged: false,
|
||||||
// embedBuilders: FlutterQuillEmbeds.editorBuilders(),
|
// readOnlyMouseCursor: SystemMouseCursors.text,
|
||||||
// sharedConfigurations: const QuillSharedConfigurations(
|
enableScribble: true,
|
||||||
// locale: Locale('en'),
|
|
||||||
// ),
|
padding: const EdgeInsets.all(8),
|
||||||
// ),
|
placeholder: 'Type something...',
|
||||||
// ),
|
embedBuilders: [
|
||||||
// ),
|
...FlutterQuillEmbeds.editorBuilders(
|
||||||
|
imageEmbedConfig: QuillEditorImageEmbedConfig(
|
||||||
|
imageProviderBuilder: (context, imageUrl) {
|
||||||
|
// https://pub.dev/packages/flutter_quill_extensions#-image-assets
|
||||||
|
if (imageUrl.startsWith('assets/')) {
|
||||||
|
return AssetImage(imageUrl);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
videoEmbedConfig: QuillEditorVideoEmbedConfig(
|
||||||
|
customVideoBuilder: (videoUrl, readOnly) {
|
||||||
|
// To load YouTube videos https://github.com/singerdmx/flutter-quill/releases/tag/v10.8.0
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TimeStampEmbedBuilder(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TimeStampEmbed extends Embeddable {
|
||||||
|
const TimeStampEmbed(
|
||||||
|
String value,
|
||||||
|
) : super(timeStampType, value);
|
||||||
|
|
||||||
|
static const String timeStampType = 'timeStamp';
|
||||||
|
|
||||||
|
static TimeStampEmbed fromDocument(Document document) =>
|
||||||
|
TimeStampEmbed(jsonEncode(document.toDelta().toJson()));
|
||||||
|
|
||||||
|
Document get document => Document.fromJson(jsonDecode(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
class TimeStampEmbedBuilder extends EmbedBuilder {
|
||||||
|
@override
|
||||||
|
String get key => 'timeStamp';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toPlainText(Embed node) {
|
||||||
|
return node.value.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(
|
||||||
|
BuildContext context,
|
||||||
|
EmbedContext embedContext,
|
||||||
|
) {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.access_time_rounded),
|
||||||
|
Text(embedContext.node.value.data as String),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user