Giter Site home page Giter Site logo

Lazy load about bubble_lens HOT 4 OPEN

gopawe avatar gopawe commented on July 26, 2024
Lazy load

from bubble_lens.

Comments (4)

gopawe avatar gopawe commented on July 26, 2024 1

Thank you !

from bubble_lens.

jtkeyva avatar jtkeyva commented on July 26, 2024

@gopawe i asked asked a while back but no activity. i'm gonna have a crack at it but not sure the outcome because it's not a typical list/grid

from bubble_lens.

gopawe avatar gopawe commented on July 26, 2024

@jtkeyva , please let me know if you find a solution. I will highly appreciate

from bubble_lens.

jtkeyva avatar jtkeyva commented on July 26, 2024

@gopawe
this is a start but InteractiveViewer absorbs all GestureDetector so haven't figtured out how to make each circle tappable. Also, haven't figured out how to scale them. But it is essentially an infinite list of images in all directions. There's a bug where every other column disappears too early along the edge too...

Let me know if you make any progress on this, thanks.

import 'package:flutter/material.dart';
import 'package:vector_math/vector_math_64.dart' show Quad, Vector3;

void main() {
  runApp(IVBuilderExampleApp());
}

class IVBuilderExampleApp extends StatelessWidget {
  const IVBuilderExampleApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('IV Builder Example'),
        ),
        body: _IVBuilderExample(),
      ),
    );
  }
}

class _IVBuilderExample extends StatefulWidget {
  const _IVBuilderExample({Key? key}) : super(key: key);

  @override
  State<_IVBuilderExample> createState() => _IVBuilderExampleState();
}

class _IVBuilderExampleState extends State<_IVBuilderExample> {
  static const double _cellSize = 80.0;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: LayoutBuilder(
        builder: (BuildContext context, BoxConstraints constraints) {
          return InteractiveViewer.builder(
            minScale: .5,
            maxScale: 10,
            boundaryMargin: const EdgeInsets.all(double.infinity),
            builder: (BuildContext context, Quad viewport) {
              return _TableBuilder(
                cellSize: _cellSize,
                viewport: axisAlignedBoundingBox(viewport),
                builder: (BuildContext context, int row, int column) {
                  final bool isStaggeredRow = row % 2 != 0;
                  final double offsetX = isStaggeredRow ? _cellSize / 2 : 0;
                  final double offsetY = 0;

                  return Positioned(
                    left: column * _cellSize + offsetX,
                    top: row * _cellSize + offsetY,
                    child: GestureDetector(
                      onTap: () {
                        print('Tapped: $row x $column');
                      },
                      child: Container(
                        height: _cellSize,
                        width: _cellSize,
                        decoration: BoxDecoration(
                          image: DecorationImage(image: NetworkImage('https://picsum.photos/300?rando={$row * 100 * $column}')),
                          color: (row + column) % 2 == 0
                              ? Colors.white
                              : Colors.grey.withOpacity(0.1),
                          shape: BoxShape.circle,
                        ),
                        child: Center(
                          child: Text('$row x $column'),
                        ),
                      ),
                    ),
                  );
                },
              );
            },
          );
        },
      ),
    );
  }

  Rect axisAlignedBoundingBox(Quad quad) {
    double xMin = quad.point0.x;
    double xMax = quad.point0.x;
    double yMin = quad.point0.y;
    double yMax = quad.point0.y;
    for (final Vector3 point in <Vector3>[
      quad.point1,
      quad.point2,
      quad.point3,
    ]) {
      if (point.x < xMin) {
        xMin = point.x;
      } else if (point.x > xMax) {
        xMax = point.x;
      }

      if (point.y < yMin) {
        yMin = point.y;
      } else if (point.y > yMax) {
        yMax = point.y;
      }
    }

    return Rect.fromLTRB(xMin, yMin, xMax, yMax);
  }
}

typedef _CellBuilder = Widget Function(BuildContext context, int row, int column);

class _TableBuilder extends StatelessWidget {
  const _TableBuilder({
    required this.cellSize,
    required this.viewport,
    required this.builder,
  });

  final double cellSize;
  final Rect viewport;
  final _CellBuilder builder;

  @override
  Widget build(BuildContext context) {
    final int firstRow = (viewport.top / cellSize).floor();
    final int lastRow = (viewport.bottom / cellSize).ceil();
    final int firstCol = (viewport.left / cellSize).floor();
    final int lastCol = (viewport.right / cellSize).ceil();

    return SizedBox(
      width: 1,
      height: 1,
      child: Stack(
        clipBehavior: Clip.none,
        children: <Widget>[
          for (int row = firstRow; row < lastRow; row++)
            for (int col = firstCol; col < lastCol; col++)
              builder(context, row, col),
        ],
      ),
    );
  }
}

from bubble_lens.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.