Pull up `TextEditingDeltaHistoryManager` to drop redundancy (#1306)

pull/1311/head
Brett Morgan 3 years ago committed by GitHub
parent addafa93ec
commit 77cf69097a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -303,46 +303,46 @@ class _MyHomePageState extends State<MyHomePage> {
_updateToggleButtonsStateOnButtonPressed, _updateToggleButtonsStateOnButtonPressed,
updateToggleButtonStateOnSelectionChanged: updateToggleButtonStateOnSelectionChanged:
_updateToggleButtonsStateOnSelectionChanged, _updateToggleButtonsStateOnSelectionChanged,
child: Column( child: TextEditingDeltaHistoryManager(
children: [ history: _textEditingDeltaHistory,
Padding( updateHistoryOnInput: _updateTextEditingDeltaHistory,
padding: const EdgeInsets.symmetric(vertical: 8.0), child: Column(
child: Row( children: [
mainAxisAlignment: MainAxisAlignment.center, Padding(
children: [ padding: const EdgeInsets.symmetric(vertical: 8.0),
Builder(builder: (innerContext) { child: Row(
final ToggleButtonsStateManager manager = mainAxisAlignment: MainAxisAlignment.center,
ToggleButtonsStateManager.of(innerContext); children: [
Builder(builder: (innerContext) {
return ToggleButtons( final ToggleButtonsStateManager manager =
borderRadius: ToggleButtonsStateManager.of(innerContext);
const BorderRadius.all(Radius.circular(4.0)),
isSelected: [ return ToggleButtons(
manager.toggleButtonsState borderRadius:
.contains(ToggleButtonsState.bold), const BorderRadius.all(Radius.circular(4.0)),
manager.toggleButtonsState isSelected: [
.contains(ToggleButtonsState.italic), manager.toggleButtonsState
manager.toggleButtonsState .contains(ToggleButtonsState.bold),
.contains(ToggleButtonsState.underline), manager.toggleButtonsState
], .contains(ToggleButtonsState.italic),
onPressed: (index) => manager.toggleButtonsState
manager.updateToggleButtonsOnButtonPressed(index), .contains(ToggleButtonsState.underline),
children: const [ ],
Icon(Icons.format_bold), onPressed: (index) => manager
Icon(Icons.format_italic), .updateToggleButtonsOnButtonPressed(index),
Icon(Icons.format_underline), children: const [
], Icon(Icons.format_bold),
); Icon(Icons.format_italic),
}), Icon(Icons.format_underline),
], ],
);
}),
],
),
), ),
), Expanded(
Expanded( child: Padding(
child: Padding( padding: const EdgeInsets.symmetric(horizontal: 35.0),
padding: const EdgeInsets.symmetric(horizontal: 35.0),
child: TextEditingDeltaHistoryManager(
history: _textEditingDeltaHistory,
updateHistoryOnInput: _updateTextEditingDeltaHistory,
child: BasicTextField( child: BasicTextField(
controller: _replacementTextEditingController, controller: _replacementTextEditingController,
style: const TextStyle( style: const TextStyle(
@ -351,15 +351,11 @@ class _MyHomePageState extends State<MyHomePage> {
), ),
), ),
), ),
), Expanded(
Expanded( child: Column(
child: Column( children: [
children: [ _buildTextEditingDeltaViewHeader(),
_buildTextEditingDeltaViewHeader(), Expanded(
Expanded(
child: TextEditingDeltaHistoryManager(
history: _textEditingDeltaHistory,
updateHistoryOnInput: _updateTextEditingDeltaHistory,
child: Builder( child: Builder(
builder: (innerContext) { builder: (innerContext) {
final TextEditingDeltaHistoryManager manager = final TextEditingDeltaHistoryManager manager =
@ -381,12 +377,12 @@ class _MyHomePageState extends State<MyHomePage> {
}, },
), ),
), ),
), const SizedBox(height: 10),
const SizedBox(height: 10), ],
], ),
), ),
), ],
], ),
), ),
), ),
), ),

@ -18,7 +18,8 @@ class TextEditingDeltaHistoryManager extends InheritedWidget {
static TextEditingDeltaHistoryManager of(BuildContext context) { static TextEditingDeltaHistoryManager of(BuildContext context) {
final TextEditingDeltaHistoryManager? result = context final TextEditingDeltaHistoryManager? result = context
.dependOnInheritedWidgetOfExactType<TextEditingDeltaHistoryManager>(); .dependOnInheritedWidgetOfExactType<TextEditingDeltaHistoryManager>();
assert(result != null, 'No ToggleButtonsStateManager found in context'); assert(
result != null, 'No TextEditingDeltaHistoryManager found in context');
return result!; return result!;
} }

Loading…
Cancel
Save