Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:loading/loading.dart';
- import 'package:loading/indicator/ball_pulse_indicator.dart';
- import 'package:pull_to_refresh/pull_to_refresh.dart';
- import 'package:http/http.dart' as http;
- import 'dart:async';
- import 'dart:convert';
- class KursPage extends StatefulWidget {
- @override
- _KursPageState createState() => _KursPageState();
- }
- class _KursPageState extends State<KursPage> {
- //UIs
- bool loading = true;
- bool updateCounter = true;
- //Variables
- String baseUrl, serverCode;
- Map data;
- String kursSekarang, kursPembayaran, kursSekarangTanggal, kursPembayaranTanggal;
- //Datasets
- List kursList;
- RefreshController _refreshController = RefreshController(initialRefresh: false);
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- getServerUrl();
- }
- @override
- Widget build(BuildContext context) {
- final body = Container(
- width: MediaQuery.of(context).size.width,
- padding: EdgeInsets.all(8.0),
- decoration: BoxDecoration(
- color: Colors.grey[300]
- ),
- child: (loading) ?
- Center(
- child: Column(
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(top: MediaQuery.of(context).size.height/2.2),
- ),
- Loading(
- indicator: BallPulseIndicator(), size: 50.0, color: Colors.lightBlue,
- ),
- Text("Memuat Data")
- ]
- )
- ) : SmartRefresher(
- enablePullDown: true,
- enablePullUp: false,
- header: WaterDropHeader(waterDropColor: Colors.lightBlue),
- footer: CustomFooter(
- builder: (BuildContext context, LoadStatus mode){
- Widget body ;
- if(mode==LoadStatus.noMore){
- body = Text("No more Data");
- }
- else if(mode==LoadStatus.loading){
- body = Loading(
- indicator: BallPulseIndicator(), size: 50.0, color: Colors.lightBlue,
- );
- }
- else if(mode == LoadStatus.failed){
- body = Text("Load Failed!Click retry!");
- }
- else if(mode == LoadStatus.canLoading){
- body = Text("release to load more");
- }
- else{
- body = Text("pull up load");
- }
- return Container(
- height: 55.0,
- child: Center(child:body),
- );
- },
- ),
- controller: _refreshController,
- onRefresh: _onRefresh,
- onLoading: _onLoading,
- child: (kursList == null) ?
- Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Text("Tidak ada rekam jejak kurs.", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold))
- ]
- )
- ) :
- ListView.builder(
- itemCount: (kursList == null) ? 0 : kursList.length,
- itemBuilder: (BuildContext context, int index) {
- return InkWell(
- highlightColor: Colors.white.withAlpha(30),
- splashColor: Colors.white.withAlpha(20),
- child: Card(
- margin: EdgeInsets.all(3.0),
- elevation: 3,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(7.0)
- ),
- child: Padding(
- padding: EdgeInsets.all(2.0),
- child: ListTile(
- title: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text("${kursList[index]["kurs_mata_uang"]}",
- style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(right: 5.0),
- ),
- ]
- )
- ]
- ),
- subtitle: Column(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text("Kurs Sekarang Rp. ${kursList[index]["kurs_sekarang"]}"),
- Text("Kurs Pembayaran Rp. ${kursList[index]["kurs_pembayaran"]}"),
- ]
- ),
- SizedBox(height: 2.0),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text("${kursList[index]["kurs_sekarang_tgl"]}"),
- Text("${kursList[index]["kurs_pembayaran_tgl"]}"),
- ]
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- ]
- )
- ],
- )
- )
- )
- )
- );
- }
- )
- )
- );
- return Scaffold(
- backgroundColor: Colors.grey[200],
- appBar: new AppBar(
- title: const Text('List Kurs'),
- elevation: 3,
- ),
- body: body
- );
- }
- Future getServerUrl() async {
- SharedPreferences prefs = await SharedPreferences.getInstance();
- setState(() {
- if (prefs.getString("login_jaringan") == "Lokal"){
- baseUrl = "http://192.168.1.200/";
- } else {
- baseUrl = "http://koffiesoftmjw.ngrok.io/";
- }
- if (prefs.getString("login_cabang") == 'MJWJKT'){
- serverCode = "/koffie_mjw/index.php?c=c_kurs&m=get_action";
- } else if(prefs.getString("login_cabang") == 'MJWSBY'){
- serverCode = "/koffie_mjw_sby/index.php?c=c_kurs&m=get_action";
- } else {
- serverCode = "/koffie_mjw_testing/index.php?c=c_kurs&m=get_action";
- }
- getData();
- });
- }
- Future getData() async {
- http.Response response = await http.post("$baseUrl$serverCode", body: {
- "task" : "LIST",
- "query" : "",
- "type" : "app",
- "start" : "0",
- "limit" : "100"
- });
- if (response.statusCode == 200) {
- data = json.decode(response.body);
- print(data.toString());
- if (data["total"] == "0") {
- kursList = null;
- } else {
- kursList = data["results"];
- for (var i = 0; i < json.decode(response.body)["results"].length; i++) {
- kursSekarang = json.decode(response.body)["results"][i]["kurs_sekarang"];
- kursPembayaran = json.decode(response.body)["results"][i]["kurs_pembayaran"];
- kursSekarangTanggal = json.decode(response.body)["results"][i]["kurs_sekarang_tgl"];
- kursPembayaranTanggal = json.decode(response.body)["results"][i]["kurs_pembayaran_tgl"];
- kursList.add(kursSekarang);
- kursList.add(kursSekarang);
- kursList.add(kursSekarang);
- kursList.add(kursSekarang);
- }
- print(kursSekarangTanggal);
- setState(() {
- loading = false;
- });
- }
- } else {
- return null;
- }
- }
- void _onRefresh() async{
- await Future.delayed(Duration(milliseconds: 1000));
- // if failed,use refreshFailed()
- _refreshController.refreshCompleted();
- getData();
- }
- void _onLoading() async{
- // monitor network fetch
- await Future.delayed(Duration(milliseconds: 1000));
- // if failed,use loadFailed(),if no data return,use LoadNodata()
- setState(() {});
- _refreshController.loadComplete();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement