update example
This commit is contained in:
@@ -9,3 +9,7 @@
|
|||||||
## 1.0.2
|
## 1.0.2
|
||||||
|
|
||||||
- Again update README ( -\_-)
|
- Again update README ( -\_-)
|
||||||
|
|
||||||
|
## 1.0.3
|
||||||
|
|
||||||
|
- Update example
|
||||||
|
|||||||
@@ -11,11 +11,14 @@ class SimpleExample extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SimpleExampleState extends State<SimpleExample> {
|
class _SimpleExampleState extends State<SimpleExample> {
|
||||||
final LazyCanvasController controller = LazyCanvasController(debug: true, buildCacheExtent: const Offset(50, 50));
|
late final LazyCanvasController controller;
|
||||||
final List<CanvasChildId> childIds = [];
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
final cacheExtent = const Offset(50, 50);
|
||||||
|
controller = LazyCanvasController(debug: true, buildCacheExtent: cacheExtent);
|
||||||
|
final List<CanvasChildId> childIds = [];
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
final id = controller.addChild(
|
final id = controller.addChild(
|
||||||
@@ -30,7 +33,8 @@ class _SimpleExampleState extends State<SimpleExample> {
|
|||||||
);
|
);
|
||||||
childIds.add(id);
|
childIds.add(id);
|
||||||
}
|
}
|
||||||
controller.addChild(
|
|
||||||
|
final trackId = controller.addChild(
|
||||||
const Offset(0, 200),
|
const Offset(0, 200),
|
||||||
Container(
|
Container(
|
||||||
width: 300,
|
width: 300,
|
||||||
@@ -52,6 +56,8 @@ class _SimpleExampleState extends State<SimpleExample> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
controller.addChild(const Offset(330, 200), _PositionTracker(controller: controller, childId: trackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -97,3 +103,94 @@ class InfoContainer extends StatelessWidget {
|
|||||||
return Container(color: color, width: 50, height: 50);
|
return Container(color: color, width: 50, height: 50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _PositionTracker extends StatefulWidget {
|
||||||
|
final LazyCanvasController controller;
|
||||||
|
final CanvasChildId childId;
|
||||||
|
const _PositionTracker({required this.controller, required this.childId});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_PositionTracker> createState() => _PositionTrackerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PositionTrackerState extends State<_PositionTracker> {
|
||||||
|
late final VoidCallback _listener;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_listener = () {
|
||||||
|
if (mounted) setState(() {});
|
||||||
|
};
|
||||||
|
widget.controller.addListener(_listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
widget.controller.removeListener(_listener);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final childPosition = widget.controller
|
||||||
|
.widgetsWithScreenPositions()
|
||||||
|
.where((e) => e.id == widget.childId)
|
||||||
|
.firstOrNull;
|
||||||
|
|
||||||
|
final visible = childPosition != null;
|
||||||
|
final borderColor = visible ? Colors.green : Colors.red;
|
||||||
|
final icon = visible ? Icons.visibility : Icons.visibility_off;
|
||||||
|
final statusText = visible ? 'Visible' : 'Off screen';
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.surface,
|
||||||
|
border: Border(left: BorderSide(color: borderColor, width: 4)),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
boxShadow: [BoxShadow(color: Colors.black.withAlpha(10), blurRadius: 8, offset: const Offset(0, 2))],
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'This example uses tight build extents so you can see the text box get unmounted when its position ( top left ) goes off screen.\nIncrease it in your app.',
|
||||||
|
style: TextStyle(fontSize: 13, color: Theme.of(context).colorScheme.onSurface),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(icon, size: 16, color: borderColor),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Text(
|
||||||
|
statusText,
|
||||||
|
style: TextStyle(color: borderColor, fontWeight: FontWeight.w600),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
'Cache extent: ${widget.controller.buildCacheExtent}',
|
||||||
|
style: TextStyle(color: Theme.of(context).colorScheme.onSurface, fontSize: 13),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 6),
|
||||||
|
if (visible)
|
||||||
|
Text(
|
||||||
|
'Text box position: ${childPosition.ssPosition}',
|
||||||
|
style: TextStyle(color: Theme.of(context).colorScheme.onSurface, fontSize: 13),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
const Text('Text box is off screen', style: TextStyle(fontSize: 13)),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Text(
|
||||||
|
'Note: due to spatial hashing the offset is an approximate, not a pixel-perfect measure.',
|
||||||
|
style: TextStyle(fontSize: 11, color: Theme.of(context).colorScheme.onSurface.withAlpha(200)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+1
-41
@@ -25,14 +25,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.4.0"
|
version: "1.4.0"
|
||||||
charcode:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: charcode
|
|
||||||
sha256: fb0f1107cac15a5ea6ef0a6ef71a807b9e4267c713bb93e00e92d737cc8dbd8a
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.4.0"
|
|
||||||
clock:
|
clock:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -57,14 +49,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.6"
|
version: "3.0.6"
|
||||||
csslib:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: csslib
|
|
||||||
sha256: "09bad715f418841f976c77db72d5398dc1253c21fb9c0c7f0b0b985860b2d58e"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.0.2"
|
|
||||||
cupertino_icons:
|
cupertino_icons:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -107,21 +91,13 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
html:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: html
|
|
||||||
sha256: "6d1264f2dffa1b1101c25a91dff0dc2daee4c18e87cd8538729773c073dbf602"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "0.15.6"
|
|
||||||
infinite_lazy_grid:
|
infinite_lazy_grid:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: ".."
|
path: ".."
|
||||||
relative: true
|
relative: true
|
||||||
source: path
|
source: path
|
||||||
version: "0.0.1"
|
version: "1.0.2"
|
||||||
leak_tracker:
|
leak_tracker:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -255,22 +231,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.4.0"
|
version: "1.4.0"
|
||||||
universal_html:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: universal_html
|
|
||||||
sha256: "56536254004e24d9d8cfdb7dbbf09b74cf8df96729f38a2f5c238163e3d58971"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.2.4"
|
|
||||||
universal_io:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: universal_io
|
|
||||||
sha256: "1722b2dcc462b4b2f3ee7d188dad008b6eb4c40bbd03a3de451d82c78bba9aad"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.2.2"
|
|
||||||
uuid:
|
uuid:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ class LazyCanvasController with ChangeNotifier {
|
|||||||
Offset get _ssCenter => Offset(_canvasSize.width / 2, _canvasSize.height / 2);
|
Offset get _ssCenter => Offset(_canvasSize.width / 2, _canvasSize.height / 2);
|
||||||
Offset get _gsCenter => ssToGs(_ssCenter, _gsTopLeftOffset, _scale);
|
Offset get _gsCenter => ssToGs(_ssCenter, _gsTopLeftOffset, _scale);
|
||||||
bool get _renderCacheDirty => _lastProcessedOffset != _gsTopLeftOffset || _lastProcessedScale != _scale || _markDirty;
|
bool get _renderCacheDirty => _lastProcessedOffset != _gsTopLeftOffset || _lastProcessedScale != _scale || _markDirty;
|
||||||
|
Offset get buildExtent => _buildExtent;
|
||||||
|
Offset? get buildCacheExtent => _buildCacheExtent;
|
||||||
|
|
||||||
// ==================== Callback Functions ====================
|
// ==================== Callback Functions ====================
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
name: infinite_lazy_grid
|
name: infinite_lazy_grid
|
||||||
description: "infinitely scrollable and zoomable grid layout with lazy loading capabilities."
|
description: "infinitely scrollable and zoomable grid layout with lazy loading capabilities."
|
||||||
version: 1.0.2
|
version: 1.0.3
|
||||||
homepage: https://github.com/ruinivist/infinite_lazy_grid
|
homepage: https://github.com/ruinivist/infinite_lazy_grid
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
Reference in New Issue
Block a user