outputdone

Tutorial Membuat Aplikasi Blog Flutter Backend WordPress API

Artikel ini akan membahas tutorial bagaimana membuat aplikasi blog sederhana menggunakan flutter dengan menggunakan wordpress sebagai API-nya, studi kasus kali ini menggunakan backend.

Langkah pertamanya adalah membuat project di flutter

flutter create blogwp

create flutter project

main.dart

Ubah bagian main.dart pada folder lib

import 'package:flutter/material.dart';
void main() {
  runApp(const MyApp());
}
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}
class MyHomePage extends StatefulWidget {
  const MyHomePage({ Key? key,  }) : super(key: key);
  @override
  _MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('belajarflutterapp'),
      ),
    );
  }
}

Add Dependency

lalu kita siapkan package yang dibutuhkan dengan menggunakan shortcut ctrl + shift + P, tampilannya akan seperti di bawah ini :

Dart :add dependency

Function Get

 

Selanjutnya kita akan membuat function / fungsi yang berfungsi untuk mengirimkan permintaan ke aplikasi mobile yang ingin kita buat.

Future<List> getPosts() async {
var response = await http.get(
Uri.parse("https://belajarflutter.com/wp-json/wp/v2/posts?_embed"),
headers: {
"Accept": "application/json",
},
);
return jsonDecode(response.body);
}

initstate

lalu tambahkan function getPosts ke dalam void initstate

 

void initState() {
getPosts();
super.initState();
}

Untuk full code nya di atas ada di bawah ini :

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
Future<List> getPosts() async {
var response = await http.get(
Uri.parse("https://belajarflutter.com/wp-json/wp/v2/posts?_embed"),
headers: {
"Accept": "application/json",
},
);
return jsonDecode(response.body);
}
@override
void initState() {
getPosts();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'BelajarFlutterApps',
),
),
body: FutureBuilder(
future: getPosts(),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
Map posts = snapshot.data[index];
return Text(posts['title']['rendered']);
});
}
return CircularProgressIndicator();
},
),
);
}
}

Output Sementara

Next Step

langkah selanjutnya kita akan tampung datanya di dalam column dan sedikit merapikan user interfacenya

Column

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
Future<List> getPosts() async {
var response = await http.get(
Uri.parse("https://belajarflutter.com/wp-json/wp/v2/posts?_embed"),
headers: {
"Accept": "application/json",
},
);
return jsonDecode(response.body);
}
@override
void initState() {
getPosts();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'BelajarFlutterApps',
),
),
body: FutureBuilder(
future: getPosts(),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
Map posts = snapshot.data[index];
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
posts['title']['rendered'],
style: TextStyle(
fontSize: 20.0,
color: Colors.blueAccent,
fontWeight: FontWeight.bold,
),
),
],
);
});
}
return CircularProgressIndicator();
},
),
);
}
}

Card dan Padding

tambahkan card dan padding pada desain yang kita buat

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
Future<List> getPosts() async {
var response = await http.get(
Uri.parse("https://belajarflutter.com/wp-json/wp/v2/posts?_embed"),
headers: {
"Accept": "application/json",
},
);
return jsonDecode(response.body);
}
@override
void initState() {
getPosts();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'BelajarFlutterApps',
),
),
body: FutureBuilder(
future: getPosts(),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
Map posts = snapshot.data[index];
return Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
posts['title']['rendered'],
style: TextStyle(
fontSize: 20.0,
color: Colors.blueAccent,
fontWeight: FontWeight.bold,
),
),
],
),
),
);
});
}
return CircularProgressIndicator();
},
),
);
}
}

Tampilkan Gambar

return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
Map posts = snapshot.data[index];
return Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image.network(
posts['_embedded']['wp:featuredmedia'][0]['source_url'],
),
Text(
posts['title']['rendered'],
style: TextStyle(
fontSize: 20.0,
color: Colors.blueAccent,
fontWeight: FontWeight.bold,
),
),
],
),
),
);
});

Output finalnya adalah seperti di bawah ini :

Full Code nya :

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
Future<List> getPosts() async {
var response = await http.get(
Uri.parse("https://belajarflutter.com/wp-json/wp/v2/posts?_embed"),
headers: {
"Accept": "application/json",
},
);
return jsonDecode(response.body);
}
@override
void initState() {
getPosts();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'BelajarFlutterApps',
),
),
body: FutureBuilder(
future: getPosts(),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
Map posts = snapshot.data[index];
return Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image.network(
posts['_embedded']['wp:featuredmedia'][0]['source_url'],
),
Text(
posts['title']['rendered'],
style: TextStyle(
fontSize: 20.0,
color: Colors.blueAccent,
fontWeight: FontWeight.bold,
),
),
],
),
),
);
});
}
return CircularProgressIndicator();
},
),
);
}
}

Download Antivirus Ansav 2009 dan Smadav 2009

Ansav dan Smadav merupakan salah satu antivirus buatan lokal yang cukup handal. Pada dasarnya keduanya sama2 ampuh membasmi virus. Berikut ini link untuk download Ansav dan Smadav:

Software

ANSAV (2.0.40 – 19 Juni 2009)

* Ansav 2.0.39 format zip (799KB)
* Ansav 2.0.39 format exe (678KB)
* Anda dapat juga mendownload langsung dari:  Website Ansav

Perbaikan di versi 2.0.40

* Perbaikan bug pada command line parser yang menyebabkan crash.

Smadav 2009 (update 4 Juni 2009)

* Smadav 2009

Update virus database:

* http://ansav.server.or.id/

Apapun antivirus yang Anda gunakan, jangan lupa untuk mengupdate database antivirus secara reguler misalnya 1 minggu sekali atau maksimal sebulan sekali agar komputer anda bisa lebih aman dari serangan virus.

Semoga informasi ini dapat bermanfaat bagi anda yang membutuhkannya.