Skip to content

Instantly share code, notes, and snippets.

@shakil807g
Created August 9, 2018 19:05
Show Gist options
  • Save shakil807g/8a66f0ddac2a1b967be05e2dabb28b6e to your computer and use it in GitHub Desktop.
Save shakil807g/8a66f0ddac2a1b967be05e2dabb28b6e to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:cached_network_image/cached_network_image.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: DemoScreen(),
);
}
}
class DemoScreen extends StatefulWidget {
@override
_DemoScreenState createState() => _DemoScreenState();
}
class _DemoScreenState extends State<DemoScreen> {
// List<String> imgList = ["https://images.pexels.com/photos/691034/pexels-photo-691034.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=350",
// "https://images.pexels.com/photos/1308678/pexels-photo-1308678.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=350",
// "https://images.pexels.com/photos/951539/pexels-photo-951539.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=350"];
List<String> imgList = [];
@override
Widget build(BuildContext context) {
return new Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(backgroundColor: Colors.black,
title: Text("Slide Show",style: TextStyle(color: Colors.white),),centerTitle: true,
leading: new IconButton(
iconSize: 28.0,
padding: const EdgeInsets.all(16.0),
icon: Icon(Icons.arrow_back,color: Colors.white,),
onPressed: () {
Navigator.pop(context);
},
),
),
body: new SafeArea(
child: new Column(
children: <Widget>[
new SizedBox(height: 40.0,),
imgList.length > 0 ?
new CarouselSlider(
items: imgList.map((url) {
return new Container(
width: MediaQuery.of(context).size.width,
margin: new EdgeInsets.symmetric(horizontal: 5.0),
decoration: new BoxDecoration(
borderRadius: new BorderRadius.all(new Radius.circular(5.0)),
),
child: new CachedNetworkImage(
imageUrl: url,
fit: BoxFit.cover,
placeholder: new Center(
child: new SizedBox(
width: 50.0,
height: 50.0,
child: new CircularProgressIndicator()
)
),
errorWidget: new Icon(Icons.error),
fadeOutDuration: new Duration(seconds: 1),
fadeInDuration: new Duration(seconds: 1),
),
);
}).toList(),
height: MediaQuery.of(context).size.height * 0.70 ,
autoPlay: true
):
Expanded(child: Center(child: new Text("No photo found.",style: TextStyle(color: Colors.white))))
,
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment