BaapJaan

Test Islamicaskbd

Jun 19th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 10.08 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_wordpress/flutter_wordpress.dart' as wp;
  3. import 'package:url_launcher/url_launcher.dart';
  4. import 'package:flutter_html/flutter_html.dart';
  5.  
  6. class Home extends StatelessWidget {
  7.  
  8.   wp.WordPress WordPress =  wp.WordPress(
  9.     baseUrl: 'https://islamicaskbd.com/'
  10.   );
  11.  
  12.   fetchPosts(){
  13.     Future <List<wp.Post>> posts = WordPress.fetchPosts(postParams: wp.ParamsPostList(
  14.     context: wp.WordPressContext.view,
  15.       pageNum: 1,
  16.       perPage: 10,
  17.     ),
  18.       fetchAuthor: true,
  19.       fetchCategories: true,
  20.       fetchFeaturedMedia: true,
  21.     );
  22.     return posts;
  23.   }
  24.  
  25.   getPostImage(wp.Post post){
  26.     if(post.featuredMedia == null){
  27.       return SizedBox();
  28.     }
  29.     return Image.network(post.featuredMedia.sourceUrl);
  30.   }
  31.  
  32.  
  33.   lunchUrl(String link) async{
  34.     if(await canLaunch(link)){
  35.       await launch(link);
  36.     }else{
  37.       throw 'can\'t find anything, Can you please turn on Data';
  38.     }
  39.   }
  40.  
  41.  
  42.  
  43.   @override
  44.   Widget build(BuildContext context) {
  45.     return Scaffold(
  46.       appBar: AppBar(
  47.         title: Image.asset('images/logo.png'),
  48.         backgroundColor: Color(0xFFf6f8fc),
  49.         elevation: 0.0,
  50.         centerTitle: true,
  51.       ),
  52.       backgroundColor: Color(0xFFf6f8fc),
  53.       body: Container(
  54.         child: FutureBuilder(
  55.           future: fetchPosts(),
  56.             builder: (BuildContext context , AsyncSnapshot<List<wp.Post>> snapshot) {
  57.             if(snapshot.connectionState == ConnectionState.none) {
  58.               return Container();
  59.             }
  60.             if(snapshot.connectionState == ConnectionState.waiting) {
  61.               return Center(
  62.                 child: CircularProgressIndicator(),
  63.               );
  64.             }
  65.             return ListView.builder(itemCount: snapshot.data.length, itemBuilder: (context,index){
  66.               wp.Post post = snapshot.data[index];
  67.               return InkWell(
  68.                 enableFeedback: false,
  69.                 onTap: (){
  70.                   print('post');
  71.                 },
  72.                 child: Column(
  73.                   children: <Widget>[
  74.                     Column(
  75.                       children: <Widget>[
  76.                         Padding(
  77.                           padding: EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 0.0),
  78.                           child: Card(
  79.                             color: Colors.white,
  80.                             elevation: 4.0,
  81.                             shape: RoundedRectangleBorder(
  82.                               borderRadius: BorderRadius.circular(5.0),
  83.                             ),
  84.                             child: Padding(
  85.                               padding: EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 0.0),
  86.                               child: Row(
  87.                                 mainAxisAlignment: MainAxisAlignment.spaceBetween,
  88.                                 crossAxisAlignment: CrossAxisAlignment.start,
  89.                                 children: <Widget>[
  90.                                   Padding(
  91.                                     padding: EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0),
  92.                                     child: Container(
  93.                                       width: 320.0,
  94.  
  95.                                       child: Column(
  96.                                         mainAxisAlignment: MainAxisAlignment.spaceBetween,
  97.                                         crossAxisAlignment: CrossAxisAlignment.stretch,
  98.                                         children: <Widget>[
  99.                                           Column(
  100.                                             children: <Widget>[
  101.                                               Column(
  102.  
  103.                                                 crossAxisAlignment: CrossAxisAlignment.start,
  104.                                                 children: <Widget>[
  105.                                                   Text(
  106.                                                     post.title.rendered,
  107.                                                     textAlign: TextAlign.left,
  108.                                                     style: TextStyle(
  109.                                                       fontSize: 15.0,
  110.                                                       fontWeight: FontWeight.bold,
  111.                                                       color: Colors.teal[600],
  112.                                                       fontFamily: 'TatsamBengaliRndBold',
  113.                                                     ),
  114.                                                   ),
  115.  
  116.                                                   Html(data: post.excerpt.rendered,
  117.                                                   onLinkTap: (String url){
  118.                                                     launch(url);
  119.                                                   },),
  120.  
  121.                                                   SizedBox(
  122.                                                     height: 25.0,
  123.                                                   ),
  124.                                                   Row(
  125.                                                     crossAxisAlignment:
  126.                                                     CrossAxisAlignment.start,
  127.                                                     children: <Widget>[
  128.                                                       CircleAvatar(
  129.                                                         backgroundImage: NetworkImage(
  130.                                                             'https://image.shutterstock.com/image-photo/photo-owl-macro-photography-high-260nw-1178957458.jpg'),
  131.                                                       ),
  132.                                                       SizedBox(
  133.                                                         width: 10.0,
  134.                                                       ),
  135.                                                       Column(
  136.                                                         crossAxisAlignment:
  137.                                                         CrossAxisAlignment.start,
  138.                                                         children: <Widget>[
  139.  
  140.                                                           Text(
  141.                                                             post.author.name,
  142.                                                             textAlign: TextAlign.left,
  143.                                                             style: TextStyle(
  144.                                                               fontSize: 12.0,
  145.                                                               fontWeight: FontWeight.bold,
  146.                                                               color: Colors.black,
  147.                                                               fontFamily: 'TatsamBengaliRndLight',
  148.                                                             ),
  149.                                                           ),
  150. // Post Date & Times
  151. //                                                          Text(
  152. //                                                            post.dateGmt,
  153. //                                                            textAlign: TextAlign.left,
  154. //                                                            style: TextStyle(
  155. //                                                              fontSize: 10.0,
  156. //                                                              fontWeight: FontWeight.normal,
  157. //                                                              color: Colors.black,
  158. //                                                              fontFamily: 'TatsamBengaliRndLight',
  159. //                                                            ),
  160. //                                                          ),
  161.  
  162.                                                         ],
  163.                                                       )
  164.                                                     ],
  165.                                                   )
  166.                                                 ],
  167.                                               )
  168.                                             ],
  169.                                           )
  170.                                         ],
  171.                                       ),
  172.                                     ),
  173.                                   ),
  174. // side images
  175. //                                  Padding(
  176. //                                    padding: EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 0.0),
  177. //                                    child: Column(
  178. //                                      children: <Widget>[
  179. //                                        Container(
  180. //                                          width: 80.0,
  181. //                                          height: 120.0,
  182. //                                          child: Column(
  183. //                                            mainAxisAlignment:
  184. //                                            MainAxisAlignment.spaceBetween,
  185. //                                            children: <Widget>[
  186. //                                              ClipRRect(
  187. //                                                borderRadius: BorderRadius.circular(5.0),
  188. //                                                child: getPostImage(post),
  189. //                                              ),
  190. //                                              Icon(
  191. //                                                Icons.favorite,
  192. //                                                color: Colors.pinkAccent,
  193. //                                              )
  194. //                                            ],
  195. //                                          ),
  196. //                                        )
  197. //                                      ],
  198. //                                    ),
  199. //                                  )
  200.                                 ],
  201.                               ),
  202.                             ),
  203.                           ),
  204.                         ),
  205.                       ],
  206.                     ),
  207.                   ],
  208.                 ),
  209.               );
  210.             },
  211.             );
  212.             },
  213.       )
  214.       )
  215.     );
  216.   }
  217. }
Add Comment
Please, Sign In to add comment