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
    with TickerProviderStateMixin {


  Animation 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.
    );
  }
}

你可能感兴趣的:(flutter,flutter)