From 8850a0bd3cb496968a1c981da698b272dd822151 Mon Sep 17 00:00:00 2001 From: Thito Yalasatria Sunarya Date: Sun, 24 Nov 2024 09:20:49 +0700 Subject: [PATCH] Update text field example 2 --- .../components/input/input_example_2.dart | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/docs/lib/pages/docs/components/input/input_example_2.dart b/docs/lib/pages/docs/components/input/input_example_2.dart index 925d6283..31606c0c 100644 --- a/docs/lib/pages/docs/components/input/input_example_2.dart +++ b/docs/lib/pages/docs/components/input/input_example_2.dart @@ -1,13 +1,36 @@ import 'package:shadcn_flutter/shadcn_flutter.dart'; -class InputExample2 extends StatelessWidget { +class InputExample2 extends StatefulWidget { const InputExample2({super.key}); + @override + State createState() => _InputExample2State(); +} + +class _InputExample2State extends State { + final TextEditingController _searchController = TextEditingController(); @override Widget build(BuildContext context) { - return const TextField( + return TextField( + controller: _searchController, initialValue: 'Hello World!', - placeholder: Text('Enter your message'), + placeholder: Text('Search something...'), + leading: StatedWidget.builder( + builder: (context, states) { + if (states.focused) { + return Icon(Icons.search); + } else { + return Icon(Icons.search).iconMutedForeground(); + } + }, + ), + trailing: IconButton.text( + icon: Icon(Icons.close), + density: ButtonDensity.compact, + onPressed: () { + _searchController.clear(); + }, + ), ); } }