blob: 2e7378f6a438891f1ee7d03c6c6cb4028ce6b847 [file] [log] [blame]
Emmanuel Garciaa3c6e4a2020-03-18 13:24:52 -07001// 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
5import 'dart:io';
6
7import 'package:flutter/material.dart';
8import 'package:flutter/scheduler.dart' show timeDilation;
9
10void main() {
11 runApp(
Emmanuel Garciab1760422020-04-28 19:24:15 -070012 const PlatformViewApp()
Emmanuel Garciaa3c6e4a2020-03-18 13:24:52 -070013 );
14}
15
16class PlatformViewApp extends StatefulWidget {
Emmanuel Garciab1760422020-04-28 19:24:15 -070017 const PlatformViewApp({
Michael Goderbauer195a1cc2022-03-29 12:52:42 -070018 super.key,
19 });
Emmanuel Garciab1760422020-04-28 19:24:15 -070020
Emmanuel Garciaa3c6e4a2020-03-18 13:24:52 -070021 @override
22 PlatformViewAppState createState() => PlatformViewAppState();
Emmanuel Garciaa3c6e4a2020-03-18 13:24:52 -070023}
24
25class 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 Garciaa3c6e4a2020-03-18 13:24:52 -070042class PlatformViewLayout extends StatelessWidget {
Michael Goderbauer195a1cc2022-03-29 12:52:42 -070043 const PlatformViewLayout({ super.key });
Emmanuel Garciaa3c6e4a2020-03-18 13:24:52 -070044
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
72class DummyPlatformView extends StatelessWidget {
Michael Goderbauer195a1cc2022-03-29 12:52:42 -070073 const DummyPlatformView({super.key});
Emmanuel Garciaa3c6e4a2020-03-18 13:24:52 -070074
75 @override
76 Widget build(BuildContext context) {
77 const String viewType = 'benchmarks/platform_views_layout/DummyPlatformView';
Michael Goderbauer99b9ec82021-02-09 10:06:08 -080078 late Widget nativeView;
Emmanuel Garciaa3c6e4a2020-03-18 13:24:52 -070079 if (Platform.isIOS) {
80 nativeView = const UiKitView(
81 viewType: viewType,
82 );
83 } else if (Platform.isAndroid) {
Chris Yangc5a69b92020-07-22 18:36:11 -070084 nativeView = const AndroidView(
85 viewType: viewType,
86 );
Emmanuel Garciaa3c6e4a2020-03-18 13:24:52 -070087 } 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
98class RotationContainer extends StatefulWidget {
Michael Goderbauer195a1cc2022-03-29 12:52:42 -070099 const RotationContainer({super.key});
Emmanuel Garciaa3c6e4a2020-03-18 13:24:52 -0700100
101 @override
Michael Goderbauerb8a24562021-05-10 16:26:16 -0700102 State<RotationContainer> createState() => _RotationContainerState();
Emmanuel Garciaa3c6e4a2020-03-18 13:24:52 -0700103}
104
105class _RotationContainerState extends State<RotationContainer>
106 with SingleTickerProviderStateMixin {
Michael Goderbauer99b9ec82021-02-09 10:06:08 -0800107 late AnimationController _rotationController;
Emmanuel Garciaa3c6e4a2020-03-18 13:24:52 -0700108
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}