line wrapping
This commit is contained in:
parent
7bd690a807
commit
be43333da6
2 changed files with 80 additions and 6 deletions
72
lib/codefield.dart
Normal file
72
lib/codefield.dart
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_code_editor/flutter_code_editor.dart';
|
||||||
|
|
||||||
|
class WrappedCodeField extends StatefulWidget {
|
||||||
|
final CodeController controller;
|
||||||
|
final bool expands;
|
||||||
|
final bool wrap;
|
||||||
|
final TextStyle? textStyle;
|
||||||
|
final Color? cursorColor;
|
||||||
|
final EdgeInsets padding;
|
||||||
|
final bool readOnly;
|
||||||
|
final FocusNode? focusNode;
|
||||||
|
|
||||||
|
const WrappedCodeField({
|
||||||
|
super.key,
|
||||||
|
required this.controller,
|
||||||
|
this.expands = false,
|
||||||
|
this.wrap = true, // ✅ Enable wrapping by default
|
||||||
|
this.textStyle,
|
||||||
|
this.cursorColor,
|
||||||
|
this.padding = EdgeInsets.zero,
|
||||||
|
this.readOnly = false,
|
||||||
|
this.focusNode,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_WrappedCodeFieldState createState() => _WrappedCodeFieldState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _WrappedCodeFieldState extends State<WrappedCodeField> {
|
||||||
|
late FocusNode _focusNode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_focusNode = widget.focusNode ?? FocusNode();
|
||||||
|
_focusNode.attach(context, onKeyEvent: _onKeyEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyEventResult _onKeyEvent(FocusNode node, KeyEvent event) {
|
||||||
|
return widget.controller.onKey(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_focusNode.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
padding: widget.padding,
|
||||||
|
child: TextField(
|
||||||
|
focusNode: _focusNode,
|
||||||
|
controller: widget.controller,
|
||||||
|
expands: widget.expands,
|
||||||
|
minLines: widget.expands ? null : 1,
|
||||||
|
maxLines: widget.expands ? null : null, // Allows text to grow dynamically
|
||||||
|
scrollPhysics: widget.wrap ? const NeverScrollableScrollPhysics() : null,
|
||||||
|
style: widget.textStyle ?? const TextStyle(fontSize: 16),
|
||||||
|
cursorColor: widget.cursorColor ?? Colors.white,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
isCollapsed: true,
|
||||||
|
border: InputBorder.none,
|
||||||
|
contentPadding: EdgeInsets.symmetric(vertical: 16),
|
||||||
|
),
|
||||||
|
readOnly: widget.readOnly,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ import 'package:path/path.dart' as path;
|
||||||
import 'themes/day.dart';
|
import 'themes/day.dart';
|
||||||
import 'themes/night.dart';
|
import 'themes/night.dart';
|
||||||
import 'themes/markdown.dart';
|
import 'themes/markdown.dart';
|
||||||
|
import 'codefield.dart';
|
||||||
|
|
||||||
class NoteEditorScreen extends StatefulWidget {
|
class NoteEditorScreen extends StatefulWidget {
|
||||||
final File note;
|
final File note;
|
||||||
|
|
@ -204,12 +205,13 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||||
child: CodeTheme(
|
child: CodeTheme(
|
||||||
data: CodeThemeData(
|
data: CodeThemeData(
|
||||||
styles: widget.isDarkMode ? nightTheme : dayTheme),
|
styles: widget.isDarkMode ? nightTheme : dayTheme),
|
||||||
child: CodeField(
|
child: SingleChildScrollView(
|
||||||
gutterStyle: GutterStyle.none,
|
child: WrappedCodeField(
|
||||||
controller: _controller,
|
wrap: true,
|
||||||
expands: true,
|
controller: _controller,
|
||||||
textStyle: TextStyle(
|
textStyle: TextStyle(
|
||||||
fontSize: _fontSize,
|
fontSize: _fontSize,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue