Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'dart:async';
- import 'dart:convert';
- import 'package:http/http.dart' as http;
- import 'package:wisata_flutter/model/ModelSlider.dart';
- import 'package:wisata_flutter/constant/Constant.dart';
- import 'package:carousel_pro/carousel_pro.dart';
- class HomePage extends StatefulWidget {
- @override
- _HomePageState createState() => _HomePageState();
- }
- class _HomePageState extends State<HomePage> {
- //List data slider
- static List listSlider = [];
- Map data;
- //get data slider from server
- Future getDataSlider() async {
- http.Response response =
- await http.get(ConstantFile().baseUrl + "getSlider");
- data = jsonDecode(response.body);
- if (response.statusCode == 200) {
- setState(() {
- listSlider = data['data'];
- print(listSlider);
- });
- }
- }
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- getDataSlider();
- }
- Widget image_slider() {
- return Container(
- height: 250.0,
- child: Padding(
- padding: const EdgeInsets.all(2.0),
- child: Card(
- shape:
- RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
- child: Padding(
- padding: const EdgeInsets.all(5.0),
- child: new Carousel(
- images: [
- NetworkImage(
- "http://onedayflutter.e-iso27001.com/images/gudeg%20yogyakarta.jpg"),
- NetworkImage("${ConstantFile().pathImage}" +
- "${listSlider[0]['foto_wisata']}"),
- NetworkImage("${ConstantFile().pathImage}" +
- "${listSlider[1]['foto_wisata']}"),
- NetworkImage("${ConstantFile().pathImage}" +
- "${listSlider[2]['foto_wisata']}"),
- ],
- animationCurve: Curves.fastOutSlowIn,
- animationDuration: new Duration(microseconds: 2000),
- ),
- ),
- ),
- ),
- );
- }
- //menampilkan slider dengan corousal
- // var imageSlider = Container(
- // height: 185,
- // child: listSlider.isEmpty ? CircularProgressIndicator(strokeWidth: 25,)
- // : new SizedBox(
- // height: 150.0,
- // width: 300.0,
- // child: Carousel(
- // images: [
- // //menampilkan slider
- //
- // NetworkImage("http://onedayflutter.e-iso27001.com/images/gudeg%20yogyakarta.jpg"),
- // NetworkImage("${ConstantFile().pathImage}"+ "${listSlider[0]['foto_wisata']}"),
- // NetworkImage("${ConstantFile().pathImage}"+ "${listSlider[1]['foto_wisata']}"),
- // NetworkImage("${ConstantFile().pathImage}"+ "${listSlider[2]['foto_wisata']}"),
- // ],
- // dotSize: 4.0,
- // dotSpacing: 15.0,
- // dotColor: Colors.lightBlueAccent,
- // indicatorBgPadding: 5.0,
- // dotBgColor: Colors.black12.withOpacity(0.5),
- // borderRadius: true,
- // moveIndicatorFromBottom: 180,
- // noRadiusForIndicator: true,
- // ),
- //
- // )
- // );
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: Stack(
- children: <Widget>[
- SingleChildScrollView(
- child: Column(
- children: <Widget>[image_slider()],
- ),
- )
- ],
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement