Skip to content

Instantly share code, notes, and snippets.

@momshaddinury
Created March 17, 2020 09:27
Show Gist options
  • Save momshaddinury/fec1ea11ed0bfb941045ea26616171a1 to your computer and use it in GitHub Desktop.
Save momshaddinury/fec1ea11ed0bfb941045ea26616171a1 to your computer and use it in GitHub Desktop.
This is a small portion of my code. It is used to create a slider.
import 'dart:io';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:dnb/services/AssetManager.dart';
import 'package:flutter/material.dart';
class NoticeSliderScreen extends StatefulWidget {
@override
_NoticeSliderScreenState createState() => _NoticeSliderScreenState();
}
class _NoticeSliderScreenState extends State<NoticeSliderScreen> {
int _current = 0;
@override
Widget build(BuildContext context) {
return Container(
color: Colors.black,
child: Row(
children: <Widget>[
Flexible(
child: CarouselSlider(
viewportFraction: 1.0,
initialPage: 0,
autoPlay: true,
enableInfiniteScroll: true,
autoPlayInterval: Duration(seconds: 2),
scrollDirection: Axis.horizontal,
onPageChanged: (index) {
setState(() {
_current = index;
});
},
items: noticeList.map((url) {
return Builder(
builder: (BuildContext context) {
return Container(
color: Colors.black,
child: Row(
//crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: Image.file(
File(url),
fit: BoxFit.fill,
)),
],
),
);
},
);
}).toList(),
),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment