Skip to content

Commit

Permalink
sec
Browse files Browse the repository at this point in the history
  • Loading branch information
apps-transround committed Apr 12, 2021
1 parent b98ccaf commit 4bc56a8
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 105 deletions.
30 changes: 12 additions & 18 deletions lib/cell_widget_paint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,18 @@ class CellWidgetPaint extends StatelessWidget {

@override
Widget build(BuildContext context) {
return SmartWidget(
key: Key('cont$row - $column'),
child: Container(
width: width,
height: height,
decoration: BoxDecoration(
color: fancy ? Colors.green.shade100 : Colors.red.shade100,
border: Border(
top: BorderSide(),
)),
child: SmartWidget(
key: Key('$row - $column'),
child: Text(
'Dummy cell content: $row - $column',
// style: Theme.of(context).textTheme.bodyText2,
),
)),
);
return Container(
width: width,
height: height,
decoration: BoxDecoration(
color: fancy ? Colors.green.shade100 : Colors.red.shade100,
border: Border(
top: BorderSide(),
)),
child: Text(
'Dummy cell content: $row - $column',
// style: Theme.of(context).textTheme.bodyText2,
));
// return Container(
// width: width,
// height: height,
Expand Down
17 changes: 17 additions & 0 deletions lib/demo_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ class _DemoControlState extends State<DemoControl> {
Widget build(BuildContext context) {
return Row(
children: [
Padding(
padding: const EdgeInsets.only(left: 16.0),
child: DropdownButton<LogLevel>(
onChanged: (value) {
setState(() {
debugRepaintLogLevel = value ?? LogLevel.none;
});
},
items: LogLevel.values.map<DropdownMenuItem<LogLevel>>((LogLevel value) {
return DropdownMenuItem<LogLevel>(
value: value,
child: Text((value.toString())),
);
}).toList(),
value: debugRepaintLogLevel,
),
),
Expanded(
child: ExpansionTile(
title: SizedBox(
Expand Down
42 changes: 42 additions & 0 deletions lib/expensive_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'dart:math';

import 'package:flutter/material.dart';

class ExpensiveWidget extends StatelessWidget {
final double width, height;

const ExpensiveWidget({Key? key, this.width = 100, this.height = 100}) : super(key: key);

@override
Widget build(BuildContext context) {
return Container(
width: width,
height: height,
decoration: BoxDecoration(color: Colors.orange),
child: CustomPaint(
painter: ShapesPainter(width, height),
),
);
}
}

class ShapesPainter extends CustomPainter {
final double count = 20;
final double width, height;
final painter = Paint();

ShapesPainter(this.width, this.height);

@override
void paint(Canvas canvas, Size size) {
Random random = new Random();
for (int j = 0; j < count; j++) {
painter.color = Color((random.nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
canvas.drawLine(Offset(random.nextDouble() * width, random.nextDouble() * height),
Offset(random.nextDouble() * width, random.nextDouble() * height), painter);
}
}

@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}
5 changes: 5 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:scroll_test/paintEvent.dart';
import 'package:scroll_test/rotate.dart';
import 'package:scroll_test/scroll.dart';
import 'package:scroll_test/two_way_scroll_widget.dart';

void main() {
// debugPaintLayerBordersEnabled = true;
debugRepaintRainbowEnabled = true;
debugRepaintLogLevel = LogLevel.full;
runApp(
MaterialApp(
home: RotateTest(),
Expand Down
5 changes: 3 additions & 2 deletions lib/paintEvent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import 'package:rxdart/rxdart.dart';

enum PlaybackMode { none, run, pause, stop }
enum EventMode { record, playback, interactive, none }
enum LogLevel { full, benchmark, indicator, none }

const Map<PaintEventType, Color> colorsMap = {
PaintEventType.paintChild: Colors.deepOrange,
PaintEventType.paintChild: Color(0xFF0D47A1),// Colors.blue.shade700,
PaintEventType.paintBoundary: Colors.deepPurple,
PaintEventType.markPaintBoundary: Colors.blue,
PaintEventType.markPaintBoundary: Colors.indigoAccent,
PaintEventType.markPaintUp: Colors.amber,
PaintEventType.markPaintRoot: Colors.grey,
};
Expand Down
113 changes: 63 additions & 50 deletions lib/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,11 @@
// return;
// assert(() {
// if (debugRepaintRainbowEnabled) {
// final Paint paint = Paint()
// ..style = PaintingStyle.stroke
// ..strokeWidth = 6.0
// ..color = debugCurrentRepaintColor.toColor();
// canvas.drawRect(estimatedBounds.deflate(3.0), paint);
// // final Paint paint = Paint()
// // ..style = PaintingStyle.stroke
// // ..strokeWidth = 6.0
// // ..color = debugCurrentRepaintColor.toColor();
// // canvas.drawRect(estimatedBounds.deflate(3.0), paint);
// }
// if (debugPaintLayerBordersEnabled) {
// final Paint paint = Paint()
Expand Down Expand Up @@ -2391,23 +2391,23 @@
// void debugPaintPaintInfo(PaintingContext context, Offset offset) {
// if ([
// 'RenderSemanticsAnnotations',
// 'RenderPadding',
// '_RenderInkFeatures',
// 'RenderSemanticsGestureHandler',
// 'RenderExcludeSemantics',
// 'RenderBlockSemantics',
// '_RenderInkFeatures',
// 'RenderPointerListener',
// 'RenderMouseRegion',
// '_RenderInputPadding',
// 'RenderPositionedBox',
// 'RenderAbsorbPointer',
// 'RenderIgnorePointer',
// 'RenderExcludeSemantics',
// 'RenderBlockSemantics',
// 'RenderConstrainedBox',
// 'RenderMouseRegion',
// '_RenderInputPadding',
// 'RenderPadding',
// // 'RenderPositionedBox',
// // 'RenderConstrainedBox',
// ].contains(this.runtimeType.toString()))
// return;
//
// // print(this.runtimeType.toString());
// int i = 0;
// print(this.runtimeType.toString());
// int i = -1;
// // paintEvents.forEach((element) {
// // final p1 = Offset(i * 5 + delta, 0);
// // final p2 = Offset(i * 5 + delta, 4);
Expand All @@ -2417,55 +2417,68 @@
// // context.canvas.drawLine(offset + p1, offset + p2, paint);
// // i++;
// // });
//
//
// if (this is RenderRepaintBoundary) {
// int asymPC = (this as RenderRepaintBoundary).debugAsymmetricPaintCount + 1;
// int symPC = (this as RenderRepaintBoundary).debugSymmetricPaintCount + 1;
// int fraction = (asymPC / (asymPC + symPC) * 8).round() + 1;
//
// paintText(context, Offset.zero, ' $asymPC / $symPC', textColor: judgementColorMap[fraction] ?? Color(0xFFFF0000));
//
// // final textStyle = TextStyle(
// // color: judgementColorMap[fraction] ?? Color(0xFFFF0000),
// // fontSize: 14,
// // );
// // final textSpan = TextSpan(
// // text: ' $asymPC / $symPC',
// // style: textStyle,
// // );
// // final textPainter = TextPainter(
// // text: textSpan,
// // textDirection: TextDirection.ltr,
// // );
// // textPainter.layout(
// // minWidth: 0,
// // maxWidth: 80,
// // );
// // context.canvas.drawRRect(
// // RRect.fromRectAndRadius(Rect.fromLTWH(0.0, 0.0, 60, 20), Radius.circular(4.0)),
// // Paint()
// // ..strokeCap = StrokeCap.round
// // ..color = Color(0xFF000000));
// // textPainter.paint(context.canvas, this.paintBounds.topLeft);
// final Paint paint = Paint()
// ..style = PaintingStyle.stroke
// ..strokeWidth = 2.0
// ..color = judgementColorMap[fraction] ?? Color(0xFFa0a0a0);
// context.canvas.drawRect(Rect.fromLTWH(offset.dx, offset.dy,
// paintBounds.width, paintBounds.height)
// , paint);
// } //else {
// i = 1;
// eventssMap.forEach((key, value) {
// if ((value) != 0) {
// paintText(context, Offset(offset.dx, offset.dy + i * 20), ' ${key
// .toString()
// .split('.')
// .last
// .substring(0, 4)}: ${value.toString()}', backgroundColor: colorsMap[key] ?? Color(0xFFFF0000));
// i++;
// }
// }); // final Paint paint = Paint()
//
// if (debugRepaintLogLevel == LogLevel.full)
// paintData(context, offset, i);
// // eventssMap.forEach((key, value) {
// // // if ((value) != 0) {
// // paintText(context, Offset(offset.dx, offset.dy + i * 20), ' ${key
// // .toString()
// // .split('.')
// // .last
// // .substring(0, 4)}: ${value.toString()}', backgroundColor: colorsMap[key] ?? Color(0xFFFF0000));
// // i++;
// // // }
// // }); // final Paint paint = Paint()
// delta = delta == 0 ? 8 : delta - 1;
// // }
// }
//
// void paintIndicator(PaintingContext context, Offset offset, int i, double limit, int value) {
// final Paint paint = Paint()
// ..style = PaintingStyle.stroke
// ..strokeWidth = 2.0
// ..color = judgementColorMap[value] ?? Color(0xFFa0a0a0);
// context.canvas.drawRect(Rect.fromLTWH(offset.dx, offset.dy,
// paintBounds.width, paintBounds.height)
// , paint);
//
// }
// void paintData(PaintingContext context, Offset offset, int i) {
// if (this is RenderRepaintBoundary) {
// paintText(context, Offset(offset.dx, offset.dy + i * 20),
// // ' ${key.toString().split('.').last.substring(0, 4)}: '
// ' ${(eventssMap[PaintEventType.paintBoundary]?? 0).toString()} / ${(eventssMap[PaintEventType.markPaintBoundary] ?? 0).toString()} ',
// backgroundColor: colorsMap[PaintEventType.paintBoundary] ?? Color(0xFFFF0000));
//
// } else
// paintText(context, Offset(offset.dx, offset.dy + i * 20),
// ' ${(eventssMap[PaintEventType.paintChild] ?? 0).toString()} / ${(eventssMap[PaintEventType.markPaintUp]?? 0).toString() } ',
// backgroundColor: colorsMap[PaintEventType.paintChild] ?? Color(0xFFFF0000));
//
// }
//
// void paintText(PaintingContext context, Offset offset, String text, {Color backgroundColor = const Color(
// 0xFF000000), Color textColor = const Color(0xFFFFFFFF)}) {
// final textStyle = TextStyle(
// color: Color(0xFFFFFFFF),
// color: textColor,
// fontSize: 14,
// );
// final textSpan = TextSpan(
Expand All @@ -2479,7 +2492,7 @@
// textPainter.layout(
// );
// context.canvas.drawRRect(
// RRect.fromRectAndRadius(Rect.fromLTWH(offset.dx, offset.dy, 80, 20), Radius.circular(4.0)),
// RRect.fromRectAndRadius(Rect.fromLTWH(offset.dx, offset.dy, textPainter.width, 20), Radius.circular(8.0)),
// Paint()
// ..strokeCap = StrokeCap.round
// ..color = backgroundColor);
Expand Down
23 changes: 15 additions & 8 deletions lib/rotate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:scroll_test/demo_control.dart';
import 'package:scroll_test/expensive_widget.dart';
import 'package:scroll_test/paintEvent.dart';

void main() => runApp(const MyApp());
Expand Down Expand Up @@ -76,21 +77,23 @@ class _RotateTestState extends State<RotateTest> with TickerProviderStateMixin {
// ),
// ],
// ),
DemoControl(),
RepaintBoundary(child: Text('A')),
DemoControl(),
// CustomPaint(
// size: Size(100, 20),
// painter: PaintMarker(),
// ),
ExpensiveWidget(
width: 240,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('SMArt'),
child: Text('Tap logos to rotate'),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('A'),
child: Text('With RepaintBoundary'),
),
// CustomPaint(
// size: Size(100, 20),
// painter: PaintMarker(),
// ),

Center(
child: RepaintBoundary(
child: GestureDetector(
Expand All @@ -112,6 +115,10 @@ class _RotateTestState extends State<RotateTest> with TickerProviderStateMixin {
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('Without RepaintBoundary'),
),
Center(
child: SizedBox(
width: 100,
Expand Down
21 changes: 12 additions & 9 deletions lib/scroll.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:scroll_test/playback_control.dart';
import 'package:scroll_test/smart_widget.dart';
import 'package:scroll_test/two_way_scroll_widget.dart';

import 'demo_control.dart';

/// This is the stateful widget that the main application instantiates.
class ScrollPaintTest extends StatefulWidget {
const ScrollPaintTest({Key? key}) : super(key: key);
Expand All @@ -32,15 +34,16 @@ class _ScrollPaintTestState extends State<ScrollPaintTest> with TickerProviderSt
body: Column(
mainAxisSize: MainAxisSize.max,
children: [
PlaybackControl(
onRecord: () {
setState(() {});
iterate(leftScrollController);
},
onPlay: () {
setState(() {});
},
),
// PlaybackControl(
// onRecord: () {
// setState(() {});
// iterate(leftScrollController);
// },
// onPlay: () {
// setState(() {});
// },
// ),
DemoControl(),
TwoWayScroll(
scrollController: leftScrollController,
rowCount: rowCount,
Expand Down
Loading

0 comments on commit 4bc56a8

Please sign in to comment.