-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic screen structure added for rich text editing
- Loading branch information
vshanbha
committed
Nov 17, 2024
1 parent
29dd41e
commit a2e710b
Showing
18 changed files
with
969 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" | ||
#include "Generated.xcconfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" | ||
#include "Generated.xcconfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Uncomment this line to define a global platform for your project | ||
# platform :ios, '12.0' | ||
|
||
# CocoaPods analytics sends network stats synchronously affecting flutter build latency. | ||
ENV['COCOAPODS_DISABLE_STATS'] = 'true' | ||
|
||
project 'Runner', { | ||
'Debug' => :debug, | ||
'Profile' => :release, | ||
'Release' => :release, | ||
} | ||
|
||
def flutter_root | ||
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) | ||
unless File.exist?(generated_xcode_build_settings_path) | ||
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" | ||
end | ||
|
||
File.foreach(generated_xcode_build_settings_path) do |line| | ||
matches = line.match(/FLUTTER_ROOT\=(.*)/) | ||
return matches[1].strip if matches | ||
end | ||
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" | ||
end | ||
|
||
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) | ||
|
||
flutter_ios_podfile_setup | ||
|
||
target 'Runner' do | ||
use_frameworks! | ||
use_modular_headers! | ||
|
||
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) | ||
target 'RunnerTests' do | ||
inherit! :search_paths | ||
end | ||
end | ||
|
||
post_install do |installer| | ||
installer.pods_project.targets.each do |target| | ||
flutter_additional_ios_build_settings(target) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_quill/flutter_quill.dart' as quill; | ||
import 'package:super_editor/super_editor.dart'; | ||
|
||
class EditRichTextScreen extends StatefulWidget { | ||
const EditRichTextScreen({super.key}); | ||
|
||
@override | ||
_EditRichTextScreenState createState() => _EditRichTextScreenState(); | ||
} | ||
|
||
class _EditRichTextScreenState extends State<EditRichTextScreen> { | ||
quill.QuillController? _quillController; | ||
Document? _superEditorDocument; | ||
String _currentEditor = "Quill"; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_quillController = quill.QuillController.basic(); | ||
_superEditorDocument = MutableDocument(nodes: [ | ||
ParagraphNode(id: DocumentEditor.createNodeId(), text: AttributedText()), | ||
]); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Edit Rich Text'), | ||
), | ||
body: Container( | ||
padding: const EdgeInsets.all(16), | ||
child: Column( | ||
children: [ | ||
DropdownButton<String>( | ||
value: _currentEditor, | ||
items: const [ | ||
DropdownMenuItem(value: "Quill", child: Text("Quill Editor")), | ||
DropdownMenuItem( | ||
value: "HTML", child: Text("HTML Enhanced (Stub)")), | ||
DropdownMenuItem( | ||
value: "SuperEditor", child: Text("Super Editor")), | ||
], | ||
onChanged: (value) { | ||
setState(() { | ||
_currentEditor = value ?? "Quill"; | ||
}); | ||
}, | ||
), | ||
Expanded( | ||
child: Container( | ||
decoration: BoxDecoration( | ||
border: Border.all(width: 2.0), | ||
borderRadius: | ||
const BorderRadius.all(Radius.elliptical(16.0, 9.0))), | ||
padding: const EdgeInsets.all(5.0), | ||
child: _buildEditor(), | ||
), | ||
), | ||
ElevatedButton( | ||
onPressed: () { | ||
String content = ""; | ||
|
||
if (_currentEditor == "Quill") { | ||
content = _quillController?.document.toPlainText() ?? ""; | ||
} else if (_currentEditor == "SuperEditor") { | ||
content = _superEditorDocument?.nodes.map((node) { | ||
if (node is ParagraphNode) { | ||
return node.text.text; | ||
} | ||
return ""; | ||
}).join("\n") ?? | ||
""; | ||
} else { | ||
content = "HTML Enhanced content (stub)."; | ||
} | ||
|
||
Navigator.pop(context, content); | ||
}, | ||
child: const Text('Save'), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
|
||
Widget _buildEditor() { | ||
if (_currentEditor == "Quill") { | ||
return quill.QuillEditor.basic( | ||
controller: _quillController!, | ||
// readOnly: false, | ||
); | ||
} | ||
/* | ||
else if (_currentEditor == "SuperEditor") { | ||
return SuperEditor( | ||
editor: DocumentEditor(document: _superEditorDocument!), | ||
documentOverlayBuilders: [], | ||
); | ||
} | ||
*/ | ||
else { | ||
return const Center( | ||
child: Text("HTML Enhanced Editor is not implemented."), | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,125 +1,23 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_rte_tester/main_screen.dart'; | ||
|
||
void main() { | ||
runApp(const MyApp()); | ||
runApp(const RTEApp()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
const MyApp({super.key}); | ||
class RTEApp extends StatelessWidget { | ||
const RTEApp({super.key}); | ||
|
||
// This widget is the root of your application. | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'Flutter Demo', | ||
title: 'Flutter Rich Text Editor Tester', | ||
theme: ThemeData( | ||
// This is the theme of your application. | ||
// | ||
// TRY THIS: Try running your application with "flutter run". You'll see | ||
// the application has a purple toolbar. Then, without quitting the app, | ||
// try changing the seedColor in the colorScheme below to Colors.green | ||
// and then invoke "hot reload" (save your changes or press the "hot | ||
// reload" button in a Flutter-supported IDE, or press "r" if you used | ||
// the command line to start the app). | ||
// | ||
// Notice that the counter didn't reset back to zero; the application | ||
// state is not lost during the reload. To reset the state, use hot | ||
// restart instead. | ||
// | ||
// This works for code too, not just values: Most code changes can be | ||
// tested with just a hot reload. | ||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), | ||
useMaterial3: true, | ||
), | ||
home: const MyHomePage(title: 'Flutter Demo Home Page'), | ||
); | ||
} | ||
} | ||
|
||
class MyHomePage extends StatefulWidget { | ||
const MyHomePage({super.key, required this.title}); | ||
|
||
// This widget is the home page of your application. It is stateful, meaning | ||
// that it has a State object (defined below) that contains fields that affect | ||
// how it looks. | ||
|
||
// This class is the configuration for the state. It holds the values (in this | ||
// case the title) provided by the parent (in this case the App widget) and | ||
// used by the build method of the State. Fields in a Widget subclass are | ||
// always marked "final". | ||
|
||
final String title; | ||
|
||
@override | ||
State<MyHomePage> createState() => _MyHomePageState(); | ||
} | ||
|
||
class _MyHomePageState extends State<MyHomePage> { | ||
int _counter = 0; | ||
|
||
void _incrementCounter() { | ||
setState(() { | ||
// This call to setState tells the Flutter framework that something has | ||
// changed in this State, which causes it to rerun the build method below | ||
// so that the display can reflect the updated values. If we changed | ||
// _counter without calling setState(), then the build method would not be | ||
// called again, and so nothing would appear to happen. | ||
_counter++; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
// This method is rerun every time setState is called, for instance as done | ||
// by the _incrementCounter method above. | ||
// | ||
// The Flutter framework has been optimized to make rerunning build methods | ||
// fast, so that you can just rebuild anything that needs updating rather | ||
// than having to individually change instances of widgets. | ||
return Scaffold( | ||
appBar: AppBar( | ||
// TRY THIS: Try changing the color here to a specific color (to | ||
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar | ||
// change color while the other colors stay the same. | ||
backgroundColor: Theme.of(context).colorScheme.inversePrimary, | ||
// Here we take the value from the MyHomePage object that was created by | ||
// the App.build method, and use it to set our appbar title. | ||
title: Text(widget.title), | ||
), | ||
body: Center( | ||
// Center is a layout widget. It takes a single child and positions it | ||
// in the middle of the parent. | ||
child: Column( | ||
// Column is also a layout widget. It takes a list of children and | ||
// arranges them vertically. By default, it sizes itself to fit its | ||
// children horizontally, and tries to be as tall as its parent. | ||
// | ||
// Column has various properties to control how it sizes itself and | ||
// how it positions its children. Here we use mainAxisAlignment to | ||
// center the children vertically; the main axis here is the vertical | ||
// axis because Columns are vertical (the cross axis would be | ||
// horizontal). | ||
// | ||
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint" | ||
// action in the IDE, or press "p" in the console), to see the | ||
// wireframe for each widget. | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
const Text( | ||
'You have pushed the button this many times:', | ||
), | ||
Text( | ||
'$_counter', | ||
style: Theme.of(context).textTheme.headlineMedium, | ||
), | ||
], | ||
), | ||
), | ||
floatingActionButton: FloatingActionButton( | ||
onPressed: _incrementCounter, | ||
tooltip: 'Increment', | ||
child: const Icon(Icons.add), | ||
), // This trailing comma makes auto-formatting nicer for build methods. | ||
home: const MainScreen(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_rte_tester/edit_rich_text_screen.dart'; | ||
import 'package:flutter_rte_tester/view_rich_text_screen.dart'; | ||
|
||
class MainScreen extends StatefulWidget { | ||
const MainScreen({super.key}); | ||
|
||
@override | ||
_MainScreenState createState() => _MainScreenState(); | ||
} | ||
|
||
class _MainScreenState extends State<MainScreen> { | ||
final List<String> _items = []; | ||
|
||
void _addItem(String content) { | ||
setState(() { | ||
_items.add(content); | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Rich Text Editor Demo'), | ||
), | ||
body: ListView.builder( | ||
itemCount: _items.length, | ||
itemBuilder: (context, index) { | ||
return ListTile( | ||
title: Text( | ||
_items[index], | ||
maxLines: 1, | ||
overflow: TextOverflow.ellipsis, | ||
), | ||
onTap: () { | ||
Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => | ||
ViewRichTextScreen(content: _items[index]), | ||
), | ||
); | ||
}, | ||
); | ||
}, | ||
), | ||
floatingActionButton: FloatingActionButton( | ||
onPressed: () async { | ||
final result = await Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => const EditRichTextScreen(), | ||
), | ||
); | ||
|
||
if (result != null && result is String) { | ||
_addItem(result); | ||
} | ||
}, | ||
child: const Icon(Icons.add), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class ViewRichTextScreen extends StatelessWidget { | ||
final String content; | ||
|
||
const ViewRichTextScreen({super.key, required this.content}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('View Rich Text'), | ||
), | ||
body: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: SingleChildScrollView( | ||
child: Text( | ||
content, | ||
style: const TextStyle(fontSize: 16), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.