Skip to content

Instantly share code, notes, and snippets.

@becek2n
Created August 4, 2020 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save becek2n/40e7dd780230418f820451a2d59237d3 to your computer and use it in GitHub Desktop.
Save becek2n/40e7dd780230418f820451a2d59237d3 to your computer and use it in GitHub Desktop.
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class SliderShowFullmages extends StatefulWidget{
final List listImagesModel;
final int current;
const SliderShowFullmages({ Key key, this.listImagesModel, this.current }) : super(key: key);
@override
_SliderShowFullmagesState createState() => _SliderShowFullmagesState();
}
class _SliderShowFullmagesState extends State<SliderShowFullmages> {
int _current = 0;
bool _stateChange = false;
@override
void initState() {
super.initState();
}
List<T> map<T>(List list, Function handler) {
List<T> result = [];
for (var i = 0; i < list.length; i++) {
result.add(handler(i, list[i]));
}
return result;
}
@override
Widget build(BuildContext context) {
_current = (_stateChange == false) ? widget.current : _current;
return new Container(
color: Colors.transparent,
child: new Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
backgroundColor: Colors.transparent,
//title: const Text('Transaction Detail'),
),
body: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
CarouselSlider(
options: CarouselOptions(
autoPlay: false,
height: MediaQuery.of(context).size.height/1.3,
viewportFraction: 1.0,
onPageChanged: (index, data) {
setState(() {
_stateChange = true;
_current = index;
});
},
initialPage: widget.current
),
items: map<Widget>(widget.listImagesModel, (index, url) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(0.0)),
child: Image.asset(
url,
fit: BoxFit.fill,
height: 400.0,
),
),
)
]
);
}),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: map<Widget>(widget.listImagesModel, (index, url) {
return Container(
width: 10.0,
height: 9.0,
margin: EdgeInsets.symmetric(vertical: 10.0, horizontal: 5.0),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: (_current == index) ? Colors.redAccent : Colors.grey,
),
);
}),
),
],
),
)
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment