From 5790adf6d2e5fd76c7aa06b2f9fea0e2b7d2ab2c Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Wed, 7 Apr 2021 14:50:53 +0300 Subject: [PATCH] Enable search ui and search parameter added. --- lib/api/tangheem_user_api_client.dart | 13 +++- lib/main.dart | 1 + lib/ui/screens/home_screen.dart | 92 +++++++++++++-------------- lib/ui/screens/tangheem_screen.dart | 10 +-- 4 files changed, 63 insertions(+), 53 deletions(-) diff --git a/lib/api/tangheem_user_api_client.dart b/lib/api/tangheem_user_api_client.dart index 056d287..05a0bcd 100644 --- a/lib/api/tangheem_user_api_client.dart +++ b/lib/api/tangheem_user_api_client.dart @@ -53,9 +53,18 @@ class TangheemUserApiClient { return await ApiClient().postJsonForObject((json) => TangheemType.fromJson(json), url, postParams); } - Future getAyaTangheemTypeMapped(int surahNo, String tangheemTypeName) async { + Future getAyaTangheemTypeMapped(int surahNo, String tangheemTypeName, String ayaText) async { String url = "${ApiConsts.tangheemUsers}AyatTangheemTypeMapped_Get"; - var postParams = {"surahNo": surahNo, "tangheemTypeName": tangheemTypeName}; + var postParams = {}; + if (surahNo != null) { + postParams["surahNo"] = surahNo; + } + if (tangheemTypeName != null) { + postParams["tangheemTypeName"] = tangheemTypeName; + } + if (ayaText != null) { + postParams["ayaText"] = ayaText; + } return await ApiClient().postJsonForObject((json) => AyatTangheemTypeMapped.fromJson(json), url, postParams); } diff --git a/lib/main.dart b/lib/main.dart index 6f7d0d9..7fda270 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -49,6 +49,7 @@ class Application extends StatelessWidget { child: TangheemScreen( surah: data["surahData"], tangheemTypeName: data["tangheemTypeName"], + tangheemQuery: data["tangheemQuery"], ), ); break; diff --git a/lib/ui/screens/home_screen.dart b/lib/ui/screens/home_screen.dart index 30b6f29..8fb6567 100644 --- a/lib/ui/screens/home_screen.dart +++ b/lib/ui/screens/home_screen.dart @@ -157,56 +157,56 @@ class _HomeScreenState extends State { ), ), SizedBox(height: 16), - - // todo "Sikander" : hide this search ui, later when we have search requirement, then visible this ui. - Visibility( - visible: false, - child: Container( - height: 50, - padding: EdgeInsets.only(top: 4, bottom: 6), - child: TextField( - controller: _searchController, - focusNode: _searchFocusNode, - style: TextStyle(color: ColorConsts.primaryBlack, fontSize: 14), - decoration: InputDecoration( - contentPadding: EdgeInsets.fromLTRB(4, 4, 4, 4), - alignLabelWithHint: true, - fillColor: Colors.white, - filled: true, - hintStyle: TextStyle(color: ColorConsts.textHintGrey, fontSize: 12), - hintText: "البحث عن سورة أو آية", - prefixIconConstraints: BoxConstraints(maxHeight: 16), - prefixIcon: Padding( - padding: EdgeInsets.only(right: 6), - child: SvgPicture.asset("assets/icons/search.svg"), - ), - suffixIcon: InkWell( - onTap: () async { - _searchFocusNode.unfocus(); - _searchFocusNode.canRequestFocus = false; - await Navigator.pushNamed(context, QuranScreen.routeName, arguments: _searchController.text); - _searchFocusNode.canRequestFocus = true; - }, - splashColor: Colors.transparent, - highlightColor: Colors.transparent, - child: Container( - alignment: Alignment.center, - width: 80, - child: Text( - "بحث", - style: TextStyle(fontSize: 14, color: Colors.white), - ), - decoration: BoxDecoration( - color: ColorConsts.secondaryPink, - borderRadius: BorderRadius.only( - bottomLeft: Radius.circular(6), - topLeft: Radius.circular(6), - ), + Container( + height: 50, + padding: EdgeInsets.only(top: 4, bottom: 6), + child: TextField( + controller: _searchController, + focusNode: _searchFocusNode, + style: TextStyle(color: ColorConsts.primaryBlack, fontSize: 14), + decoration: InputDecoration( + contentPadding: EdgeInsets.fromLTRB(4, 4, 4, 4), + alignLabelWithHint: true, + fillColor: Colors.white, + filled: true, + hintStyle: TextStyle(color: ColorConsts.textHintGrey, fontSize: 12), + hintText: "البحث عن سورة أو آية", + prefixIconConstraints: BoxConstraints(maxHeight: 16), + prefixIcon: Padding( + padding: EdgeInsets.only(right: 6), + child: SvgPicture.asset("assets/icons/search.svg"), + ), + suffixIcon: InkWell( + onTap: () async { + _searchFocusNode.unfocus(); + if (_searchController.text.length < 1) { + Utils.showToast("يجب إدخال بعض الكلمات للبحث"); + return; + } + _searchFocusNode.canRequestFocus = false; + var data = {"tangheemQuery": _searchController.text}; + await Navigator.pushNamed(context, TangheemScreen.routeName, arguments: data); + _searchFocusNode.canRequestFocus = true; + }, + splashColor: Colors.transparent, + highlightColor: Colors.transparent, + child: Container( + alignment: Alignment.center, + width: 80, + child: Text( + "بحث", + style: TextStyle(fontSize: 14, color: Colors.white), + ), + decoration: BoxDecoration( + color: ColorConsts.secondaryPink, + borderRadius: BorderRadius.only( + bottomLeft: Radius.circular(6), + topLeft: Radius.circular(6), ), ), ), - border: OutlineInputBorder(borderRadius: BorderRadius.circular(6), borderSide: BorderSide.none), ), + border: OutlineInputBorder(borderRadius: BorderRadius.circular(6), borderSide: BorderSide.none), ), ), ) diff --git a/lib/ui/screens/tangheem_screen.dart b/lib/ui/screens/tangheem_screen.dart index 2700ca8..35de193 100644 --- a/lib/ui/screens/tangheem_screen.dart +++ b/lib/ui/screens/tangheem_screen.dart @@ -11,9 +11,10 @@ import 'package:tangheem/widgets/text_highlight_widget.dart'; class TangheemScreen extends StatefulWidget { static const String routeName = "/tangheem"; - final tangheemTypeName; + final String tangheemQuery; + final String tangheemTypeName; final SurahModelData surah; - TangheemScreen({Key key, this.surah, this.tangheemTypeName}) : super(key: key); + TangheemScreen({Key key, this.surah, this.tangheemQuery, this.tangheemTypeName}) : super(key: key); @override _TangheemScreenState createState() { @@ -23,6 +24,7 @@ class TangheemScreen extends StatefulWidget { class _TangheemScreenState extends State { AyatTangheemTypeMapped _ayatTangheemTypeMapped; + List _dataList; @override void initState() { @@ -33,7 +35,7 @@ class _TangheemScreenState extends State { void getTangheemData() async { Utils.showLoading(context); try { - _ayatTangheemTypeMapped = await TangheemUserApiClient().getAyaTangheemTypeMapped(widget.surah.surahID, widget.tangheemTypeName); + _ayatTangheemTypeMapped = await TangheemUserApiClient().getAyaTangheemTypeMapped(widget.surah?.surahID, widget.tangheemTypeName, widget.tangheemQuery); _dataList = _ayatTangheemTypeMapped?.data ?? []; } catch (ex, tr) { _dataList = []; @@ -49,8 +51,6 @@ class _TangheemScreenState extends State { super.dispose(); } - List _dataList; - @override Widget build(BuildContext context) { return _dataList == null