Git Product home page Git Product logo

flutter_flow_chart's Introduction

Flutter Flow Chart

A package that let you draw a flow chart diagram with different kind of customizable elements. Dashboards can be saved for later use.

Image

See online example here

Features

  • diamond, rectangle, oval, storage, parallelogram elements
  • elements can be customizable with background, border and text color, border thickness, text size and weight.
  • interactively connect elements
  • save/load dashboard

Usage

First create a Dashboard:

Dashboard dashboard = Dashboard(
    blockDefaultZoomGestures: false,    // optional
    handlerFeedbackOffset: Offset.zero, // optional
    minimumZoomFactor: 1.25,            // optional
    onScaleUpdate: (newScale) {},        // optional
);

then crete the [FlowChart] widget where you can react to the user interactions:

FlowChart(
    dashboard: dashboard,
    onDashboardTapped: ((context, position) {}),
    onDashboardLongtTapped: ((context, position) {}),
    onElementLongPressed: (context, element) {},
    onElementPressed: (context, element) {},
    onHandlerPressed: (context, position, handler, element) {},
    onHandlerLongPressed: (context, position, handler, element) {},
)

then use the dashboard variable to add, remove, resize etc. elements or load/save the dashboard.

In the example, the StarMenu package is used to easily interact with user inputs.

The Dashboard

The Dashboard object contains all the methods described below used to interact with the flow chart.

relevant methods description
setGridBackgroundParams set grid background parameters
setHandlerFeedbackOffset set the feedback offset to help on mobile device to see the end of arrow and not hiding behind the finger when moving it
setElementResizable set the element as resizable. A handle will be displayed on the bottom right and will disappear when finish resizing
addElement add a FlowElement to the dashboard
removeAllElements remove all elements
removeElementConnection remove the given handler connection of the given element
removeElementConnections remove all the connections from the given element
removeElementById remove all the elements with the given id from the dashboard
removeElement remove the given element
addNextById make a connection from the given sourceElement to the elements with the given id
recenter Recenter the dashboard relative to the first element in the element array
saveDashboard save the dashboard into the given file path
loadDashboard clear the dashboard and load the new one
setZoomFactor Zoom the entire dashboard and content by the given factor corresponding to the given epicenter

The FlowElement

The FlowElement defines the element kind with its position, size, colors and so on.

properties type description
position Offset The position of the FlowElement
size Size The size of the FlowElement
text String Element text
textColor Color Text color
fontFamily String Text font family
textSize double Text size
textIsBold bool Makes text bold if true
kind ElementKind Element shape: enum {rectangle, diamond, storage, oval, parallelogram}
handlers List Connection handlers: enum {topCenter, bottomCenter, rightCenter, leftCenter}
handlerSize Size The size of element handlers
backgroundColor Size Background color of the element
borderColor Size Border color of the element
borderThickness Size Border thickness of the element
elevation Size Shadow elevation
next List Shadow elevation
relevant methods description
setIsResizing When setting to true, a handler will disply at the element bottom right to let the user to resize it. When finish it will disappear.
setText Set element text
setTextColor Set text color
setTextSize Set text size
setTextIsBold Set text bold
setBackgroundColor Set background color
setBorderColor Set border color
setBorderThickness Set border thickness
setElevation Set elevation
changePosition Change element position in the dashboard
changeSize Change element size

Examples

Add an element to Dashboard

Dashboard dashboard = Dashboard();

///////////////////////////////////
/// Define 2 elements
FlowElement element1 = FlowElement(
    /// position in the local dashboard coordinates
    position: const Offset(100, 100),
    /// element size
    size: const Size(100, 100),
    /// text to show
    text: 'diamond',
    /// rectangle, diamond, storage, oval or parallelogram element kind
    kind: ElementKind.diamond,
    /// which handler to make active
    handlers: [
        Handler.bottomCenter,
        Handler.topCenter,
        Handler.leftCenter,
        Handler.rightCenter,
    ]);
FlowElement element2 = FlowElement(
    position: const Offset(300, 100),
    size: const Size(100, 150),
    text: 'rect',
    kind: ElementKind.rectangle,
    handlers: [
        Handler.bottomCenter,
        Handler.topCenter,
        Handler.leftCenter,
        Handler.rightCenter,
    ]);
///////////////////////////////////
/// Add the element to Dashboard
dashboard.addElement(element);

///////////////////////////////////
/// Connect right handler of element1
/// to the left handler of element2
dashboard.addNextById(
    element1,
    element2.id,
    ArrowParams(
        thickness: 1.5,
        color: Colors.Black,
        startArrowPosition: Alignment.centerRight,
        endArrowPosition: Alignment.centerLeft,
    ),
);

///////////////////////////////////
/// Save/load dashboard
Directory appDocDir =
    await path.getApplicationDocumentsDirectory();

dashboard.saveDashboard('${appDocDir.path}/FLOWCHART.json');

dashboard.loadDashboard('${appDocDir.path}/FLOWCHART.json');

flutter_flow_chart's People

Contributors

alnitak avatar gitgudyyao avatar hansbak avatar malcolmmielle avatar ofbozkurt avatar sl-pirate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

flutter_flow_chart's Issues

Canvas move and zoom

Due to the limited screen of mobile devices, is it possible to add the function of moving and zooming the canvas?

Canvas Zoom

I've seen that on issue #5 was asked to add zoom feature of the canvas.
Was it added? I can't find references to it.

add custom data to an element

Hi, pretty package you have here!
I am looking to use this flowchart editor as a 'workflow' editor for BPMN type of workflow for just the basics.

Therefore it would be nice to be able to add custom data to connections and elements,

When the generated flowchart could be loaded into the flutter flowbuilder dart package, we could use this flowchart package as a business process modelling tool.

any thoughts about this?
Regards,
Hans

Zoom issues/new features

About zoom feature:
-I've seen that arrow black dots are not resized as expected
-callback for onScaleUpdate would be useful to manage zoom gesture (on web i can't zoom with the mouse neither with the keyboard)
-if dashboard has a fixed size when zooming in and out the sizes of the dashboard are not updated so i see the element inside the dashboard resized correcly but the dashboard keeps same size

Pdf download of dashboard

Is it possible to download the pdf version of the dashboard created? i think it would be useful to export and be able to print the canvas.

Change arrow style

It's a very nice package! Would it be possible to add an example on how to change the arrow style?

Add {bool notify = true} to `removeElement`

image
I was using this package to build a chart which addNextById automatically when adding or remove elements, it is better to add {bool notify = true} to removeElement fuction. Just an advice.

reopening issue as I see the same behavior - keyboard window closes before I can type anything

          Hello @alnitak ,

Apologies for not responding sooner.

I believe you are correct, StarMenu is still leading to problems.

I just updated all my Flutter packages (picked up the new update), and though I don't see the same exception, I still see the same behavior (i.e., the keyboard window closes before I can type anything).

For now, the current exception is the following:

======== Exception caught by scheduler library =====================================================
E/flutter (31108): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:flutter/src/widgets/overlay.dart': Failed assertion: line 161 pos 12: '_overlay != null': is not true.
E/flutter (31108): #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
E/flutter (31108): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
The following assertion was thrown during a scheduler callback:
Cannot get renderObject of inactive element.
E/flutter (31108): #2 OverlayEntry.remove (package:flutter/src/widgets/overlay.dart:161:12)

Thank you for all your help.

Originally posted by @bl12345 in #2 (comment)

Text Editor Bug/Crash

Hello Marco,

We notice when using your flutter_flow_chart, that when attempting to input text into an object, the editor quickly closes (before we can input any text), due to the following exception (see below):

Note: The exception below can cause the flutter app (consisting solely of your code example) to crash (please see attached video Bug-Crash.mp4 for more information).

Bug-Crash.mp4

`======== Exception caught by scheduler library ==============================================
The following assertion was thrown during a scheduler callback:
Cannot get renderObject of inactive element.

In order for an element to have a valid renderObject, it must be active, which means it is part of the tree.
Instead, this element is in the _ElementLifecycle.defunct state.
If you called this method from a State object, consider guarding it with State.mounted.
The findRenderObject() method was called for the following element: StatefulElement#6d185(DEFUNCT)
no widget
When the exception was thrown, this was the stack:
#0 Element.findRenderObject. (package:flutter/src/widgets/framework.dart:4093:9)
#1 Element.findRenderObject (package:flutter/src/widgets/framework.dart:4106:6)
#2 StarMenuState._showMenu (package:star_menu/src/star_menu.dart:387:36)
#3 StarMenuState.showMenu (package:star_menu/src/star_menu.dart:375:7)
#4 StarMenuState.resetForChanges (package:star_menu/src/star_menu.dart:236:7)
#5 StarMenuState.didChangeMetrics. (package:star_menu/src/star_menu.dart:221:7)
#6 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1175:15)
#7 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1113:9)
#8 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1015:5)
#9 _invoke (dart:ui/hooks.dart:148:13)
#10 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:318:5)
#11 _drawFrame (dart:ui/hooks.dart:115:31)
==============================================================================`

Thank you for any help you can provide.

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.