[dart] page search
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- import 'package:easy_localization/easy_localization.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:provider/provider.dart';
- import 'package:thawaf/common/extensions/buildcontext_extension.dart';
- import 'package:thawaf/common/providers/app_setting.dart';
- import 'package:thawaf/common/providers/user_behavior.dart';
- import 'package:thawaf/common/utils/datetime_utils.dart';
- import 'package:thawaf/common/utils/global_function_utils.dart';
- import 'package:thawaf/common/utils/global_variable_utils.dart';
- import 'package:thawaf/resources/data_state/data_item_model.dart';
- import 'package:thawaf/resources/models/user_model.dart';
- import 'package:thawaf/screens/home/tabs/home/providers/features_provider.dart';
- import 'package:thawaf/screens/home/tabs/home/providers/news_provider.dart';
- import 'package:thawaf/screens/home/tabs/home/home_screen.dart';
- import 'package:thawaf/screens/home/tabs/home/providers/home_screen_provider.dart';
- import 'package:thawaf/screens/home/tabs/home/providers/panduan_state_provider.dart';
- import 'package:thawaf/screens/home/tabs/home/resources/model/features_model.dart';
- import 'package:thawaf/screens/home/tabs/home/widgets/home_features_widget.dart';
- import 'package:thawaf/screens/home/tabs/home/widgets/home_widgets.dart';
- import 'package:thawaf/screens/news/news_detail.dart';
- import 'package:thawaf/screens/news/resources/models/news_model.dart';
- import 'package:thawaf/screens/panduan/detail_panduan.dart';
- import 'package:thawaf/screens/panduan/resources/models/panduan_umrah_model.dart';
- import 'package:thawaf/widgets/app_widget/app_widget.dart';
- import 'package:thawaf/widgets/image_widget/image_network_widget.dart';
- class HomeSearch extends StatefulWidget {
- final UserModel userModel;
- HomeSearch({Key? key, required this.userModel}) : super(key: key);
- @override
- State<HomeSearch> createState() => _HomeSearchState();
- }
- class _HomeSearchState extends State<HomeSearch> {
- bool isLoading = false;
- List<DataItem> featureData = [];
- List<DataItem> newsData = [];
- List<DataItem> panduanData = [];
- final FocusNode _focusNode = FocusNode();
- final TextEditingController _searchController = TextEditingController();
- @override
- void initState() {
- super.initState();
- }
- @override
- void dispose() {
- _focusNode.dispose();
- _searchController.dispose();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- UserModel userModel = Provider.of<UserModel>(context);
- FeatureProvider fP = Provider.of<FeatureProvider>(context);
- NewsProvider nP = Provider.of<NewsProvider>(context);
- PanduanStateProvider pP = Provider.of<PanduanStateProvider>(context);
- if ((!fP.isInit || fP.isLoading) ||
- (!nP.isInit || nP.isLoading) ||
- (!pP.isInit || pP.isLoading)) {
- return Scaffold(
- body: Center(
- child: AppWidget.loadingData(),
- ),
- );
- }
- void _onSearch() async {
- isLoading = true;
- setState(() {});
- try {
- featureData = await fP.dataStateFeature.find(
- search: SearchDataState(
- keys: ['featureIdName', 'featureEnName'],
- value: _searchController.text,
- ),
- );
- newsData = await nP.dataStateNews.find(
- search:
- SearchDataState(keys: ['title'], value: _searchController.text),
- );
- panduanData = await pP.dataStatePanduan.find(
- search:
- SearchDataState(keys: ['title'], value: _searchController.text),
- );
- } catch (e) {
- print('Search error: $e');
- }
- isLoading = false;
- setState(() {});
- }
- return GestureDetector(
- onTap: () {
- context.requestFocus();
- },
- child: Scaffold(
- appBar: AppBar(
- toolbarHeight: 80,
- leading: IconButton(
- icon: Icon(Icons.arrow_back, color: Colors.black),
- onPressed: () => Navigator.of(context).pop(),
- ),
- title: Container(
- height: 50,
- padding: const EdgeInsets.symmetric(horizontal: 15),
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.circular(10),
- border: Border.all(width: 1, color: Color(0xFF9E9E9E)),
- ),
- child: Row(
- children: [
- Icon(Icons.search, color: Color(0xFF9E9E9E)),
- SizedBox(width: 10),
- Expanded(
- child: TextField(
- controller: _searchController,
- focusNode: _focusNode,
- autofocus: true,
- onChanged: (_) {
- _onSearch();
- },
- decoration: InputDecoration(
- hintText: 'home.search'.tr(),
- border: InputBorder.none,
- hintStyle: TextStyle(
- color: Color(0xFF9E9E9E),
- fontSize: 14,
- fontFamily: 'Lato',
- fontWeight: FontWeight.w500,
- letterSpacing: 0.07,
- ),
- ),
- onSubmitted: (value) => _onSearch(), // Update here
- ),
- ),
- ],
- ),
- ),
- backgroundColor: Colors.transparent,
- elevation: 0,
- centerTitle: false,
- ),
- body: NotificationListener<OverscrollIndicatorNotification>(
- onNotification: (overscroll) {
- overscroll.disallowIndicator();
- return true;
- },
- child: SizedBox(
- width: context.width(),
- height: context.height(),
- child: Builder(
- builder: (_) {
- // mode search
- if (_searchController.text.isNotEmpty) {
- if (featureData.isEmpty &&
- newsData.isEmpty &&
- panduanData.isEmpty) {
- return Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- Text('home.no_search_data'.tr()),
- ],
- );
- }
- return NotificationListener<OverscrollIndicatorNotification>(
- onNotification: (overscroll) {
- overscroll.disallowIndicator();
- return true;
- },
- child: SingleChildScrollView(
- physics: ClampingScrollPhysics(),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- children: [
- if (featureData.isNotEmpty)
- Column(
- children: [
- dividerMenu(
- title: 'home.feature'.tr(),
- withLine: false,
- ),
- Padding(
- padding: const EdgeInsets.only(
- left: 10, right: 10),
- child: SizedBox(
- width: context.width(),
- child: SingleChildScrollView(
- scrollDirection: Axis.horizontal,
- child: Row(
- mainAxisAlignment:
- MainAxisAlignment.start,
- crossAxisAlignment:
- CrossAxisAlignment.start,
- children: featureData.map((e) {
- FeaturesModel feature =
- FeaturesModel.fromDataItem(e);
- return Padding(
- padding: EdgeInsets.only(
- right: 8.0, bottom: 10.0),
- child: GestureDetector(
- onTap: () {
- if (feature.route ==
- 'panicButton') {
- HomeWidgets
- .panicButtonActionSheet(
- pageContext: context,
- userData: userModel,
- );
- // User Behavior - function clicked features
- Provider.of<UserBehavior>(
- context,
- listen: false)
- .clickedFeature(
- docId: userModel.docUid,
- identifier: 'Tersesat',
- );
- } else {
- AppFunction.pushNamed(
- context: context,
- route: feature.route,
- arguments:
- feature.withGetUserData,
- );
- // User Behavior - function clicked features
- Provider.of<UserBehavior>(
- context,
- listen: false)
- .clickedFeature(
- docId: userModel.docUid,
- identifier:
- feature.identifier,
- );
- }
- },
- child: Column(
- mainAxisAlignment:
- MainAxisAlignment.start,
- crossAxisAlignment:
- CrossAxisAlignment.center,
- mainAxisSize: MainAxisSize.min,
- children: [
- Container(
- width: 65.w,
- height: 60.h,
- decoration: BoxDecoration(
- borderRadius:
- BorderRadius
- .circular(10)),
- child: ClipRRect(
- borderRadius:
- BorderRadius.circular(
- 10),
- child: Image.asset(
- feature.iconPath,
- fit: BoxFit.cover,
- ),
- ), // Use iconPath from feature
- ),
- SizedBox(height: 3.h),
- Consumer<AppSettings>(builder:
- (_,
- AppSettings
- appSettings,
- __) {
- return Container(
- width: 70.w,
- child: Text(
- appSettings.isIndonesianLanguage
- ? feature
- .featureIdName
- : feature
- .featureEnName,
- overflow:
- TextOverflow.clip,
- textAlign:
- TextAlign.center,
- style: TextStyle(
- color: ThawafMisc
- .appTheme
- .smokyBlackColor,
- fontFamily: 'Lato',
- fontSize: 12.sp,
- ),
- ),
- );
- }),
- ],
- ),
- ),
- );
- }).toList(),
- ),
- ),
- ),
- ),
- SizedBox(
- height: 14,
- ),
- ],
- ),
- if (newsData.isNotEmpty)
- Column(
- children: [
- dividerMenu(
- title: 'home.news'.tr(),
- withLine: false,
- ),
- Padding(
- padding: const EdgeInsets.only(
- left: 10, right: 10, bottom: 30),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- children: newsData.map((e) {
- NewsModel news =
- NewsModel.formDataItem(e);
- return Padding(
- padding:
- const EdgeInsets.only(bottom: 10),
- child: GestureDetector(
- onTap: () {
- AppFunction.push(
- context: context,
- page: NewsDetail(docs: news),
- withGetUserData: false,
- );
- },
- child: Container(
- width: MediaQuery.of(context)
- .size
- .width,
- height: 120,
- decoration: ShapeDecoration(
- color: Colors.white,
- shape: RoundedRectangleBorder(
- borderRadius:
- BorderRadius.circular(10),
- ),
- shadows: [AppTheme().shadow1],
- ),
- child: Padding(
- padding: const EdgeInsets.all(10),
- child: Row(
- crossAxisAlignment:
- CrossAxisAlignment.start,
- mainAxisAlignment:
- MainAxisAlignment.start,
- children: [
- Container(
- height: 85.h,
- width: 85.w,
- child: ClipRRect(
- borderRadius:
- BorderRadius.circular(
- 5.r),
- child: ImageNetworkWidget(
- news.cover.toString(),
- progressIndicatorBuilder:
- (_, __, ___) {
- return Image.asset(
- "assets/icons/icon_placeholder_news.png");
- },
- fit: BoxFit.cover,
- ),
- ),
- ),
- SizedBox(
- width: 10,
- ),
- Expanded(
- child: Column(
- crossAxisAlignment:
- CrossAxisAlignment
- .start,
- mainAxisAlignment:
- MainAxisAlignment
- .center,
- children: [
- Text(
- DateTimeUtils
- .dateFormat(news
- .createdAt),
- overflow: TextOverflow
- .ellipsis,
- style: TextStyle(
- fontSize: 10,
- fontFamily: 'Lato',
- fontWeight:
- FontWeight.w500,
- color: AppTheme()
- .greyDisableColor,
- ),
- ),
- SizedBox(
- height: 6,
- ),
- Text(
- news.title,
- maxLines: 3,
- overflow: TextOverflow
- .ellipsis,
- style: TextStyle(
- fontSize: 16.sp,
- fontFamily: 'Lato',
- fontWeight:
- FontWeight.w500,
- ),
- ),
- ],
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- );
- }).toList(),
- ),
- )
- ],
- ),
- if (panduanData.isNotEmpty)
- Column(
- children: [
- dividerMenu(
- title: 'home.guide_text'.tr(),
- withLine: false,
- ),
- Padding(
- padding: const EdgeInsets.only(
- left: 10, right: 10, bottom: 30),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- children: panduanData.map((e) {
- PanduanModel panduan =
- PanduanModel.fromDataItem(e);
- return Padding(
- padding:
- const EdgeInsets.only(bottom: 10),
- child: GestureDetector(
- onTap: () {
- AppFunction.push(
- context: context,
- page: DetailPanduanScreen(
- data: panduan,
- pageTitle:
- 'home.hajj_guide'.tr(),
- ),
- withGetUserData: false,
- );
- },
- child: Container(
- width: MediaQuery.of(context)
- .size
- .width,
- height: 120,
- decoration: ShapeDecoration(
- color: Colors.white,
- shape: RoundedRectangleBorder(
- borderRadius:
- BorderRadius.circular(10),
- ),
- shadows: [AppTheme().shadow1],
- ),
- child: Padding(
- padding: const EdgeInsets.all(10),
- child: Row(
- crossAxisAlignment:
- CrossAxisAlignment.start,
- mainAxisAlignment:
- MainAxisAlignment.start,
- children: [
- Container(
- height: 85.h,
- width: 85.w,
- child: ClipRRect(
- borderRadius:
- BorderRadius.circular(
- 5.r),
- child: ImageNetworkWidget(
- panduan.cover
- .toString(),
- progressIndicatorBuilder:
- (_, __, ___) {
- return Image.asset(
- "assets/icons/icon_placeholder_news.png");
- },
- fit: BoxFit.cover,
- ),
- ),
- ),
- SizedBox(
- width: 10,
- ),
- Expanded(
- child: Column(
- crossAxisAlignment:
- CrossAxisAlignment
- .start,
- mainAxisAlignment:
- MainAxisAlignment
- .center,
- children: [
- Text(
- DateTimeUtils
- .dateFormat(panduan
- .createdAt),
- overflow: TextOverflow
- .ellipsis,
- style: TextStyle(
- fontSize: 10,
- fontFamily: 'Lato',
- fontWeight:
- FontWeight.w500,
- color: AppTheme()
- .greyDisableColor,
- ),
- ),
- SizedBox(
- height: 6,
- ),
- Text(
- panduan.title,
- maxLines: 3,
- overflow: TextOverflow
- .ellipsis,
- style: TextStyle(
- fontSize: 16.sp,
- fontFamily: 'Lato',
- fontWeight:
- FontWeight.w500,
- ),
- ),
- ],
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- );
- }).toList(),
- ),
- )
- ],
- ),
- ],
- ),
- ),
- );
- }
- return NotificationListener<OverscrollIndicatorNotification>(
- onNotification: (overscroll) {
- overscroll.disallowIndicator();
- return true;
- },
- child: SingleChildScrollView(
- physics: ClampingScrollPhysics(),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- children: [
- dividerMenu(
- title: 'home.feature'.tr(),
- withLine: false,
- ),
- if (_searchController.text.isEmpty)
- Padding(
- padding: EdgeInsets.only(left: 10, right: 10),
- child: Consumer<HomeScreenProvider>(
- builder:
- (_, HomeScreenProvider homeProvider, __) {
- return ConstrainedBox(
- key: homeProvider.featureListTutorialKey,
- constraints: BoxConstraints(
- minHeight: 80.h,
- maxHeight: 100.h,
- ),
- child: HomeFeaturesWidget(
- userModel: widget.userModel,
- maxItems: 4,
- showLainnya: false,
- ),
- );
- },
- ),
- ),
- SizedBox(
- height: 14,
- ),
- dividerMenu(
- title: 'home.news'.tr(),
- withLine: false,
- ),
- if (_searchController.text.isEmpty)
- Consumer<HomeScreenProvider>(
- builder: (_, HomeScreenProvider homeProvider, __) {
- return Container(
- padding: EdgeInsets.only(left: 10, right: 10),
- child: HomeFeaturesWidget.newsSliderWidget(
- context),
- );
- },
- ),
- dividerMenu(
- title: 'home.guide_text'.tr(),
- withLine: false,
- ),
- if (_searchController.text.isEmpty)
- Consumer<HomeScreenProvider>(
- builder: (_, HomeScreenProvider homeProvider, __) {
- return Container(
- padding: EdgeInsets.only(left: 10, right: 10),
- child: HomeFeaturesWidget.newsSliderWidget(
- context),
- );
- },
- ),
- ],
- ),
- ),
- );
- },
- ),
- ),
- ),
- ),
- );
- }
- }
Editor
You can edit this paste and save as new: