import 'package:http/http.dart' as http;
import 'Hadiths.dart';
// ignore: must_be_immutable
class HadithChapters extends StatefulWidget {
var bookSlug;
HadithChapters(this.bookSlug, {super.key});
@override
State createState() => _HadithChaptersState();
}
class _HadithChaptersState extends State {
late Map rawdatamap = {};
late List datalist = [];
void getapi() async {
var slug = widget.bookSlug;
var apiKey =
"\$2y\$10\$BylaBcXs5Lw7ZOtYmQ3PXO1x15zpp26oc1FeGktdmF6YeYoRd88e";
var res = await http.get(
Uri.parse("https://hadithapi.com/api/$slug/chapters?apiKey=$apiKey"));
class Home extends StatefulWidget {
const Home({super.key});
@override
State createState() => _HomeState();
}
class _HomeState extends State {
void hadith() {
// Get available collections
// print(getCollections());
// Get a single collection
// print(getCollection(Collections.bukhari));
// // Get collection data
// print(getCollectionData(Collections.bukhari, Languages.en));
//Get books of a collection
// print(getBooks(Collections.bukhari));
// Get a single book
// print(getBook(Collections.bukhari, 1));
// // Get book data
// print(getBookData(Collections.bukhari, 1, Languages.en));
// // Get hadiths of a book
// print(getHadiths(Collections.bukhari, 1));
// // Get a single hadith
// print(getHadith(Collections.bukhari, 1, 1));
// Get hadith data
// print(getHadithData(Collections.bukhari, 1, 1, Languages.en));
// // Get hadith data by hadith number
// print(getHadithDataByNumber(Collections.bukhari, '1', Languages.en));
// print(getHadithDataByNumber(Collections.muslim, '36 b', Languages.en));
// // Get collection URL
// print(getCollectionURL(Collections.bukhari));
// // Get book URL
// print(getBookURL(Collections.bukhari, 1));
import 'package:http/http.dart' as http;
import 'package:custom_radio_grouped_button/custom_radio_grouped_button.dart';
class SearchHadith extends StatefulWidget {
const SearchHadith({super.key});
@override
State createState() => _SearchHadithState();
}
class _SearchHadithState extends State {
late Map rawdatamap = {};
late List datalist = [];
late String searchInput = "";
late String selectlang = "";
bool isLoading = false;
Code :-
1.) (Hadith books) import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:flutter/material.dart'; import 'HadithChapters.dart';
class HadithBooks extends StatefulWidget { const HadithBooks({super.key});
@override State createState() => _HadithBooksState();
}
class _HadithBooksState extends State {
late Map rawdatamap = {};
late List datalist = [];
void getapi() async { var apiKey = "\$2y\$10\$BylaBcXs5Lw7ZOtYmQ3PXO1x15zpp26oc1FeGktdmF6YeYoRd88e"; var res = await http .get(Uri.parse("https://hadithapi.com/api/books?apiKey=$apiKey")); // print("SMASB" + res.body);
}
@override void initState() { // TODO: implement initState super.initState();
}
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text( "Hadith Books Collection", style: TextStyle(color: Color(0XFFF2F2F2)), ), centerTitle: true, backgroundColor: Color(0XFF0D0D0D), ), body: datalist.isEmpty ? Center( child: CircularProgressIndicator(), ) : ListView.builder( itemBuilder: (context, index) { return Padding( padding: const EdgeInsets.all(16.0), child: ListTile( onTap: () { var bookSlug = datalist[index]["bookSlug"];
} }
2.) Hadith chapters import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'Hadiths.dart';
// ignore: must_be_immutable class HadithChapters extends StatefulWidget { var bookSlug; HadithChapters(this.bookSlug, {super.key});
@override State createState() => _HadithChaptersState();
}
class _HadithChaptersState extends State {
late Map rawdatamap = {};
late List datalist = [];
void getapi() async {
var slug = widget.bookSlug;
var apiKey =
"\$2y\$10\$BylaBcXs5Lw7ZOtYmQ3PXO1x15zpp26oc1FeGktdmF6YeYoRd88e";
var res = await http.get(
Uri.parse("https://hadithapi.com/api/$slug/chapters?apiKey=$apiKey"));
// print("SMASB" + res.body);
}
@override void initState() { // TODO: implement initState super.initState();
}
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text( "Hadith Books Chapters", style: TextStyle(color: Color(0XFFF2F2F2)), ), centerTitle: true, backgroundColor: Color(0XFF0D0D0D), ), body: datalist.isEmpty ? Center( child: CircularProgressIndicator(), ) : ListView.builder( itemBuilder: (context, index) { return Padding( padding: const EdgeInsets.all(8.0), child: ListTile( onTap: () { var bookSlug = datalist[index]["bookSlug"]; var chapterNumber = datalist[index]["chapterNumber"];
} }
3.) Hadith Packages import 'package:flutter/material.dart';
import 'package:hadith/hadith.dart';
class Home extends StatefulWidget { const Home({super.key});
@override State createState() => _HomeState();
}
class _HomeState extends State {
void hadith() {
// Get available collections
// print(getCollections());
}
List datalist = Collections.values;
@override void initState() { // TODO: implement initState super.initState(); hadith(); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Hadith Collections "), centerTitle: true, ), backgroundColor: Colors.indigo[900], body: ListView.builder( itemBuilder: (context, index) { return ListTile( onTap: () { var name = datalist[index]; Navigator.push( context, MaterialPageRoute( builder: (context) => BOHadith(name), ));
} }
class BOHadith extends StatefulWidget { final nameofcollection; BOHadith(this.nameofcollection, {super.key});
@override State createState() => _BOHadithState();
}
class _BOHadithState extends State {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Books of Hadiths "),
centerTitle: true,
),
body: ListView.builder(
itemBuilder: (context, index) {
return ListTile(
onTap: () {},
leading: Text("${index + 1}"),
title: Text(
getBooks(widget.nameofcollection)[index].book[1].name.toString(),
style: TextStyle(fontFamily: "alq", fontSize: 20),
),
subtitle: Text(getBooks(widget.nameofcollection)[index]
.book[0]
.name
.toString()),
trailing: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text("Hadiths" +
getBooks(widget.nameofcollection)[index]
.hadithStartNumber
.toString() +
" To " +
getBooks(widget.nameofcollection)[index]
.hadithEndNumber
.toString()),
Text("Total Hadiths :" +
getBooks(widget.nameofcollection)[index]
.numberOfHadith
.toString()),
],
),
);
},
itemCount: getBooks(widget.nameofcollection).length,
),
);
}
}
4.) Hadiths import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
// ignore: must_be_immutable class Hadiths extends StatefulWidget { var slug; var number; Hadiths(this.slug, this.number, {super.key});
@override State createState() => _HadithsState();
}
class _HadithsState extends State {
late Map rawdatamap = {};
late List datalist = [];
void getapi() async {
var bookslug = widget.slug;
var number = widget.number;
var apiKey =
"\$2y\$10\$BylaBcXs5Lw7ZOtYmQ3PXO1x15zpp26oc1FeGktdmF6YeYoRd88e";
var res = await http.get(Uri.parse(
"https://hadithapi.com/public/api/hadiths?apiKey=$apiKey&book=$bookslug&chapter=$number&paginate=100000"));
}
@override void initState() { // TODO: implement initState super.initState(); getapi(); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text( "Hadith Books Collection", style: TextStyle(color:Color(0XFFF2F2F2),), ), centerTitle: true, backgroundColor: Color(0XFF595959), ), body: datalist.isEmpty ? Center( child: CircularProgressIndicator(), ) : ListView.builder( itemBuilder: (context, index) { return Card( color: Color(0XFFD9D9D9), child: Column( children: [ ListTile( title: Text("Hadith Number #" + datalist[index]["hadithNumber"].toString()), trailing: Text("Status :" + datalist[index]["status"].toString())), Card( color: Color(0XFFF2F2F2), child: Container( width: double.infinity, child: Padding( padding: const EdgeInsets.all(16.0), child: Text( datalist[index]["hadithArabic"].toString(), style: const TextStyle( fontFamily: "alq", fontSize: 20, color: Color.fromARGB(255, 0, 77, 64) ), textAlign: TextAlign.justify, textDirection: TextDirection.rtl, ), ), ), ), Card( color: Color(0XFFF2F2F2), child: Container( width: double.infinity, child: Padding( padding: const EdgeInsets.all(16.0), child: Text( datalist[index]["hadithUrdu"].toString(), style: const TextStyle( fontFamily: "jameel", fontSize: 20, ), textAlign: TextAlign.justify, textDirection: TextDirection.rtl, ), ), ), ), Card( color: Color(0XFFF2F2F2), child: Container( width: double.infinity, child: Padding( padding: const EdgeInsets.all(16.0), child: Text( datalist[index]["hadithEnglish"].toString(), style: const TextStyle( fontFamily: "alq", fontSize: 20, ), textAlign: TextAlign.justify, textDirection: TextDirection.ltr, ), ), ), ), ], ), ); }, itemCount: datalist.length, ), );
} }
5.) Main import 'package:flutter/material.dart'; import 'SplashScreen.dart';
void main() { runApp(const MyApp()); }
class MyApp extends StatelessWidget { const MyApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Color(0XFF404040)), useMaterial3: true, ), home: const SplashScreen(), ); } }
6.) Search Hadith import 'dart:convert'; import 'dart:math';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'package:custom_radio_grouped_button/custom_radio_grouped_button.dart';
class SearchHadith extends StatefulWidget { const SearchHadith({super.key});
@override State createState() => _SearchHadithState();
}
class _SearchHadithState extends State {
late Map rawdatamap = {};
late List datalist = [];
late String searchInput = "";
late String selectlang = "";
bool isLoading = false;
void getapi(String value) async { setState(() { isLoading = true; });
}
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text( "Search In All Hadith Books ", style: TextStyle( color: Color(0XFFF2F2F2), ), ), centerTitle: true, backgroundColor: Color(0XFF595959), ), body: Column( children: [ Padding( padding: const EdgeInsets.all(16.0), child: Text( "سرچ کے لیے مندرجہ ذیل آپشن کو پہلے منتخب کیجیے", style: const TextStyle( fontFamily: "jameel", fontSize: 20, ), textAlign: TextAlign.justify, textDirection: TextDirection.rtl, )), CustomRadioButton( absoluteZeroSpacing: true, elevation: 0, unSelectedBorderColor: Color(0XFFD9D9D9), enableShape: true, selectedBorderColor: Color(0XFF0D0D0D), selectedColor: Color(0XFF0D0D0D), unSelectedColor: Color(0XFFD9D9D9), buttonLables: ['Arabic', 'Urdu', 'English', 'Hadith No'], buttonValues: ['Arabic', 'Urdu', 'English', 'Hadith No'], buttonTextStyle: const ButtonTextStyle( selectedColor: Colors.white, unSelectedColor: Colors.black, textStyle: TextStyle(fontSize: 16)), radioButtonValue: (value) { setState(() { selectlang = value; }); }, ), Padding( padding: const EdgeInsets.all(8.0), child: TextField( decoration: selectlang == 'Urdu' || selectlang == 'Arabic' ? InputDecoration( hintText: " ..... تلاش کریں ", suffixIcon: Icon(Icons.search_rounded)) : InputDecoration( hintText: "Search Here..... ", prefixIcon: Icon(Icons.search_rounded)), onChanged: (value) { searchInput = value; print("search value smas=>" + searchInput); }, style: selectlang == 'Urdu' || selectlang == 'Arabic' ? TextStyle(fontFamily: "jameel") : TextStyle(fontFamily: "alq"), textAlign: selectlang == 'Urdu' || selectlang == 'Arabic' ? TextAlign.right : TextAlign.left, textDirection: selectlang == 'Urdu' || selectlang == 'Arabic' ? TextDirection.rtl : TextDirection.ltr, ), ), ElevatedButton( onPressed: () { getapi(selectlang); }, child: Text("Search")), SizedBox( height: 10, ), Expanded( child: isLoading ? const Center( child: CircularProgressIndicator(), ) : ListView.builder( itemBuilder: (context, index) { String hadithdata = '';
} }
7.) Splash Screen import 'dart:async';
import 'package:flutter/material.dart'; import 'TabsScr.dart';
class SplashScreen extends StatefulWidget { const SplashScreen({super.key});
@override State createState() => _SplashScreenState();
}
class _SplashScreenState extends State {
void initState() {
// TODO: implement initState
super.initState();
}
@override Widget build(BuildContext context) { return Scaffold( body: Center( child: Container( width: double.infinity, height: double.infinity, decoration: const BoxDecoration( color: Color(0XFF262626), ), child:Image.asset("assets/hadith.jpg",width: double.infinity,height:double.infinity ,) ), ), backgroundColor: Color(0XFFD9D9D9)); } } 8.) TabScr import 'package:flutter/material.dart'; import 'HadithBooks.dart'; import 'SearchHadith.dart';
class TabsScr extends StatefulWidget { const TabsScr({super.key});
@override State createState() => _TabsScrState();
}
class _TabsScrState extends State {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: Text(
" احادیث نبویﷺ",
style: TextStyle(fontFamily: "alq",),
textDirection: TextDirection.rtl,
textAlign: TextAlign.justify,
),
centerTitle: true,
bottom: TabBar(
labelColor: Color(0XFF404040),
unselectedLabelColor: Colors.grey,
indicatorColor: Color(0XFF0D0D0D),
tabs: [
Tab(
text: "Hadith Books",
),
Tab(
text: "Search Hadiths",
),
],
),
),
body: TabBarView(children: [
HadithBooks(),
SearchHadith(),
])),
);
}
}