|
| 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 'package:flutter/material.dart'; |
| 6 | + |
| 7 | +/// Macrobenchmark page reproducing the text shadow scrolling workload from |
| 8 | +/// https://github.com/flutter/flutter/issues/190395. |
| 9 | +class TextShadowPerfPage extends StatefulWidget { |
| 10 | + const TextShadowPerfPage({super.key}); |
| 11 | + |
| 12 | + @override |
| 13 | + State<TextShadowPerfPage> createState() => _TextShadowPerfPageState(); |
| 14 | +} |
| 15 | + |
| 16 | +class _TextShadowPerfPageState extends State<TextShadowPerfPage> |
| 17 | + with SingleTickerProviderStateMixin { |
| 18 | + late final ScrollController _scrollController; |
| 19 | + late final AnimationController _animationController; |
| 20 | + |
| 21 | + @override |
| 22 | + void initState() { |
| 23 | + super.initState(); |
| 24 | + _scrollController = ScrollController(); |
| 25 | + _animationController = AnimationController(vsync: this, duration: const Duration(seconds: 10)) |
| 26 | + ..repeat(reverse: true); |
| 27 | + _animationController.addListener(_onAnimationTick); |
| 28 | + } |
| 29 | + |
| 30 | + void _onAnimationTick() { |
| 31 | + if (_scrollController.hasClients && _scrollController.position.maxScrollExtent > 0) { |
| 32 | + _scrollController.jumpTo( |
| 33 | + _animationController.value * _scrollController.position.maxScrollExtent, |
| 34 | + ); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + @override |
| 39 | + void dispose() { |
| 40 | + _animationController.removeListener(_onAnimationTick); |
| 41 | + _animationController.dispose(); |
| 42 | + _scrollController.dispose(); |
| 43 | + super.dispose(); |
| 44 | + } |
| 45 | + |
| 46 | + @override |
| 47 | + Widget build(BuildContext context) { |
| 48 | + const columnCount = 7; |
| 49 | + const groupsPerColumn = 28; |
| 50 | + |
| 51 | + return Scaffold( |
| 52 | + backgroundColor: const Color(0xff080808), |
| 53 | + body: ScrollConfiguration( |
| 54 | + behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false), |
| 55 | + child: SingleChildScrollView( |
| 56 | + controller: _scrollController, |
| 57 | + child: Row( |
| 58 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 59 | + children: List<Widget>.generate(columnCount, (int column) { |
| 60 | + return Expanded( |
| 61 | + child: Padding( |
| 62 | + padding: const EdgeInsets.all(6), |
| 63 | + child: Column( |
| 64 | + crossAxisAlignment: CrossAxisAlignment.stretch, |
| 65 | + children: List<Widget>.generate(groupsPerColumn, (int row) { |
| 66 | + return _TextShadowGroup(index: column * groupsPerColumn + row); |
| 67 | + }), |
| 68 | + ), |
| 69 | + ), |
| 70 | + ); |
| 71 | + }), |
| 72 | + ), |
| 73 | + ), |
| 74 | + ), |
| 75 | + ); |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +class _TextShadowGroup extends StatelessWidget { |
| 80 | + const _TextShadowGroup({required this.index}); |
| 81 | + |
| 82 | + final int index; |
| 83 | + |
| 84 | + static const List<Shadow> _shadows = <Shadow>[Shadow(blurRadius: 1.0)]; |
| 85 | + |
| 86 | + @override |
| 87 | + Widget build(BuildContext context) { |
| 88 | + return SizedBox( |
| 89 | + height: 230, |
| 90 | + child: Align( |
| 91 | + alignment: Alignment.bottomLeft, |
| 92 | + child: Padding( |
| 93 | + padding: const EdgeInsets.all(12), |
| 94 | + child: Column( |
| 95 | + mainAxisSize: MainAxisSize.min, |
| 96 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 97 | + children: <Widget>[ |
| 98 | + Text( |
| 99 | + 'Synthetic text item $index', |
| 100 | + maxLines: 2, |
| 101 | + overflow: TextOverflow.ellipsis, |
| 102 | + style: const TextStyle( |
| 103 | + color: Colors.white, |
| 104 | + fontSize: 10, |
| 105 | + fontWeight: FontWeight.bold, |
| 106 | + shadows: _shadows, |
| 107 | + ), |
| 108 | + ), |
| 109 | + Row( |
| 110 | + children: <Widget>[ |
| 111 | + Text( |
| 112 | + '${8 + index % 14}:30', |
| 113 | + style: const TextStyle( |
| 114 | + color: Color(0xff43ddff), |
| 115 | + fontSize: 9, |
| 116 | + fontWeight: FontWeight.bold, |
| 117 | + shadows: _shadows, |
| 118 | + ), |
| 119 | + ), |
| 120 | + const Spacer(), |
| 121 | + Text( |
| 122 | + 'Ep ${1 + index % 24}', |
| 123 | + style: const TextStyle(color: Colors.white70, fontSize: 9, shadows: _shadows), |
| 124 | + ), |
| 125 | + ], |
| 126 | + ), |
| 127 | + ], |
| 128 | + ), |
| 129 | + ), |
| 130 | + ), |
| 131 | + ); |
| 132 | + } |
| 133 | +} |
0 commit comments