flutter_trianglify 0.0.7

  • Readme
  • Changelog
  • Example
  • Installing
  • new78

Trianglify for Flutter #

Build Status

Flutter widget inspired by http://qrohlf.com/trianglify/

Demo Screenshot

Installation #

Pub

Add the Package

dependencies:
  flutter_trianglify: ^0.0.6

Usage #

Cell size, variance, bleeds, color generator can be initialized from Widget:

    Trianglify(
        bleedX: 0,
        bleedY: 10,
        cellSize: 35,
        gridWidth: MediaQuery.of(context).size.width + (200 * scaleFactor),
        gridHeight: 400 * scaleFactor,
        isDrawStroke: true,
        isFillTriangle: true,
        isFillViewCompletely: false,
        isRandomColoring: false,
        generateOnlyColor: false,
        typeGrid: Trianglify.GRID_RECTANGLE,
        variance: 20,
        palette: Palette.getPalette(Palette.BLUES),
    )

Examples #

Web and command-line examples can be found in the example folder.

Web Examples #

In order to run the web examples, please follow these steps:

  1. Clone this repo and enter the directory
  2. Run pub get
  3. Run pub run build_runner serve example
  4. Navigate to http://localhost:8080/web/ in your browser

Command Line Examples #

In order to run the command line example, please follow these steps:

  1. Clone this repo and enter the directory
  2. Run pub get
  3. Run dart example/lib/trianglify_example.dart

Flutter Example #

Install Flutter #

In order to run the flutter example, you must have Flutter installed. For installation instructions, view the online documentation.

Run the app #

  1. Open up an Android Emulator, the iOS Simulator, or connect an appropriate mobile device for debugging.
  2. Open up a terminal
  3. cd into the example/lib/trianglify_example directory
  4. Run flutter doctor to ensure you have all Flutter dependencies working.
  5. Run flutter packages get
  6. Run flutter run

License #

BSD 2-Clause License

Copyright (c) 2019, Jonathan Monga
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0.0.1 #

  • TODO: Describe initial release.

example/README.md

Example for Flutter Trianglify #

    Trianglify(
        bleedX: 0,
        bleedY: 10,
        cellSize: 35,
        gridWidth: MediaQuery.of(context).size.width + (200 * scaleFactor),
        gridHeight: 400 * scaleFactor,
        isDrawStroke: true,
        isFillTriangle: true,
        isFillViewCompletely: false,
        isRandomColoring: false,
        generateOnlyColor: false,
        typeGrid: Trianglify.GRID_RECTANGLE,
        variance: 20,
        palette: Palette.getPalette(Palette.BLUES),
    )

Complete Example for Flutter Trianglify #

import 'package:flutter/material.dart';

import 'package:flutter_trianglify/flutter_trianglify.dart';

class TrianglifySample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        home: SafeArea(
          child: Material(
            child: CustomScrollView(
              slivers: [
                SliverPersistentHeader(
                  delegate: MySliverAppBar(expandedHeight: 200),
                  pinned: true,
                ),
                SliverList(
                  delegate: SliverChildBuilderDelegate(
                    (_, index) => ListTile(
                      title: Text("Index: $index"),
                    ),
                  ),
                )
              ],
            ),
          ),
        ));
  }
}

class MySliverAppBar extends SliverPersistentHeaderDelegate {
  static const double BASE_SIZE = 320.0;

  final double expandedHeight;

  MySliverAppBar({@required this.expandedHeight});

  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
        double scaleFactor = MediaQuery.of(context).size.shortestSide / BASE_SIZE;
    return Stack(
      fit: StackFit.expand,
      overflow: Overflow.visible,
      children: [
        Trianglify(
          bleedX: 0,
          bleedY: 10,
          cellSize: 35,
          gridWidth: MediaQuery.of(context).size.width + (200 * scaleFactor),
          gridHeight: 400 * scaleFactor,
          isDrawStroke: true,
          isFillTriangle: true,
          isFillViewCompletely: false,
          isRandomColoring: false,
          generateOnlyColor: false,
          typeGrid: Trianglify.GRID_RECTANGLE,
          variance: 20,
          palette: Palette.getPalette(Palette.BLUES),
        ),
        Center(
          child: Opacity(
            opacity: shrinkOffset / expandedHeight,
            child: Text(
              "MySliverAppBar",
              style: TextStyle(
                color: Colors.white,
                fontWeight: FontWeight.w700,
                fontSize: 23,
              ),
            ),
          ),
        ),
        Positioned(
          top: expandedHeight / 2 - shrinkOffset,
          left: MediaQuery.of(context).size.width / 4,
          child: Opacity(
            opacity: (1 - shrinkOffset / expandedHeight),
            child: Card(
              elevation: 10,
              child: SizedBox(
                height: expandedHeight,
                width: MediaQuery.of(context).size.width / 2,
                child: FlutterLogo(),
              ),
            ),
          ),
        ),
      ],
    );
  }

  @override
  double get maxExtent => expandedHeight;

  @override
  double get minExtent => kToolbarHeight;

  @override
  bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) => true;
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_trianglify: ^0.0.7

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_trianglify/flutter_trianglify.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
60
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
78
Learn more about scoring.

We analyzed this package on Dec 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4
  • Flutter: 1.12.13+hotfix.4

Health suggestions

Fix lib/src/trianglify_widget.dart. (-0.50 points)

Analysis of lib/src/trianglify_widget.dart reported 1 hint:

line 5 col 160: The name SizedBox is shown, but not used.

Format lib/flutter_trianglify.dart.

Run flutter format to format lib/flutter_trianglify.dart.

Format lib/src/colorizers/colorizer.dart.

Run flutter format to format lib/src/colorizers/colorizer.dart.

Fix additional 11 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/colorizers/fixed_points_colorizer.dart (Run flutter format to format lib/src/colorizers/fixed_points_colorizer.dart.)
  • lib/src/palette.dart (Run flutter format to format lib/src/palette.dart.)
  • lib/src/pattern/circle.dart (Run flutter format to format lib/src/pattern/circle.dart.)
  • lib/src/pattern/rectangle.dart (Run flutter format to format lib/src/pattern/rectangle.dart.)
  • lib/src/point.dart (Run flutter format to format lib/src/point.dart.)
  • lib/src/thread_local_random.dart (Run flutter format to format lib/src/thread_local_random.dart.)
  • lib/src/trianglify.dart (Run flutter format to format lib/src/trianglify.dart.)
  • lib/src/triangulator/delaunay_triangulator.dart (Run flutter format to format lib/src/triangulator/delaunay_triangulator.dart.)
  • lib/src/triangulator/edge_2d.dart (Run flutter format to format lib/src/triangulator/edge_2d.dart.)
  • lib/src/triangulator/triangle_2d.dart (Run flutter format to format lib/src/triangulator/triangle_2d.dart.)
  • lib/src/triangulator/triangle_soup.dart (Run flutter format to format lib/src/triangulator/triangle_soup.dart.)

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test