-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SuperTextField] [SuperDesktopTextField] Adds Page-Up/Down, Home/End …
- Loading branch information
1 parent
8610aa5
commit 53b90ad
Showing
15 changed files
with
2,207 additions
and
164 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
66 changes: 66 additions & 0 deletions
66
...itor/example/lib/demos/supertextfield/textfield_inside_single_child_scroll_view_demo.dart
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,66 @@ | ||
import 'package:example/demos/supertextfield/demo_text_styles.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:super_editor/super_text_field.dart'; | ||
|
||
/// Demo of [SuperDesktopTextField] inside [SingleChildScrollView] with scrollable content. | ||
class TextFieldInsideSingleChildScrollViewDemo extends StatefulWidget { | ||
const TextFieldInsideSingleChildScrollViewDemo({super.key}); | ||
|
||
@override | ||
State<TextFieldInsideSingleChildScrollViewDemo> createState() => _TextFieldInsideSingleChildScrollViewDemoState(); | ||
} | ||
|
||
class _TextFieldInsideSingleChildScrollViewDemoState extends State<TextFieldInsideSingleChildScrollViewDemo> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return SingleChildScrollView( | ||
child: Column( | ||
children: [ | ||
SizedBox( | ||
// Occupy 80% of the vertical space to avoid pushing text field off-screen | ||
// and to provide a visual clue on text field's position within demo. | ||
height: MediaQuery.of(context).size.height * 0.8, | ||
width: double.infinity, | ||
child: Placeholder( | ||
child: Center( | ||
child: Text("Content"), | ||
), | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: SuperDesktopTextField( | ||
// This demo tests scrolling text field behavior. Force the text field to be tall | ||
// enough to easily see content scrolling by, but short enough to ensure that | ||
// the content is scrollable. | ||
minLines: 5, | ||
maxLines: 5, | ||
textStyleBuilder: demoTextStyleBuilder, | ||
decorationBuilder: (context, child) { | ||
return Container( | ||
decoration: BoxDecoration( | ||
borderRadius: BorderRadius.circular(4), | ||
border: Border.all( | ||
color: Colors.grey.shade300, | ||
width: 1, | ||
), | ||
), | ||
child: child, | ||
); | ||
}, | ||
), | ||
), | ||
SizedBox( | ||
height: MediaQuery.of(context).size.height * 2, | ||
width: double.infinity, | ||
child: Placeholder( | ||
child: Center( | ||
child: Text("Content"), | ||
), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
super_editor/example/lib/demos/supertextfield/textfield_inside_slivers_demo.dart
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,70 @@ | ||
import 'package:example/demos/supertextfield/demo_text_styles.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:super_editor/super_text_field.dart'; | ||
|
||
/// Demo of [SuperDesktopTextField] inside Slivers with scrollable content. | ||
class TextFieldInsideSliversDemo extends StatefulWidget { | ||
const TextFieldInsideSliversDemo({super.key}); | ||
|
||
@override | ||
State<TextFieldInsideSliversDemo> createState() => _TextFieldInsideSliversDemoState(); | ||
} | ||
|
||
class _TextFieldInsideSliversDemoState extends State<TextFieldInsideSliversDemo> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return CustomScrollView( | ||
slivers: [ | ||
SliverToBoxAdapter( | ||
child: SizedBox( | ||
// Occupy 80% of the vertical space to avoid pushing text field off-screen | ||
// and to provide a visual clue on text field's position within demo. | ||
height: MediaQuery.of(context).size.height * 0.8, | ||
width: double.infinity, | ||
child: Placeholder( | ||
child: Center( | ||
child: Text("Content"), | ||
), | ||
), | ||
), | ||
), | ||
SliverToBoxAdapter( | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: SuperDesktopTextField( | ||
// This demo tests scrolling text field behavior. Force the text field to be tall | ||
// enough to easily see content scrolling by, but short enough to ensure that | ||
// the content is scrollable. | ||
minLines: 5, | ||
maxLines: 5, | ||
textStyleBuilder: demoTextStyleBuilder, | ||
decorationBuilder: (context, child) { | ||
return Container( | ||
decoration: BoxDecoration( | ||
borderRadius: BorderRadius.circular(4), | ||
border: Border.all( | ||
color: Colors.grey.shade300, | ||
width: 1, | ||
), | ||
), | ||
child: child, | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
SliverToBoxAdapter( | ||
child: SizedBox( | ||
height: MediaQuery.of(context).size.height, | ||
width: double.infinity, | ||
child: Placeholder( | ||
child: Center( | ||
child: Text("Content"), | ||
), | ||
), | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |
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
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
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
21 changes: 21 additions & 0 deletions
21
super_editor/lib/src/infrastructure/flutter/build_context.dart
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,21 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
extension ScrollableFinder on BuildContext { | ||
/// Finds the nearest ancestor [Scrollable] with a vertical scroll in the | ||
/// widget tree. | ||
ScrollableState? get findAncestorScrollableWithVerticalScroll { | ||
final ancestorScrollable = Scrollable.maybeOf(this); | ||
if (ancestorScrollable == null) { | ||
return null; | ||
} | ||
|
||
final direction = ancestorScrollable.axisDirection; | ||
// If the direction is horizontal, then we are inside a widget like a TabBar | ||
// or a horizontal ListView, so we can't use the ancestor scrollable | ||
if (direction == AxisDirection.left || direction == AxisDirection.right) { | ||
return null; | ||
} | ||
|
||
return ancestorScrollable; | ||
} | ||
} |
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.