Flutter Swiper: How to show multiple widgets on one page while aligning left?

Viewed 472

I'm using swiper and I want to get one and a half of the card widget on the screen with the first card aligned to the left. However, the first card always align-center as shown. Is there a way to go about this?

enter image description here

The code for the swiper is as shown below:

  @override
  _EventSwiperState createState() => _EventSwiperState();
}

class _EventSwiperState extends State<EventSwiper> {
  @override
  Widget build(BuildContext context) {
    var width = MediaQuery.of(context).size.width;
    var height = MediaQuery.of(context).size.height;
    Color starColor = Colors.orange;
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Padding(
          padding: const EdgeInsets.all(18.0),
          child: Text('Upcoming Events',style: TextStyle(fontSize: 21,
              color:Colors.white,
              fontWeight: FontWeight.bold,
              fontFamily: 'Nunito'),),
        ),
        Container(
          height: height * 0.33,
          width: width,
          child: Swiper(
            // itemWidth: width*0.6,
            itemBuilder: (BuildContext context, int index) {
              return EventCard(events[index]);
            },
            // itemHeight: height / 4.2,
            itemCount: events.length,
            layout: SwiperLayout.DEFAULT,
            index: 0,
            viewportFraction: 0.8,
            scale: 1.1,
            loop: false,
            itemWidth: width*0.9,
            control: SwiperControl(iconNext: null, iconPrevious: null),
          ),
        ),
      ],
    );
  }

The code for the individual card is as shown below:

class EventCard extends StatefulWidget {
  final Event events;
  const EventCard(this.events);

  @override
  _EventCardState createState() => _EventCardState();
}

class _EventCardState extends State<EventCard> {
  @override
  Widget build(BuildContext context) {
    var width = MediaQuery.of(context).size.width;
    var height = MediaQuery.of(context).size.height;
    return Container(
      margin: EdgeInsets.symmetric(horizontal: width / 24,),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.all(Radius.circular(10)),
        color: Color(0xff282828),
      ),
      child: Text(widget.events.emoji)
);  }
}

0 Answers
Related