Как сделать карусель там, где центр больше? (Флаттер) - PullRequest
0 голосов
/ 19 февраля 2020

Я хочу иметь слайд-шоу, где вы видите три контейнера, а средний контейнер должен быть больше двух других.

Вот как это должно выглядеть: slideshow where you can see three Elements at once which center item is bigger or the other two smaller

Я попытался поставить увеличитьCenterPage: true, но он работает только с viewportFraction: 0.8.

Вот как это выглядит сейчас: the center is not bigger as I would like to have

Это мой код с плагином ,, carousel_slider: ^ 1.4.1 '':

mport 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../classes/konto.dart';
import '../providers/account_type.dart';

class Carousel extends StatefulWidget {
  @override
  _CarouselState createState() => _CarouselState();
}

class _CarouselState extends State<Carousel> {
  @override
  Widget build(BuildContext context) {
    return Consumer<GeldKonto>(
      builder: (ctx, konto, child) => CarouselSlider.builder(
          height: MediaQuery.of(context).size.height * 0.5,
          //realPage: 1,
         aspectRatio: 16/4,
          viewportFraction: 0.4,
          initialPage: 0,
          enableInfiniteScroll: true,
          reverse: false,
          autoPlay: true,
          autoPlayInterval: Duration(seconds: 4),
          autoPlayAnimationDuration: Duration(milliseconds: 800),
          autoPlayCurve: Curves.fastOutSlowIn,
          pauseAutoPlayOnTouch: Duration(seconds: 10),
          enlargeCenterPage: true,
          scrollDirection: Axis.horizontal,
          itemCount: konto.kontos.length,
          itemBuilder: (BuildContext context, int i) {
            Map<String, Konto> kontoHier = konto.kontos;
            String key = kontoHier.keys.elementAt(i);
            return 
               Container(
                 height: 200,
                 child: Column(mainAxisAlignment: MainAxisAlignment.center ,
              children: <Widget>[
                  Text(
                    kontoHier[key].title,
                    style: Theme.of(context).textTheme.title,
                  ),
                  Container(
                    height: 150,
                    width: 150,
                    margin: EdgeInsets.all(10.0),
                    decoration: BoxDecoration(
                        color: Colors.transparent,
                        border: Border.all(
                          color: Colors.white54,
                          width: 2,
                        ),
                        shape: BoxShape.circle),
                        child: kontoHier[key].icon,
                       
                  ),
                   Text(
                    '${kontoHier[key].kontostand}',
                    style: Theme.of(context).textTheme.title,
                  ),
              ]
            ),
               );
          }),
    );
  }
}

Как сделать центр больше (два других меньше)?

Я новичок в трепетании и хотел бы услышать несколько советов:)

1 Ответ

1 голос
/ 19 февраля 2020

Используйте виджет масштаба, как показано здесь

import 'package:carousel_slider/carousel_slider.dart';
    import 'package:flutter/material.dart';

    class CArousel extends StatefulWidget {
      @override
      _CArouselState createState() => _CArouselState();
    }

    class _CArouselState extends State<CArousel> {
      int _current = 0;

      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Container(
              padding: EdgeInsets.only(top: 200),
              child: CarouselSlider.builder(
                  viewportFraction: 0.7,
                  initialPage: _current,
                  onPageChanged: (index) {
                    setState(() {
                      _current = index;
                    });
                  },
                  itemCount: 6,
                  itemBuilder: (ctx, int index) {
                    return Transform.scale(
                      scale: index == _current ? 1 : 0.8,
                      child: Container(
                        height: 400,
                        width: 300,
                        color: Colors.red,
                        child: Center(
                          child: Text(
                            "$index",
                            style: TextStyle(fontSize: 30),
                          ),
                        ),
                      ),
                    );
                  })),
        );
      }
    }
...