Rich text editor for Flutter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

58 lines
1.5 KiB

import 'package:flutter/material.dart';
import 'package:flutter_quill/widgets/controller.dart';
import 'package:flutter_quill/widgets/editor.dart';
import '../widgets/demo_scaffold.dart';
class ReadOnlyPage extends StatefulWidget {
@override
_ReadOnlyPageState createState() => _ReadOnlyPageState();
}
class _ReadOnlyPageState extends State<ReadOnlyPage> {
final FocusNode _focusNode = FocusNode();
bool _edit = false;
@override
Widget build(BuildContext context) {
return DemoScaffold(
documentFilename: 'sample_data.json',
builder: _buildContent,
showToolbar: _edit == true,
floatingActionButton: FloatingActionButton.extended(
label: Text(_edit == true ? 'Done' : 'Edit'),
onPressed: _toggleEdit,
icon: Icon(_edit == true ? Icons.check : Icons.edit)),
);
}
Widget _buildContent(BuildContext context, QuillController? controller) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.grey.shade200),
),
child: QuillEditor(
controller: controller!,
scrollController: ScrollController(),
scrollable: true,
focusNode: _focusNode,
autoFocus: true,
readOnly: !_edit,
enableInteractiveSelection: true,
expands: false,
padding: EdgeInsets.zero,
),
),
);
}
void _toggleEdit() {
setState(() {
_edit = !_edit;
});
}
}