|
| 1 | +// Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'dart:async'; |
| 6 | +import 'dart:ui'; |
| 7 | +import 'package:flutter/material.dart'; |
| 8 | +import 'picture_cache.dart'; |
| 9 | + |
| 10 | +class ClipperCachePage extends StatefulWidget { |
| 11 | + const ClipperCachePage({super.key}); |
| 12 | + @override |
| 13 | + State<ClipperCachePage> createState() => _ClipperCachePageState(); |
| 14 | +} |
| 15 | + |
| 16 | +class _ClipperCachePageState extends State<ClipperCachePage> |
| 17 | + with TickerProviderStateMixin { |
| 18 | + final double _animateOffset = 100; |
| 19 | + final ScrollController _controller = ScrollController(); |
| 20 | + final bool _isComplex = true; |
| 21 | + late double _topMargin; |
| 22 | + |
| 23 | + @override |
| 24 | + void initState() { |
| 25 | + super.initState(); |
| 26 | + const double itemHeight = 140; |
| 27 | + _topMargin = (window.physicalSize.height / window.devicePixelRatio - itemHeight * 3) / 2; |
| 28 | + if (_topMargin < 0) { |
| 29 | + _topMargin = 0; |
| 30 | + } |
| 31 | + _controller.addListener(() { |
| 32 | + if (_controller.offset < 10) { |
| 33 | + _controller.animateTo(_animateOffset, duration: const Duration(milliseconds: 1000), curve: Curves.ease); |
| 34 | + } else if (_controller.offset > _animateOffset - 10) { |
| 35 | + _controller.animateTo(0, duration: const Duration(milliseconds: 1000), curve: Curves.ease); |
| 36 | + } |
| 37 | + }); |
| 38 | + Timer(const Duration(milliseconds: 500), () { |
| 39 | + _controller.animateTo(_animateOffset, duration: const Duration(milliseconds: 1000), curve: Curves.ease); |
| 40 | + }); |
| 41 | + } |
| 42 | + |
| 43 | + @override |
| 44 | + Widget build(BuildContext context) { |
| 45 | + return Scaffold( |
| 46 | + backgroundColor: Colors.blue, |
| 47 | + body: ListView( |
| 48 | + controller: _controller, |
| 49 | + children: <Widget>[ |
| 50 | + SizedBox(height: _topMargin), |
| 51 | + ClipPath( |
| 52 | + clipBehavior: Clip.antiAliasWithSaveLayer, |
| 53 | + child: _makeChild(0, _isComplex) |
| 54 | + ), |
| 55 | + ClipRect( |
| 56 | + clipBehavior: Clip.antiAliasWithSaveLayer, |
| 57 | + child: _makeChild(1, _isComplex) |
| 58 | + ), |
| 59 | + ClipRRect( |
| 60 | + clipBehavior: Clip.antiAliasWithSaveLayer, |
| 61 | + child: _makeChild(2, _isComplex) |
| 62 | + ), |
| 63 | + const SizedBox(height: 1000), |
| 64 | + ], |
| 65 | + ), |
| 66 | + ); |
| 67 | + } |
| 68 | + |
| 69 | + Widget _makeChild(int itemIndex, bool complex) { |
| 70 | + final BoxDecoration decoration = BoxDecoration( |
| 71 | + color: Colors.white70, |
| 72 | + boxShadow: const <BoxShadow>[ |
| 73 | + BoxShadow( |
| 74 | + blurRadius: 5.0, |
| 75 | + ), |
| 76 | + ], |
| 77 | + borderRadius: BorderRadius.circular(5.0), |
| 78 | + ); |
| 79 | + return RepaintBoundary( |
| 80 | + child: Container( |
| 81 | + margin: const EdgeInsets.fromLTRB(10, 5, 10, 5), |
| 82 | + decoration: complex ? decoration : null, |
| 83 | + child: ListItem(index: itemIndex), |
| 84 | + ), |
| 85 | + ); |
| 86 | + } |
| 87 | + |
| 88 | + @override |
| 89 | + void dispose() { |
| 90 | + _controller.dispose(); |
| 91 | + super.dispose(); |
| 92 | + } |
| 93 | +} |
0 commit comments