Flutter实现图片自动放大,超出屏幕部分裁剪

 

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

class Segment1Page extends StatefulWidget {
  Segment1Page({Key key}) : super(key: key);

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

class _Segment1PageState extends State<Segment1Page>
    with TickerProviderStateMixin {


  Animation<double> tween;
  AnimationController controller;

  @override
  void initState() {
    super.initState();

    /*创建动画控制类对象*/
    controller = new AnimationController(
        duration: const Duration(milliseconds: 5000),
        vsync: this);

    /*创建补间对象*/
    tween = new Tween(begin: 0.0, end: 1.0)
        .animate(controller)    //返回Animation对象
      ..addListener(() {        //添加监听
        setState(() {
          print(tween.value);   //打印补间插值
        });
      });
    Future.delayed(const Duration(seconds: 2),(){
      controller.forward();
    });

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [Container(
          width: MediaQuery.of(context).size.width,
          height:MediaQuery.of(context).size.height ,
          child: ClipRect(
              child: Transform.scale(
                scale: (tween.value*4)+1,
                child: Image.asset(
                  'assets/animate/p1.jpg',
                  fit: BoxFit.cover,
                  height: 200,
                ),
              )),
        )

        ],
      ),   // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值