Use ValueNotifier instead of setState in AIScribeBar
This commit is contained in:
@@ -22,7 +22,7 @@ class AIScribeBar extends StatefulWidget {
|
|||||||
|
|
||||||
class _AIScribeBarState extends State<AIScribeBar> {
|
class _AIScribeBarState extends State<AIScribeBar> {
|
||||||
final TextEditingController _controller = TextEditingController();
|
final TextEditingController _controller = TextEditingController();
|
||||||
bool _isButtonEnabled = false;
|
final ValueNotifier<bool> _isButtonEnabled = ValueNotifier(false);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -34,13 +34,12 @@ class _AIScribeBarState extends State<AIScribeBar> {
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
_controller.removeListener(_onTextChanged);
|
_controller.removeListener(_onTextChanged);
|
||||||
_controller.dispose();
|
_controller.dispose();
|
||||||
|
_isButtonEnabled.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onTextChanged() {
|
void _onTextChanged() {
|
||||||
setState(() {
|
_isButtonEnabled.value = _controller.text.trim().isNotEmpty;
|
||||||
_isButtonEnabled = _controller.text.trim().isNotEmpty;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSendPressed() {
|
void _onSendPressed() {
|
||||||
@@ -73,14 +72,19 @@ class _AIScribeBarState extends State<AIScribeBar> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: AIScribeSizes.fieldSpacing),
|
const SizedBox(width: AIScribeSizes.fieldSpacing),
|
||||||
TMailButtonWidget.fromIcon(
|
ValueListenableBuilder<bool>(
|
||||||
icon: widget.imagePaths.icSend,
|
valueListenable: _isButtonEnabled,
|
||||||
iconSize: AIScribeSizes.sendIconSize,
|
builder: (context, isEnabled, child) {
|
||||||
iconColor: Colors.white,
|
return TMailButtonWidget.fromIcon(
|
||||||
backgroundColor: _isButtonEnabled
|
icon: widget.imagePaths.icSend,
|
||||||
? AIScribeButtonStyles.sendCustomPromptBackgroundColor
|
iconSize: AIScribeSizes.sendIconSize,
|
||||||
: AIScribeButtonStyles.sendCustomPromptBackgroundColorDisabled,
|
iconColor: Colors.white,
|
||||||
onTapActionCallback: _isButtonEnabled ? _onSendPressed : null,
|
backgroundColor: isEnabled
|
||||||
|
? AIScribeButtonStyles.sendCustomPromptBackgroundColor
|
||||||
|
: AIScribeButtonStyles.sendCustomPromptBackgroundColorDisabled,
|
||||||
|
onTapActionCallback: isEnabled ? _onSendPressed : null,
|
||||||
|
);
|
||||||
|
},
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user