Skip to content

Commit

Permalink
align pipup on reaching bottom+
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-kozyrev committed Apr 14, 2022
1 parent e5c8439 commit 9d4e5a0
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 45 deletions.
69 changes: 60 additions & 9 deletions example/lib/custom_code_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,25 @@ class _CustomCodeBoxState extends State<CustomCodeBox> {
reset = false;
}

List<String?> languageList = <String>[
java,
go,
python,
scala,
dart
];
List<String?> languageList = <String>[java, go, python, scala, dart];

<<<<<<< HEAD
List<String?> themeList = <String>[
'monokai-sublime',
'a11y-dark',
'an-old-hope',
'vs2015',
'vs',
'atom-one-dark'
=======
List<String?> themeList = <String>[
"monokai-sublime",
"a11y-dark",
"an-old-hope",
"vs2015",
"vs",
"atom-one-dark"
>>>>>>> ebab93d91dca3c601128e6729b4038dd6d5117f1
];

Widget buildDropdown(Iterable<String?> choices, String value, IconData icon,
Expand Down Expand Up @@ -78,17 +82,24 @@ class _CustomCodeBoxState extends State<CustomCodeBox> {
if (val == null) return;
setState(() => theme = val);
});
<<<<<<< HEAD

final TextButton resetButton = TextButton.icon(
icon: const Icon(Icons.delete, color: Colors.white),
label: const Text('Reset', style: TextStyle(color: Colors.white)),
=======
final resetButton = TextButton.icon(
icon: Icon(Icons.delete, color: Colors.white),
label: Text('Reset', style: TextStyle(color: Colors.white)),
>>>>>>> ebab93d91dca3c601128e6729b4038dd6d5117f1
onPressed: () {
setState(() {
reset = (!reset!);
});
},
},
);

<<<<<<< HEAD
final Container buttons = Container (
height: MediaQuery.of(context).size.height/13,
color: Colors.deepPurple[900],
Expand All @@ -108,6 +119,24 @@ class _CustomCodeBoxState extends State<CustomCodeBox> {

final InnerField codeField = InnerField(
key: ValueKey<String>('$language - $theme - $reset'),
=======
final buttons = Container(
height: MediaQuery.of(context).size.height / 13,
color: Colors.deepPurple[900],
child: Row(children: [
Spacer(flex: 2),
Text('Code editor',
style: TextStyle(fontSize: 28, color: Colors.white)),
Spacer(flex: 35),
codeDropdown,
Spacer(),
themeDropdown,
Spacer(),
resetButton
]));
final codeField = InnerField(
key: ValueKey("$language - $theme - $reset"),
>>>>>>> ebab93d91dca3c601128e6729b4038dd6d5117f1
language: language!,
theme: theme!,
);
Expand Down Expand Up @@ -152,8 +181,8 @@ class _InnerFieldState extends State<InnerField> {

@override
Widget build(BuildContext context) {

return Container(
<<<<<<< HEAD
color: _codeController!.theme!['root']!.backgroundColor,
height: MediaQuery.of(context).size.height / 13 * 12,
child: Stack(
Expand All @@ -179,5 +208,27 @@ class _InnerFieldState extends State<InnerField> {
]
)
);
=======
color: _codeController!.theme!['root']!.backgroundColor,
height: MediaQuery.of(context).size.height / 13 * 12,
child: Stack(children: [
Container(
child: CodeField(
controller: _codeController!,
textStyle: const TextStyle(fontFamily: 'SourceCode'),
)),
Align(
alignment: Alignment.topRight,
child: FloatingActionButton(
child: const Icon(Icons.format_align_left_outlined),
backgroundColor: Colors.indigo[800],
onPressed: () {
setState(() {
_codeController!.text =
autoRefactor(_codeController!.text, widget.language);
});
}))
]));
>>>>>>> ebab93d91dca3c601128e6729b4038dd6d5117f1
}
}
62 changes: 52 additions & 10 deletions lib/src/autocomplete/popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

/// Popup window displaying the list of possible completions
class Popup extends StatefulWidget {
final double row;
final double column;
final double verticalIndent;
final double leftIndent;
final PopupAlign align;
final Size editingWindowSize;
final TextStyle style;
final Color? backgroundColor;
Expand All @@ -16,13 +17,14 @@ class Popup extends StatefulWidget {

Popup(
{Key? key,
required this.row,
required this.column,
required this.controller,
required this.editingWindowSize,
required this.style,
required this.parentFocusNode,
this.backgroundColor})
required this.verticalIndent,
required this.leftIndent,
this.align = PopupAlign.top,
required this.controller,
required this.editingWindowSize,
required this.style,
required this.parentFocusNode,
this.backgroundColor})
: super(key: key);

@override
Expand All @@ -49,6 +51,7 @@ class _PopupState extends State<Popup> {

@override
Widget build(BuildContext context) {
<<<<<<< HEAD
return Padding(
padding: EdgeInsets.only(
left: min(widget.column, widget.editingWindowSize.width - width),
Expand All @@ -63,6 +66,32 @@ class _PopupState extends State<Popup> {
color: widget.style.color!,
width: 0.5,
),
=======
return widget.align == PopupAlign.top
? Positioned(
left:
min(widget.leftIndent, widget.editingWindowSize.width - width),
top: widget.verticalIndent,
child: _buildBox(),
)
: Positioned(
left:
min(widget.leftIndent, widget.editingWindowSize.width - width),
bottom: widget.verticalIndent,
child: _buildBox(),
);
}

Widget _buildBox() {
return ConstrainedBox(
constraints: BoxConstraints(maxHeight: height, maxWidth: width),
child: Container(
decoration: BoxDecoration(
color: widget.backgroundColor,
border: Border.all(
color: widget.style.color!,
width: 0.5,
>>>>>>> ebab93d91dca3c601128e6729b4038dd6d5117f1
),
child: ScrollablePositionedList.builder(
shrinkWrap: true,
Expand All @@ -74,6 +103,15 @@ class _PopupState extends State<Popup> {
return _buildListItem(index);
}),
),
child: ScrollablePositionedList.builder(
shrinkWrap: true,
physics: const ClampingScrollPhysics(),
itemScrollController: widget.controller.itemScrollController,
itemPositionsListener: widget.controller.itemPositionsListener,
itemCount: widget.controller.suggestions.length,
itemBuilder: (BuildContext context, int index) {
return _buildListItem(index);
}),
),
);
}
Expand All @@ -90,7 +128,6 @@ class _PopupState extends State<Popup> {
widget.controller.selectedIndex = index;
widget.parentFocusNode.requestFocus();
widget.controller.onCompletionSelected();

},
hoverColor: Colors.grey.withOpacity(0.1),
splashColor: Colors.transparent,
Expand All @@ -116,3 +153,8 @@ class _PopupState extends State<Popup> {
setState(() {});
}
}

enum PopupAlign {
top,
bottom,
}
Loading

0 comments on commit 9d4e5a0

Please sign in to comment.