From cd84555f74b3c18654c16585ebf9d61b6a530754 Mon Sep 17 00:00:00 2001 From: xsahil03x Date: Wed, 25 Nov 2020 16:43:35 +0530 Subject: [PATCH] extract searchTextField into a separate widget --- example/lib/new_group_chat_screen.dart | 35 +---------- example/lib/search_text_field.dart | 81 ++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 32 deletions(-) create mode 100644 example/lib/search_text_field.dart diff --git a/example/lib/new_group_chat_screen.dart b/example/lib/new_group_chat_screen.dart index 11b6aa14..ece3ca9a 100644 --- a/example/lib/new_group_chat_screen.dart +++ b/example/lib/new_group_chat_screen.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; import 'group_chat_details_screen.dart'; +import 'search_text_field.dart'; class NewGroupChatScreen extends StatefulWidget { @override @@ -98,38 +99,8 @@ class _NewGroupChatScreenState extends State { ], ), SliverToBoxAdapter( - child: Container( - height: 36, - decoration: BoxDecoration( - color: Colors.white, - border: Border.all( - color: Colors.grey.shade300, - ), - borderRadius: BorderRadius.circular(24), - ), - margin: const EdgeInsets.symmetric( - vertical: 8, - horizontal: 8, - ), - child: TextField( - controller: _controller, - decoration: InputDecoration( - prefixIcon: StreamSvgIcon.search( - color: Colors.black, - size: 24, - ), - hintText: 'Search', - hintStyle: TextStyle( - color: Colors.black.withOpacity(0.5), - fontSize: 14, - ), - contentPadding: const EdgeInsets.all(0), - border: OutlineInputBorder( - borderSide: BorderSide.none, - borderRadius: BorderRadius.circular(24), - ), - ), - ), + child: SearchTextField( + controller: _controller, ), ), if (_selectedUsers.isNotEmpty) diff --git a/example/lib/search_text_field.dart b/example/lib/search_text_field.dart new file mode 100644 index 00000000..7fcd3727 --- /dev/null +++ b/example/lib/search_text_field.dart @@ -0,0 +1,81 @@ +import 'package:flutter/material.dart'; +import 'package:stream_chat_flutter/stream_chat_flutter.dart'; + +class SearchTextField extends StatelessWidget { + final TextEditingController controller; + final ValueChanged onChanged; + final String hintText; + final VoidCallback onTap; + + const SearchTextField({ + Key key, + @required this.controller, + this.onChanged, + this.onTap, + this.hintText = 'Search', + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + height: 36, + decoration: BoxDecoration( + color: Colors.white, + border: Border.all( + color: Colors.grey.shade300, + ), + borderRadius: BorderRadius.circular(24), + ), + margin: const EdgeInsets.symmetric( + vertical: 8, + horizontal: 8, + ), + child: Row( + children: [ + Expanded( + child: TextField( + onTap: onTap, + controller: controller, + onChanged: onChanged, + decoration: InputDecoration( + prefixIcon: StreamSvgIcon.search( + color: Colors.black, + size: 24, + ), + hintText: hintText, + hintStyle: TextStyle( + color: Colors.black.withOpacity(0.5), + fontSize: 14, + ), + contentPadding: const EdgeInsets.all(0), + border: OutlineInputBorder( + borderSide: BorderSide.none, + borderRadius: BorderRadius.circular(24), + ), + ), + ), + ), + // Material( + // + // child: IconButton( + // icon: StreamSvgIcon.close( + // color: Colors.grey, + // ), + // splashRadius: 24, + // onPressed: () { + // if (controller.text.isNotEmpty) { + // Future.microtask( + // () => [ + // controller.clear(), + // onChanged(''), + // ], + // ); + // } + // }, + // ), + // ), + ], + ), + ); + } +}