-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #429 from DenserMeerkat/resolve-issue-env-field
fix: environment field issues
- Loading branch information
Showing
15 changed files
with
280 additions
and
405 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:extended_text_field/extended_text_field.dart'; | ||
import 'package:apidash/consts.dart'; | ||
import 'envvar_span.dart'; | ||
|
||
class EnvRegExpSpanBuilder extends RegExpSpecialTextSpanBuilder { | ||
@override | ||
List<RegExpSpecialText> get regExps => <RegExpSpecialText>[ | ||
RegExpEnvText(), | ||
]; | ||
} | ||
|
||
class RegExpEnvText extends RegExpSpecialText { | ||
@override | ||
RegExp get regExp => kEnvVarRegEx; | ||
@override | ||
InlineSpan finishText(int start, Match match, | ||
{TextStyle? textStyle, SpecialTextGestureTapCallback? onTap}) { | ||
final String value = '${match[0]}'; | ||
return ExtendedWidgetSpan( | ||
actualText: value, | ||
start: start, | ||
alignment: PlaceholderAlignment.middle, | ||
child: EnvVarSpan(variableKey: value.substring(2, value.length - 2)), | ||
); | ||
} | ||
} |
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,113 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:multi_trigger_autocomplete/multi_trigger_autocomplete.dart'; | ||
import 'package:extended_text_field/extended_text_field.dart'; | ||
import 'env_regexp_span_builder.dart'; | ||
import 'env_trigger_options.dart'; | ||
|
||
class EnvironmentTriggerField extends StatefulWidget { | ||
const EnvironmentTriggerField({ | ||
super.key, | ||
required this.keyId, | ||
this.initialValue, | ||
this.onChanged, | ||
this.onFieldSubmitted, | ||
this.style, | ||
this.decoration, | ||
this.optionsWidthFactor, | ||
}); | ||
|
||
final String keyId; | ||
final String? initialValue; | ||
final void Function(String)? onChanged; | ||
final void Function(String)? onFieldSubmitted; | ||
final TextStyle? style; | ||
final InputDecoration? decoration; | ||
final double? optionsWidthFactor; | ||
|
||
@override | ||
State<EnvironmentTriggerField> createState() => | ||
_EnvironmentTriggerFieldState(); | ||
} | ||
|
||
class _EnvironmentTriggerFieldState extends State<EnvironmentTriggerField> { | ||
final TextEditingController controller = TextEditingController(); | ||
final FocusNode focusNode = FocusNode(); | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
controller.text = widget.initialValue ?? ''; | ||
controller.selection = | ||
TextSelection.collapsed(offset: controller.text.length); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
controller.dispose(); | ||
focusNode.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
void didUpdateWidget(EnvironmentTriggerField oldWidget) { | ||
super.didUpdateWidget(oldWidget); | ||
if (oldWidget.initialValue != widget.initialValue) { | ||
controller.text = widget.initialValue ?? ""; | ||
controller.selection = | ||
TextSelection.collapsed(offset: controller.text.length); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MultiTriggerAutocomplete( | ||
key: Key(widget.keyId), | ||
textEditingController: controller, | ||
focusNode: focusNode, | ||
optionsWidthFactor: widget.optionsWidthFactor, | ||
autocompleteTriggers: [ | ||
AutocompleteTrigger( | ||
trigger: '{', | ||
triggerEnd: "}}", | ||
triggerOnlyAfterSpace: false, | ||
optionsViewBuilder: (context, autocompleteQuery, controller) { | ||
return EnvironmentAutocompleteOptions( | ||
query: autocompleteQuery.query, | ||
onSuggestionTap: (suggestion) { | ||
final autocomplete = MultiTriggerAutocomplete.of(context); | ||
autocomplete.acceptAutocompleteOption( | ||
'{${suggestion.variable.key}', | ||
); | ||
widget.onChanged?.call(controller.text); | ||
}); | ||
}), | ||
AutocompleteTrigger( | ||
trigger: '{{', | ||
triggerEnd: "}}", | ||
triggerOnlyAfterSpace: false, | ||
optionsViewBuilder: (context, autocompleteQuery, controller) { | ||
return EnvironmentAutocompleteOptions( | ||
query: autocompleteQuery.query, | ||
onSuggestionTap: (suggestion) { | ||
final autocomplete = MultiTriggerAutocomplete.of(context); | ||
autocomplete.acceptAutocompleteOption( | ||
suggestion.variable.key, | ||
); | ||
widget.onChanged?.call(controller.text); | ||
}); | ||
}), | ||
], | ||
fieldViewBuilder: (context, textEditingController, focusnode) { | ||
return ExtendedTextField( | ||
controller: textEditingController, | ||
focusNode: focusnode, | ||
decoration: widget.decoration, | ||
style: widget.style, | ||
onChanged: widget.onChanged, | ||
onSubmitted: widget.onFieldSubmitted, | ||
specialTextSpanBuilder: EnvRegExpSpanBuilder(), | ||
); | ||
}, | ||
); | ||
} | ||
} |
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:apidash/consts.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
import 'package:apidash/models/models.dart'; | ||
import 'package:apidash/providers/providers.dart'; | ||
import 'package:apidash/utils/utils.dart'; | ||
|
||
import 'envvar_indicator.dart'; | ||
|
||
class EnvironmentAutocompleteOptions extends ConsumerWidget { | ||
const EnvironmentAutocompleteOptions({ | ||
super.key, | ||
required this.query, | ||
required this.onSuggestionTap, | ||
}); | ||
|
||
final String query; | ||
final ValueSetter<EnvironmentVariableSuggestion> onSuggestionTap; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final envMap = ref.watch(availableEnvironmentVariablesStateProvider); | ||
final activeEnvironmentId = ref.watch(activeEnvironmentIdStateProvider); | ||
final suggestions = | ||
getEnvironmentTriggerSuggestions(query, envMap, activeEnvironmentId); | ||
return suggestions == null || suggestions.isEmpty | ||
? const SizedBox.shrink() | ||
: ClipRRect( | ||
borderRadius: kBorderRadius8, | ||
child: Material( | ||
type: MaterialType.card, | ||
elevation: 8, | ||
child: ConstrainedBox( | ||
constraints: | ||
const BoxConstraints(maxHeight: kSuggestionsMenuMaxHeight), | ||
child: Ink( | ||
width: kSuggestionsMenuWidth, | ||
decoration: BoxDecoration( | ||
color: Theme.of(context).colorScheme.surface, | ||
borderRadius: kBorderRadius8, | ||
border: Border.all( | ||
color: Theme.of(context).colorScheme.outlineVariant, | ||
), | ||
), | ||
child: ListView.separated( | ||
shrinkWrap: true, | ||
itemCount: suggestions.length, | ||
separatorBuilder: (context, index) => | ||
const Divider(height: 2), | ||
itemBuilder: (context, index) { | ||
final suggestion = suggestions[index]; | ||
return ListTile( | ||
dense: true, | ||
leading: EnvVarIndicator(suggestion: suggestion), | ||
title: Text(suggestion.variable.key), | ||
subtitle: Text(suggestion.variable.value), | ||
onTap: () => onSuggestionTap(suggestion), | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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.