Emmanuel Garcia | a3c6e4a | 2020-03-18 13:24:52 -0700 | [diff] [blame] | 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:io'; |
| 6 | |
| 7 | import 'package:flutter/material.dart'; |
| 8 | import 'package:flutter/scheduler.dart' show timeDilation; |
| 9 | |
| 10 | void main() { |
| 11 | runApp( |
Emmanuel Garcia | b176042 | 2020-04-28 19:24:15 -0700 | [diff] [blame] | 12 | const PlatformViewApp() |
Emmanuel Garcia | a3c6e4a | 2020-03-18 13:24:52 -0700 | [diff] [blame] | 13 | ); |
| 14 | } |
| 15 | |
| 16 | class PlatformViewApp extends StatefulWidget { |
Emmanuel Garcia | b176042 | 2020-04-28 19:24:15 -0700 | [diff] [blame] | 17 | const PlatformViewApp({ |
Michael Goderbauer | 195a1cc | 2022-03-29 12:52:42 -0700 | [diff] [blame] | 18 | super.key, |
| 19 | }); |
Emmanuel Garcia | b176042 | 2020-04-28 19:24:15 -0700 | [diff] [blame] | 20 | |
Emmanuel Garcia | a3c6e4a | 2020-03-18 13:24:52 -0700 | [diff] [blame] | 21 | @override |
| 22 | PlatformViewAppState createState() => PlatformViewAppState(); |
Emmanuel Garcia | a3c6e4a | 2020-03-18 13:24:52 -0700 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | class PlatformViewAppState extends State<PlatformViewApp> { |
| 26 | @override |
| 27 | Widget build(BuildContext context) { |
| 28 | return MaterialApp( |
| 29 | theme: ThemeData.light(), |
| 30 | title: 'Advanced Layout', |
| 31 | home: const PlatformViewLayout(), |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | void toggleAnimationSpeed() { |
| 36 | setState(() { |
| 37 | timeDilation = (timeDilation != 1.0) ? 1.0 : 5.0; |
| 38 | }); |
| 39 | } |
| 40 | } |
| 41 | |
Emmanuel Garcia | a3c6e4a | 2020-03-18 13:24:52 -0700 | [diff] [blame] | 42 | class PlatformViewLayout extends StatelessWidget { |
Michael Goderbauer | 195a1cc | 2022-03-29 12:52:42 -0700 | [diff] [blame] | 43 | const PlatformViewLayout({ super.key }); |
Emmanuel Garcia | a3c6e4a | 2020-03-18 13:24:52 -0700 | [diff] [blame] | 44 | |
| 45 | @override |
| 46 | Widget build(BuildContext context) { |
| 47 | return Scaffold( |
| 48 | appBar: AppBar(title: const Text('Platform View Scrolling Layout')), |
| 49 | body: ListView.builder( |
| 50 | key: const Key('platform-views-scroll'), // This key is used by the driver test. |
| 51 | itemCount: 200, |
| 52 | itemBuilder: (BuildContext context, int index) { |
| 53 | return Padding( |
| 54 | padding: const EdgeInsets.all(5.0), |
| 55 | child: Material( |
| 56 | elevation: (index % 5 + 1).toDouble(), |
| 57 | color: Colors.white, |
| 58 | child: Stack( |
| 59 | children: const <Widget> [ |
| 60 | DummyPlatformView(), |
| 61 | RotationContainer(), |
| 62 | ], |
| 63 | ), |
| 64 | ), |
| 65 | ); |
| 66 | }, |
| 67 | ), |
| 68 | ); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | class DummyPlatformView extends StatelessWidget { |
Michael Goderbauer | 195a1cc | 2022-03-29 12:52:42 -0700 | [diff] [blame] | 73 | const DummyPlatformView({super.key}); |
Emmanuel Garcia | a3c6e4a | 2020-03-18 13:24:52 -0700 | [diff] [blame] | 74 | |
| 75 | @override |
| 76 | Widget build(BuildContext context) { |
| 77 | const String viewType = 'benchmarks/platform_views_layout/DummyPlatformView'; |
Michael Goderbauer | 99b9ec8 | 2021-02-09 10:06:08 -0800 | [diff] [blame] | 78 | late Widget nativeView; |
Emmanuel Garcia | a3c6e4a | 2020-03-18 13:24:52 -0700 | [diff] [blame] | 79 | if (Platform.isIOS) { |
| 80 | nativeView = const UiKitView( |
| 81 | viewType: viewType, |
| 82 | ); |
| 83 | } else if (Platform.isAndroid) { |
Chris Yang | c5a69b9 | 2020-07-22 18:36:11 -0700 | [diff] [blame] | 84 | nativeView = const AndroidView( |
| 85 | viewType: viewType, |
| 86 | ); |
Emmanuel Garcia | a3c6e4a | 2020-03-18 13:24:52 -0700 | [diff] [blame] | 87 | } else { |
| 88 | assert(false, 'Invalid platform'); |
| 89 | } |
| 90 | return Container( |
| 91 | color: Colors.purple, |
| 92 | height: 200.0, |
| 93 | child: nativeView, |
| 94 | ); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | class RotationContainer extends StatefulWidget { |
Michael Goderbauer | 195a1cc | 2022-03-29 12:52:42 -0700 | [diff] [blame] | 99 | const RotationContainer({super.key}); |
Emmanuel Garcia | a3c6e4a | 2020-03-18 13:24:52 -0700 | [diff] [blame] | 100 | |
| 101 | @override |
Michael Goderbauer | b8a2456 | 2021-05-10 16:26:16 -0700 | [diff] [blame] | 102 | State<RotationContainer> createState() => _RotationContainerState(); |
Emmanuel Garcia | a3c6e4a | 2020-03-18 13:24:52 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | class _RotationContainerState extends State<RotationContainer> |
| 106 | with SingleTickerProviderStateMixin { |
Michael Goderbauer | 99b9ec8 | 2021-02-09 10:06:08 -0800 | [diff] [blame] | 107 | late AnimationController _rotationController; |
Emmanuel Garcia | a3c6e4a | 2020-03-18 13:24:52 -0700 | [diff] [blame] | 108 | |
| 109 | @override |
| 110 | void initState() { |
| 111 | super.initState(); |
| 112 | _rotationController = AnimationController( |
| 113 | vsync: this, |
| 114 | duration: const Duration(seconds: 1), |
| 115 | value: 1, |
| 116 | ); |
| 117 | _rotationController.repeat(); |
| 118 | } |
| 119 | @override |
| 120 | Widget build(BuildContext context) { |
| 121 | return RotationTransition( |
| 122 | turns: Tween<double>(begin: 0.0, end: 1.0).animate(_rotationController), |
| 123 | child: Container( |
| 124 | color: Colors.purple, |
| 125 | width: 50.0, |
| 126 | height: 50.0, |
| 127 | ), |
| 128 | ); |
| 129 | } |
| 130 | } |