import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:tangheem/api/tangheem_user_api_client.dart'; import 'package:tangheem/classes/colors.dart'; import 'package:tangheem/classes/utils.dart'; import 'package:tangheem/models/aya_tangheem_type_mapped.dart'; import 'package:tangheem/models/surah_model.dart'; import 'package:tangheem/ui/misc/no_data_ui.dart'; import 'package:tangheem/ui/screens/tangheem_detail_screen.dart'; import 'package:tangheem/widgets/text_highlight_widget.dart'; class TangheemScreen extends StatefulWidget { static const String routeName = "/tangheem"; final String tangheemQuery; final String tangheemTypeName; final SurahModelData surah; TangheemScreen({Key key, this.surah, this.tangheemQuery, this.tangheemTypeName}) : super(key: key); @override _TangheemScreenState createState() { return _TangheemScreenState(); } } class _TangheemScreenState extends State { AyatTangheemTypeMapped _ayatTangheemTypeMapped; List _dataList; @override void initState() { super.initState(); getTangheemData(); } void getTangheemData() async { Utils.showLoading(context); try { _ayatTangheemTypeMapped = await TangheemUserApiClient().getAyaTangheemTypeMapped(widget.surah?.surahID, widget.tangheemTypeName, widget.tangheemQuery); _dataList = _ayatTangheemTypeMapped?.data ?? []; } catch (ex, tr) { _dataList = []; Utils.handleException(ex, null); } finally { Utils.hideLoading(context); } setState(() {}); } @override void dispose() { super.dispose(); } @override Widget build(BuildContext context) { return _dataList == null ? SizedBox() : _dataList.isEmpty ? NoDataUI() : ListView.separated( physics: BouncingScrollPhysics(), padding: EdgeInsets.all(16), itemCount: _dataList.length, separatorBuilder: (context, index) { return SizedBox(height: 8); }, itemBuilder: (context, index) { return InkWell( onTap: () { Navigator.pushNamed(context, TangheemDetailScreen.routeName, arguments: _dataList[index]); }, borderRadius: BorderRadius.circular(4), child: Container( padding: EdgeInsets.fromLTRB(12, 8, 12, 8), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(4), ), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ Row( mainAxisSize: MainAxisSize.min, children: [ Text( _dataList[index].surahNameAr + ":", style: TextStyle(fontSize: 12, color: ColorConsts.primaryBlue), ), Text( " ${_dataList[index].ayahNo}", style: TextStyle(fontSize: 14, color: ColorConsts.secondaryOrange), ), ], ), TextHighLightWidget( text: _dataList[index].ayahText, valueColor: ColorConsts.secondaryOrange, highlights: [_dataList[index].highlightText], textAlign: TextAlign.start, style: TextStyle( fontFamily: "UthmanicHafs", fontSize: 16, color: ColorConsts.primaryBlue, fontWeight: FontWeight.bold, ), ), ], ), ), ); }, ); } }