***Main.dart Page**
import 'package:flutter/material.dart';
import 'wp-api.dart';
import 'package:html/parser.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('NewCareer'),),
body: Container(
child: FutureBuilder(
future: fetchWpPosts(),
builder: (context,snapshot){
if(snapshot.hasData){
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index){
Map wppost = snapshot.data[index];
var imageurl = wppost["_embedded"]["wp:featuredmedia"][0]["source_url"];
return InkWell(
enableFeedback: false,
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=>Details(wppost),
),
);
},
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 0.0),
child: Card(
color: Colors.white,
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
child: Padding(
padding: EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 0.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 0.0),
child: Container(
width: 270.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Column(
children: <Widget>[
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
parse( (wppost['title']['rendered']).toString()).documentElement.text,
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 20.0,
color: Colors.red,
fontWeight: FontWeight.bold,
),
),
SizedBox(
height: 10.0,
),
Row(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
(wppost['date']).substring(0,10),
//post.dateGmt.substring(0,10),
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 14.0,
color: Colors.blue,
fontWeight: FontWeight.bold,
),
),
],
)
],
),
SizedBox(
height: 10.0,
),
Text(
parse( (wppost['excerpt']['rendered']).toString()).documentElement.text.substring(16,300),
//post.excerpt.rendered.substring(16,300),
textAlign: TextAlign.justify,
),
SizedBox(
height: 20.0,
),
],
)
],
)
],
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 0.0),
child: Column(
children: <Widget>[
Container(
width: 80.0,
height: 150.0,
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
FadeInImage.assetNetwork(
placeholder: 'assets/loading.gif',
image: imageurl,
),
//Image.network(imageurl),
CircleAvatar(
backgroundImage: NetworkImage(
'https://4.bp.blogspot.com/-uQZfu1d3Z-k/XqndVRuWAFI/AAAAAAAABB4/mTFnI370tooLBqrFKISnTxr5c4_tNQHAgCLcBGAsYHQ/s1600/Newcareer.jpg'),
),
],
),
)
],
),
)
],
),
),
),
),
]
),
);
},
);
}
return CircularProgressIndicator();
},
),
),
);
}
}
**wp-Api.dart Page**
import 'package:http/http.dart' as http;
import 'dart:convert';
Future<List> fetchWpPosts() async {
final response = await http.get('https://newcareer.in/wp-json/wp/v2/posts?_embed', headers:
{"Принять": "заявка / json"}); var convertDatato Json = jsonDecode (response.body); return convertDatatoJson; }
**details.dart page help please**
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_wordpress/flutter_wordpress.dart' as wp;
import 'package:url_launcher/url_launcher.dart';
import 'wp-api.dart';
class Details extends StatelessWidget {
wp.Post post;
Details(this.post);
getPostImage(){
if(post.featuredMedia == null){
return SizedBox(
height: 5.0,
);
}else {
return Image.network(post.featuredMedia.sourceUrl);
}
}
// launchUrl(String link) async{
// if (await canLaunch(link)){
// await launch(link);
// }else{
// throw 'can not show any thing from $link';
// }
// }
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: new IconButton(icon: new Icon(Icons.arrow_back_ios), color: Colors.black, onPressed: () =>
Navigator.of (context) .pop ()), высота: 0,0, заголовок: Image.asset ('images / lo go .png'), centerTitle: true, backgroundColor: Color (0xFFf6f8f c),), backgroundColor: Color (0xFFf6f8f c), тело: контейнер (дочерний элемент: Padding (padding: const EdgeInsets.all (5.0), дочерний элемент: SingleChildScrollView (дочерний элемент: столбец (crossAxisAlignment: CrossAxisAlignment. начало, дети: [Text (post.title.rendered.toString (), textAlign: TextAlign.left, стиль: TextStyle (fontSize: 20.0, цвет: Colors.red, fontWeight: FontWeight.bold,),), SizedBox (высота) : 10.0,), Text (post.date.replaceAll ('T', ''), textAlign: TextAlign.left, style: TextStyle (fontSize: 16.0, color: Colors.blueGrey, fontWeight: FontWeight.w200,),) ,
SizedBox(
height: 10.0,
),
// ClipRRect(
// borderRadius: BorderRadius.circular(5.0),
// child: getPostImage(),
// ),
// SizedBox(
// height: 10.0,
// ),
// Html(data: post.content.rendered,onLinkTap: (String url){
// launchUrl(url);
// },
// ),
],
)
)
),
),
);
}
}*