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 { 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; }); } }