2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2015-07-16 18:54:25 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-10-10 03:44:52 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/rendering.dart';
|
2015-07-16 18:54:25 +00:00
|
|
|
|
2016-02-13 08:52:56 +00:00
|
|
|
import '../rendering/src/solid_color_box.dart';
|
2015-07-16 18:54:25 +00:00
|
|
|
|
2019-05-25 02:13:02 +00:00
|
|
|
// Solid color, RenderObject version
|
2018-06-05 06:50:40 +00:00
|
|
|
void addFlexChildSolidColor(RenderFlex parent, Color backgroundColor, { int flex = 0 }) {
|
2018-09-12 06:29:29 +00:00
|
|
|
final RenderSolidColorBox child = RenderSolidColorBox(backgroundColor);
|
2015-07-16 18:54:25 +00:00
|
|
|
parent.add(child);
|
2020-10-22 20:33:07 +00:00
|
|
|
final FlexParentData childParentData = child.parentData! as FlexParentData;
|
2015-10-21 18:17:03 +00:00
|
|
|
childParentData.flex = flex;
|
2015-07-16 18:54:25 +00:00
|
|
|
}
|
|
|
|
|
2019-05-25 02:13:02 +00:00
|
|
|
// Solid color, Widget version
|
2016-03-12 20:13:16 +00:00
|
|
|
class Rectangle extends StatelessWidget {
|
2020-10-22 20:33:07 +00:00
|
|
|
const Rectangle(this.color, { Key? key }) : super(key: key);
|
2016-03-14 20:31:43 +00:00
|
|
|
|
2015-07-16 18:54:25 +00:00
|
|
|
final Color color;
|
2016-03-14 20:31:43 +00:00
|
|
|
|
|
|
|
@override
|
2015-10-21 18:17:03 +00:00
|
|
|
Widget build(BuildContext context) {
|
2018-09-12 06:29:29 +00:00
|
|
|
return Expanded(
|
|
|
|
child: Container(
|
2017-04-27 21:19:01 +00:00
|
|
|
color: color,
|
2019-03-01 07:17:55 +00:00
|
|
|
),
|
2015-07-16 18:54:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-22 20:33:07 +00:00
|
|
|
double? value;
|
|
|
|
RenderObjectToWidgetElement<RenderBox>? element;
|
2018-09-12 06:29:29 +00:00
|
|
|
BuildOwner owner = BuildOwner();
|
2015-10-21 18:17:03 +00:00
|
|
|
void attachWidgetTreeToRenderTree(RenderProxyBox container) {
|
2018-09-12 06:29:29 +00:00
|
|
|
element = RenderObjectToWidgetAdapter<RenderBox>(
|
2015-10-21 18:17:03 +00:00
|
|
|
container: container,
|
2018-09-12 06:29:29 +00:00
|
|
|
child: Directionality(
|
2017-09-07 23:57:38 +00:00
|
|
|
textDirection: TextDirection.ltr,
|
2018-09-12 06:29:29 +00:00
|
|
|
child: Container(
|
2017-09-07 23:57:38 +00:00
|
|
|
height: 300.0,
|
2018-09-12 06:29:29 +00:00
|
|
|
child: Column(
|
2017-09-07 23:57:38 +00:00
|
|
|
children: <Widget>[
|
2018-08-02 10:02:32 +00:00
|
|
|
const Rectangle(Color(0xFF00FFFF)),
|
2018-09-12 06:29:29 +00:00
|
|
|
Material(
|
|
|
|
child: Container(
|
2017-09-07 23:57:38 +00:00
|
|
|
padding: const EdgeInsets.all(10.0),
|
|
|
|
margin: const EdgeInsets.all(10.0),
|
2018-09-12 06:29:29 +00:00
|
|
|
child: Row(
|
2017-09-07 23:57:38 +00:00
|
|
|
children: <Widget>[
|
2020-09-16 15:02:06 +00:00
|
|
|
ElevatedButton(
|
2018-09-12 06:29:29 +00:00
|
|
|
child: Row(
|
2017-09-07 23:57:38 +00:00
|
|
|
children: <Widget>[
|
2019-04-05 18:39:30 +00:00
|
|
|
Image.network('https://flutter.dev/images/favicon.png'),
|
2017-09-07 23:57:38 +00:00
|
|
|
const Text('PRESS ME'),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
onPressed: () {
|
2020-10-22 20:33:07 +00:00
|
|
|
value = value == null ? 0.1 : (value! + 0.1) % 1.0;
|
2017-09-07 23:57:38 +00:00
|
|
|
attachWidgetTreeToRenderTree(container);
|
|
|
|
},
|
2016-01-16 00:38:10 +00:00
|
|
|
),
|
2018-09-12 06:29:29 +00:00
|
|
|
CircularProgressIndicator(value: value),
|
2017-09-07 23:57:38 +00:00
|
|
|
],
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2018-08-02 10:02:32 +00:00
|
|
|
const Rectangle(Color(0xFFFFFF00)),
|
2017-09-07 23:57:38 +00:00
|
|
|
],
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2016-03-28 20:02:03 +00:00
|
|
|
).attachToRenderTree(owner, element);
|
2015-07-16 18:54:25 +00:00
|
|
|
}
|
|
|
|
|
2020-10-22 20:33:07 +00:00
|
|
|
Duration? timeBase;
|
|
|
|
late RenderTransform transformBox;
|
2015-07-16 18:54:25 +00:00
|
|
|
|
2015-10-03 17:55:25 +00:00
|
|
|
void rotate(Duration timeStamp) {
|
2017-04-07 19:41:17 +00:00
|
|
|
timeBase ??= timeStamp;
|
2020-10-22 20:33:07 +00:00
|
|
|
final double delta = (timeStamp - timeBase!).inMicroseconds.toDouble() / Duration.microsecondsPerSecond; // radians
|
2015-07-16 18:54:25 +00:00
|
|
|
|
|
|
|
transformBox.setIdentity();
|
|
|
|
transformBox.rotateZ(delta);
|
2016-09-28 08:06:32 +00:00
|
|
|
|
2020-10-22 20:33:07 +00:00
|
|
|
owner.buildScope(element!);
|
2015-07-16 18:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
2017-03-04 02:04:27 +00:00
|
|
|
final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized();
|
2018-09-12 06:29:29 +00:00
|
|
|
final RenderProxyBox proxy = RenderProxyBox();
|
2015-10-21 18:17:03 +00:00
|
|
|
attachWidgetTreeToRenderTree(proxy);
|
2015-07-16 18:54:25 +00:00
|
|
|
|
2018-09-12 06:29:29 +00:00
|
|
|
final RenderFlex flexRoot = RenderFlex(direction: Axis.vertical);
|
2016-02-11 02:11:03 +00:00
|
|
|
addFlexChildSolidColor(flexRoot, const Color(0xFFFF00FF), flex: 1);
|
2015-07-16 18:54:25 +00:00
|
|
|
flexRoot.add(proxy);
|
2016-02-11 02:11:03 +00:00
|
|
|
addFlexChildSolidColor(flexRoot, const Color(0xFF0000FF), flex: 1);
|
2015-07-16 18:54:25 +00:00
|
|
|
|
2018-09-12 06:29:29 +00:00
|
|
|
transformBox = RenderTransform(child: flexRoot, transform: Matrix4.identity(), alignment: Alignment.center);
|
|
|
|
final RenderPadding root = RenderPadding(padding: const EdgeInsets.all(80.0), child: transformBox);
|
2015-07-16 18:54:25 +00:00
|
|
|
|
2016-04-21 23:06:51 +00:00
|
|
|
binding.renderView.child = root;
|
|
|
|
binding.addPersistentFrameCallback(rotate);
|
2015-07-16 18:54:25 +00:00
|
|
|
}
|