novel_editor 0.4.0
novel_editor: ^0.4.0 copied to clipboard
Novel for Flutter — a Notion-style rich text editor with AI writing assistant, slash commands, floating toolbar, and markdown import/export. Drop-in WYSIWYG editor widget with OpenAI, Gemini, and Anth [...]
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:novel_editor/novel_editor.dart';
void main() => runApp(const App());
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'novel_editor Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData.dark(useMaterial3: true).copyWith(
scaffoldBackgroundColor: Colors.black,
),
home: const Demo(),
);
}
}
class Demo extends StatelessWidget {
const Demo({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: NovelEditor(
// Markdown content in
initialContent: _sampleContent,
// Markdown content out (on every edit)
onChanged: (md) => debugPrint('Content: ${md.length} chars'),
// Editor options
editable: true,
darkMode: true,
fixedToolbar: true, // Always-visible toolbar at top
floatingToolbar: true, // Appears on text selection
slashMenu: true, // Type / for commands
analyticsBar: true, // Word count, reading time at bottom
// AI — pass your API key (optional, AI features hidden without it)
// ai: NovelAI.gemini(apiKey: 'YOUR_GEMINI_KEY'),
// ai: NovelAI.openAI(apiKey: 'YOUR_OPENAI_KEY'),
// ai: NovelAI.anthropic(apiKey: 'YOUR_ANTHROPIC_KEY'),
),
);
}
}
const _sampleContent = '''# Welcome to novel_editor
Novel for Flutter — a drop-in WYSIWYG editor with AI.
## Features
- **Bold**, *italic*, ~~strikethrough~~, and `inline code`
- Headings (H1, H2, H3), bullet lists, numbered lists
- To-do lists with checkboxes
- Code blocks, blockquotes, dividers
- Slash commands — type `/`
- Floating toolbar on text selection
- Fixed toolbar with formatting + AI button
- Markdown import/export
- Word count, character count, reading time
## Try It
1. **Select text** → floating toolbar appears with formatting + AI actions
2. **Type `/`** → slash command menu with blocks + AI
3. **Cmd+B** for bold, **Cmd+I** for italic, **Cmd+U** for underline
4. Click **H1/H2/H3** in toolbar to change heading level
## AI Features (when API key is provided)
Type `/ai` to open the AI prompt — or select text and use AI actions in the floating toolbar:
- **AI Improve** — rewrites selected text better
- **AI Summarize** — condenses selected text
- **AI Fix Grammar** — fixes spelling and grammar
- **AI Shorter** — makes selected text concise
- **AI Translate** — translates to any language
> "The best editor is one that gets out of your way." — Novel for Flutter
---
- [x] WYSIWYG editing
- [x] Slash commands
- [x] AI integration
- [x] Dark & light themes
- [ ] Your feature here
''';