|9| Transform Slider
Transform Slider:
import 'dart:math'; import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: MyHome(), ); } } class MyHome extends StatefulWidget { @override _MyHomeState createState() => _MyHomeState(); } class _MyHomeState extends State<MyHome> { PageController pageController; double viewportFraction = 0.8; double pageOffset = 0; @override void initState() { super.initState(); pageController = PageController(initialPage: 0, viewportFraction: viewportFraction) ..addListener(() { setState(() { pageOffset = pageController.page; }); }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Transform Slider"), backgroundColor: Colors.pink, ), backgroundColor: Colors.blueGrey, body:PageView.builder( controller: pageController, itemBuilder: (context, index) { double scale = max(viewportFraction, (1 - (pageOffset - index).abs()) + viewportFraction); double angle = (pageOffset - index).abs(); if (angle > 0.5) { angle = 1 - angle; } return Container( padding: EdgeInsets.only(right: 10, left: 20, top: 100 - scale * 25, bottom: 50), child: Transform( transform: Matrix4.identity() ..setEntry(3, 2, 0.001) ..rotateY(angle), alignment: Alignment.center, child: Image.asset( 'images/logo.jpg', fit: BoxFit.contain, ), ), ); }, itemCount: 5, ), ); } }
Comments
Post a Comment