(
19 | future: postService.getAllPost(),
20 | builder: (context, snapshot) {
21 | if (snapshot.hasData) {
22 | if (snapshot.data?.length == 0) {
23 | return Center(
24 | child: Text("0 Post"),
25 | );
26 | }
27 | return ListView.builder(
28 | itemCount: snapshot.data?.length,
29 | itemBuilder: (context, i) {
30 | // print(snapshot.data![i]['content']['rendered']);
31 | return Card(
32 | child: ListTile(
33 | title: Row(
34 | children: [
35 | Expanded(
36 | child: Image.network(snapshot.data![i]["_embedded"]
37 | ["wp:featuredmedia"][0]["source_url"]),
38 | ),
39 | Expanded(
40 | child: Container(
41 | margin: EdgeInsets.only(bottom: 10.0, left: 10.0),
42 | child: Text(
43 | snapshot.data![i]['title']['rendered'],
44 | style: TextStyle(
45 | fontSize: 24.0, fontWeight: FontWeight.bold),
46 | ),
47 | ))
48 | ],
49 | ),
50 | subtitle: Container(
51 | margin: EdgeInsets.only(bottom: 10.0),
52 | child: Text(
53 | snapshot.data![i]['content']['rendered']
54 | .toString()
55 | .replaceAll("", "")
56 | .replaceAll("
", ""),
57 | maxLines: 4,
58 | overflow: TextOverflow.ellipsis,
59 | style: TextStyle(fontSize: 20.0),
60 | ),
61 | ),
62 | onTap: () {
63 | Navigator.push(
64 | context,
65 | MaterialPageRoute(
66 | builder: (context) =>
67 | PostDetail(data: snapshot.data?[i]),
68 | ),
69 | );
70 | },
71 | ),
72 | );
73 | });
74 | } else if (snapshot.hasError) {
75 | return Center(
76 | child: Text(snapshot.error.toString()),
77 | );
78 | } else {
79 | return Center(
80 | child: CircularProgressIndicator(),
81 | );
82 | }
83 | },
84 | ),
85 | );
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/lib/screens/pageDetail.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | class PageDetail extends StatelessWidget {
4 | final data;
5 | const PageDetail({Key? key, required this.data}) : super(key: key);
6 |
7 | @override
8 | Widget build(BuildContext context) {
9 | return Scaffold(
10 | appBar: AppBar(
11 | title: Text(data['title']['rendered']),
12 | ),
13 | body: ListView(
14 | padding: const EdgeInsets.all(8),
15 | children: [
16 | Container(
17 | padding: EdgeInsets.symmetric(horizontal: 10.0),
18 | child: Text(
19 | data['content']['rendered']
20 | .toString()
21 | .replaceAll("", "")
22 | .replaceAll("
", ""),
23 | style: TextStyle(fontSize: 20.0),
24 | ),
25 | ),
26 | ],
27 | ),
28 | );
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/lib/screens/photos.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | class Photo extends StatelessWidget {
4 | const Photo({Key? key}) : super(key: key);
5 |
6 | @override
7 | Widget build(BuildContext context) {
8 | return Container(
9 | child: Text(
10 | "Photo",
11 | style: TextStyle(fontSize: 24.0),
12 | ),
13 | );
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/lib/screens/postdetail.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | class PostDetail extends StatelessWidget {
4 | final data;
5 | const PostDetail({Key? key, required this.data}) : super(key: key);
6 |
7 | @override
8 | Widget build(BuildContext context) {
9 | return Scaffold(
10 | appBar: AppBar(
11 | title: Text("E-Learning Cave - Latest Post"),
12 | ),
13 | body: ListView(
14 | padding: const EdgeInsets.all(8),
15 | children: [
16 | Center(
17 | child: Container(
18 | margin: EdgeInsets.only(bottom: 10.0, top: 10.0),
19 | child: Text(
20 | data['title']['rendered'],
21 | style: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold),
22 | ),
23 | ),
24 | ),
25 | Image.network(data["_embedded"]["wp:featuredmedia"][0]["source_url"]),
26 | Container(
27 | padding: EdgeInsets.symmetric(horizontal: 10.0),
28 | child: Text(
29 | data['content']['rendered']
30 | .toString()
31 | .replaceAll("", "")
32 | .replaceAll("
", ""),
33 | style: TextStyle(fontSize: 20.0),
34 | ),
35 | ),
36 | ],
37 | ),
38 | );
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/lib/screens/videos.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | class Video extends StatelessWidget {
4 | const Video({Key? key}) : super(key: key);
5 |
6 | @override
7 | Widget build(BuildContext context) {
8 | return Container(
9 | child: Text(
10 | "Video",
11 | style: TextStyle(fontSize: 24.0),
12 | ),
13 | );
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/lib/services/mycategory.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 |
3 | import 'package:http/http.dart' as http;
4 |
5 | class MyCategory {
6 | String baseUrl =
7 | "http://elearningcave.com/wp-json/wp/v2/posts?_embed&categories=2";
8 | Future getCategoryPost() async {
9 | try {
10 | var response = await http.get(Uri.parse(baseUrl));
11 | print(response);
12 | if (response.statusCode == 200) {
13 | return jsonDecode(response.body);
14 | } else {
15 | return Future.error("Server Error");
16 | }
17 | } catch (SocketException) {
18 | return Future.error("Error Fetching Data");
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/lib/services/page.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 |
3 | import 'package:http/http.dart' as http;
4 |
5 | class MyPage {
6 | String baseUrl = "http://elearningcave.com/wp-json/wp/v2/pages";
7 | Future getAllPage() async {
8 | try {
9 | var response = await http.get(Uri.parse(baseUrl));
10 | print(response);
11 | if (response.statusCode == 200) {
12 | return jsonDecode(response.body);
13 | } else {
14 | return Future.error("Server Error");
15 | }
16 | } catch (SocketException) {
17 | return Future.error("Error Fetching Data");
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/lib/services/post.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 |
3 | import 'package:http/http.dart' as http;
4 |
5 | class Post {
6 | String baseUrl = "http://elearningcave.com/wp-json/wp/v2/posts?_embed";
7 | Future getAllPost() async {
8 | try {
9 | var response = await http.get(Uri.parse(baseUrl));
10 | print(response);
11 | if (response.statusCode == 200) {
12 | return jsonDecode(response.body);
13 | } else {
14 | return Future.error("Server Error");
15 | }
16 | } catch (SocketException) {
17 | return Future.error("Error Fetching Data");
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/lib/widgets/maintab.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:flutter/services.dart';
3 | import 'package:flutter_wordpress_api_get_post/screens/categorypost.dart';
4 | import 'package:flutter_wordpress_api_get_post/screens/latestpost.dart';
5 | import 'package:flutter_wordpress_api_get_post/screens/photos.dart';
6 | import 'package:flutter_wordpress_api_get_post/screens/videos.dart';
7 | import 'package:flutter_wordpress_api_get_post/widgets/mydrawer.dart';
8 |
9 | class MainTab extends StatefulWidget {
10 | MainTab({Key? key}) : super(key: key);
11 |
12 | @override
13 | _MainTabState createState() => _MainTabState();
14 | }
15 |
16 | class _MainTabState extends State with SingleTickerProviderStateMixin {
17 | TabController? _tabController;
18 | final List topTabs = [
19 | Tab(child: Text("LATEST")),
20 | Tab(child: Text("POPULAR")),
21 | Tab(child: Text("VIDEOS")),
22 | Tab(child: Text("PHOTOS")),
23 | ];
24 |
25 | @override
26 | void initState() {
27 | _tabController =
28 | TabController(length: topTabs.length, initialIndex: 0, vsync: this)
29 | ..addListener(() {
30 | setState(() {});
31 | });
32 | super.initState();
33 | }
34 |
35 | Future _onWillPop() async {
36 | print("on Will Pop");
37 | if (_tabController?.index == 0) {
38 | await SystemNavigator.pop();
39 | }
40 |
41 | Future.delayed(Duration(microseconds: 200), () {
42 | print("Set Index");
43 | _tabController?.index = 0;
44 | });
45 |
46 | print("Return");
47 | return _tabController?.index == 0;
48 | }
49 |
50 | final _scaffoldKey = GlobalKey();
51 |
52 | @override
53 | Widget build(BuildContext context) {
54 | return Container(
55 | child: WillPopScope(
56 | onWillPop: _onWillPop,
57 | child: Scaffold(
58 | key: _scaffoldKey,
59 | appBar: AppBar(
60 | title: Text(
61 | 'E-Learning Cave',
62 | style: TextStyle(
63 | fontSize: 30,
64 | ),
65 | ),
66 | actions: [
67 | Container(
68 | child: IconButton(
69 | icon: Icon(Icons.search),
70 | splashColor: Colors.transparent,
71 | highlightColor: Colors.transparent,
72 | onPressed: () {
73 | print('Search Button Clicked');
74 | },
75 | ),
76 | decoration: BoxDecoration(
77 | shape: BoxShape.circle,
78 | color: Colors.pink[300],
79 | ),
80 | ),
81 | Container(
82 | margin: EdgeInsets.symmetric(horizontal: 10.0),
83 | child: IconButton(
84 | icon: Icon(Icons.menu),
85 | splashColor: Colors.transparent,
86 | highlightColor: Colors.transparent,
87 | onPressed: () => _scaffoldKey.currentState!.openEndDrawer(),
88 | ),
89 | decoration: BoxDecoration(
90 | shape: BoxShape.circle,
91 | color: Colors.pink[300],
92 | ),
93 | ),
94 | ],
95 | bottom: TabBar(
96 | controller: _tabController,
97 | indicatorColor: Colors.black,
98 | tabs: topTabs,
99 | ),
100 | ),
101 | endDrawer: Container(
102 | child: MyDrawer(),
103 | ),
104 | body: TabBarView(
105 | controller: _tabController,
106 | children: [
107 | LatestPost(),
108 | CategoryPost(),
109 | Video(),
110 | Photo(),
111 | ],
112 | ),
113 | ),
114 | ),
115 | );
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/lib/widgets/mydrawer.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:flutter_wordpress_api_get_post/screens/pageDetail.dart';
3 | import 'package:flutter_wordpress_api_get_post/services/page.dart';
4 |
5 | class MyDrawer extends StatefulWidget {
6 | MyDrawer({Key? key}) : super(key: key);
7 |
8 | @override
9 | _MyDrawerState createState() => _MyDrawerState();
10 | }
11 |
12 | class _MyDrawerState extends State {
13 | MyPage pageService = MyPage();
14 | @override
15 | Widget build(BuildContext context) {
16 | return Drawer(
17 | child: Container(
18 | color: Colors.pinkAccent[200],
19 | child: Column(
20 | children: [
21 | Expanded(
22 | child: Container(
23 | child: FutureBuilder(
24 | future: pageService.getAllPage(),
25 | builder: (context, snapshot) {
26 | if (snapshot.hasData) {
27 | if (snapshot.data?.length == 0) {
28 | return Center(
29 | child: Text("No Page"),
30 | );
31 | }
32 | return ListView.builder(
33 | itemCount: snapshot.data?.length,
34 | itemBuilder: (context, i) {
35 | return ListTile(
36 | title: Center(
37 | child: Text(
38 | snapshot.data?[i]['title']['rendered'],
39 | style: TextStyle(
40 | fontSize: 22, color: Colors.white),
41 | ),
42 | ),
43 | onTap: () => {
44 | Navigator.push(
45 | context,
46 | MaterialPageRoute(
47 | builder: (context) =>
48 | PageDetail(data: snapshot.data?[i]),
49 | ),
50 | )
51 | },
52 | );
53 | });
54 | } else if (snapshot.hasError) {
55 | return Center(
56 | child: Text(snapshot.error.toString()),
57 | );
58 | } else {
59 | return Center(
60 | child: CircularProgressIndicator(),
61 | );
62 | }
63 | },
64 | ),
65 | ))
66 | ],
67 | ),
68 | ),
69 | );
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/pubspec.lock:
--------------------------------------------------------------------------------
1 | # Generated by pub
2 | # See https://dart.dev/tools/pub/glossary#lockfile
3 | packages:
4 | async:
5 | dependency: transitive
6 | description:
7 | name: async
8 | url: "https://pub.dartlang.org"
9 | source: hosted
10 | version: "2.6.1"
11 | boolean_selector:
12 | dependency: transitive
13 | description:
14 | name: boolean_selector
15 | url: "https://pub.dartlang.org"
16 | source: hosted
17 | version: "2.1.0"
18 | characters:
19 | dependency: transitive
20 | description:
21 | name: characters
22 | url: "https://pub.dartlang.org"
23 | source: hosted
24 | version: "1.1.0"
25 | charcode:
26 | dependency: transitive
27 | description:
28 | name: charcode
29 | url: "https://pub.dartlang.org"
30 | source: hosted
31 | version: "1.2.0"
32 | clock:
33 | dependency: transitive
34 | description:
35 | name: clock
36 | url: "https://pub.dartlang.org"
37 | source: hosted
38 | version: "1.1.0"
39 | collection:
40 | dependency: transitive
41 | description:
42 | name: collection
43 | url: "https://pub.dartlang.org"
44 | source: hosted
45 | version: "1.15.0"
46 | cupertino_icons:
47 | dependency: "direct main"
48 | description:
49 | name: cupertino_icons
50 | url: "https://pub.dartlang.org"
51 | source: hosted
52 | version: "1.0.3"
53 | fake_async:
54 | dependency: transitive
55 | description:
56 | name: fake_async
57 | url: "https://pub.dartlang.org"
58 | source: hosted
59 | version: "1.2.0"
60 | flutter:
61 | dependency: "direct main"
62 | description: flutter
63 | source: sdk
64 | version: "0.0.0"
65 | flutter_test:
66 | dependency: "direct dev"
67 | description: flutter
68 | source: sdk
69 | version: "0.0.0"
70 | http:
71 | dependency: "direct main"
72 | description:
73 | name: http
74 | url: "https://pub.dartlang.org"
75 | source: hosted
76 | version: "0.13.3"
77 | http_parser:
78 | dependency: transitive
79 | description:
80 | name: http_parser
81 | url: "https://pub.dartlang.org"
82 | source: hosted
83 | version: "4.0.0"
84 | matcher:
85 | dependency: transitive
86 | description:
87 | name: matcher
88 | url: "https://pub.dartlang.org"
89 | source: hosted
90 | version: "0.12.10"
91 | meta:
92 | dependency: transitive
93 | description:
94 | name: meta
95 | url: "https://pub.dartlang.org"
96 | source: hosted
97 | version: "1.3.0"
98 | path:
99 | dependency: transitive
100 | description:
101 | name: path
102 | url: "https://pub.dartlang.org"
103 | source: hosted
104 | version: "1.8.0"
105 | pedantic:
106 | dependency: transitive
107 | description:
108 | name: pedantic
109 | url: "https://pub.dartlang.org"
110 | source: hosted
111 | version: "1.11.1"
112 | sky_engine:
113 | dependency: transitive
114 | description: flutter
115 | source: sdk
116 | version: "0.0.99"
117 | source_span:
118 | dependency: transitive
119 | description:
120 | name: source_span
121 | url: "https://pub.dartlang.org"
122 | source: hosted
123 | version: "1.8.1"
124 | stack_trace:
125 | dependency: transitive
126 | description:
127 | name: stack_trace
128 | url: "https://pub.dartlang.org"
129 | source: hosted
130 | version: "1.10.0"
131 | stream_channel:
132 | dependency: transitive
133 | description:
134 | name: stream_channel
135 | url: "https://pub.dartlang.org"
136 | source: hosted
137 | version: "2.1.0"
138 | string_scanner:
139 | dependency: transitive
140 | description:
141 | name: string_scanner
142 | url: "https://pub.dartlang.org"
143 | source: hosted
144 | version: "1.1.0"
145 | term_glyph:
146 | dependency: transitive
147 | description:
148 | name: term_glyph
149 | url: "https://pub.dartlang.org"
150 | source: hosted
151 | version: "1.2.0"
152 | test_api:
153 | dependency: transitive
154 | description:
155 | name: test_api
156 | url: "https://pub.dartlang.org"
157 | source: hosted
158 | version: "0.3.0"
159 | typed_data:
160 | dependency: transitive
161 | description:
162 | name: typed_data
163 | url: "https://pub.dartlang.org"
164 | source: hosted
165 | version: "1.3.0"
166 | vector_math:
167 | dependency: transitive
168 | description:
169 | name: vector_math
170 | url: "https://pub.dartlang.org"
171 | source: hosted
172 | version: "2.1.0"
173 | sdks:
174 | dart: ">=2.12.0 <3.0.0"
175 |
--------------------------------------------------------------------------------
/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: flutter_wordpress_api_get_post
2 | description: A new Flutter project.
3 |
4 | # The following line prevents the package from being accidentally published to
5 | # pub.dev using `pub publish`. This is preferred for private packages.
6 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev
7 |
8 | # The following defines the version and build number for your application.
9 | # A version number is three numbers separated by dots, like 1.2.43
10 | # followed by an optional build number separated by a +.
11 | # Both the version and the builder number may be overridden in flutter
12 | # build by specifying --build-name and --build-number, respectively.
13 | # In Android, build-name is used as versionName while build-number used as versionCode.
14 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning
15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
16 | # Read more about iOS versioning at
17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
18 | version: 1.0.0+1
19 |
20 | environment:
21 | sdk: ">=2.12.0 <3.0.0"
22 |
23 | dependencies:
24 | flutter:
25 | sdk: flutter
26 |
27 |
28 | # The following adds the Cupertino Icons font to your application.
29 | # Use with the CupertinoIcons class for iOS style icons.
30 | cupertino_icons: ^1.0.2
31 | http: ^0.13.3
32 |
33 | dev_dependencies:
34 | flutter_test:
35 | sdk: flutter
36 |
37 | # For information on the generic Dart part of this file, see the
38 | # following page: https://dart.dev/tools/pub/pubspec
39 |
40 | # The following section is specific to Flutter.
41 | flutter:
42 |
43 | # The following line ensures that the Material Icons font is
44 | # included with your application, so that you can use the icons in
45 | # the material Icons class.
46 | uses-material-design: true
47 |
48 | # To add assets to your application, add an assets section, like this:
49 | # assets:
50 | # - images/a_dot_burr.jpeg
51 | # - images/a_dot_ham.jpeg
52 |
53 | # An image asset can refer to one or more resolution-specific "variants", see
54 | # https://flutter.dev/assets-and-images/#resolution-aware.
55 |
56 | # For details regarding adding assets from package dependencies, see
57 | # https://flutter.dev/assets-and-images/#from-packages
58 |
59 | # To add custom fonts to your application, add a fonts section here,
60 | # in this "flutter" section. Each entry in this list should have a
61 | # "family" key with the font family name, and a "fonts" key with a
62 | # list giving the asset and other descriptors for the font. For
63 | # example:
64 | # fonts:
65 | # - family: Schyler
66 | # fonts:
67 | # - asset: fonts/Schyler-Regular.ttf
68 | # - asset: fonts/Schyler-Italic.ttf
69 | # style: italic
70 | # - family: Trajan Pro
71 | # fonts:
72 | # - asset: fonts/TrajanPro.ttf
73 | # - asset: fonts/TrajanPro_Bold.ttf
74 | # weight: 700
75 | #
76 | # For details regarding fonts from package dependencies,
77 | # see https://flutter.dev/custom-fonts/#from-packages
78 |
--------------------------------------------------------------------------------
/test/widget_test.dart:
--------------------------------------------------------------------------------
1 | // This is a basic Flutter widget test.
2 | //
3 | // To perform an interaction with a widget in your test, use the WidgetTester
4 | // utility that Flutter provides. For example, you can send tap and scroll
5 | // gestures. You can also use WidgetTester to find child widgets in the widget
6 | // tree, read text, and verify that the values of widget properties are correct.
7 |
8 | import 'package:flutter/material.dart';
9 | import 'package:flutter_test/flutter_test.dart';
10 |
11 | import 'package:flutter_wordpress_api_get_post/main.dart';
12 |
13 | void main() {
14 | testWidgets('Counter increments smoke test', (WidgetTester tester) async {
15 | // Build our app and trigger a frame.
16 | await tester.pumpWidget(MyApp());
17 |
18 | // Verify that our counter starts at 0.
19 | expect(find.text('0'), findsOneWidget);
20 | expect(find.text('1'), findsNothing);
21 |
22 | // Tap the '+' icon and trigger a frame.
23 | await tester.tap(find.byIcon(Icons.add));
24 | await tester.pump();
25 |
26 | // Verify that our counter has incremented.
27 | expect(find.text('0'), findsNothing);
28 | expect(find.text('1'), findsOneWidget);
29 | });
30 | }
31 |
--------------------------------------------------------------------------------
/web/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geekyshow1/flutter_wordpress_api_get_post/924768d83c8dc62874d1979fb0b372f3e94ac65b/web/favicon.png
--------------------------------------------------------------------------------
/web/icons/Icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geekyshow1/flutter_wordpress_api_get_post/924768d83c8dc62874d1979fb0b372f3e94ac65b/web/icons/Icon-192.png
--------------------------------------------------------------------------------
/web/icons/Icon-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geekyshow1/flutter_wordpress_api_get_post/924768d83c8dc62874d1979fb0b372f3e94ac65b/web/icons/Icon-512.png
--------------------------------------------------------------------------------
/web/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | flutter_wordpress_api_get_post
27 |
28 |
29 |
30 |
33 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/web/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "flutter_wordpress_api_get_post",
3 | "short_name": "flutter_wordpress_api_get_post",
4 | "start_url": ".",
5 | "display": "standalone",
6 | "background_color": "#0175C2",
7 | "theme_color": "#0175C2",
8 | "description": "A new Flutter project.",
9 | "orientation": "portrait-primary",
10 | "prefer_related_applications": false,
11 | "icons": [
12 | {
13 | "src": "icons/Icon-192.png",
14 | "sizes": "192x192",
15 | "type": "image/png"
16 | },
17 | {
18 | "src": "icons/Icon-512.png",
19 | "sizes": "512x512",
20 | "type": "image/png"
21 | }
22 | ]
23 | }
24 |
--------------------------------------------------------------------------------