Giter VIP home page Giter VIP logo

dashbook's Introduction

Dashbook

dashbook

Dashbook is a UI development tool for Flutter, it works as a development enviroment for the project widgets and also a showcase for common widgets on the app, it is heavly inspired by Storybook library, so it should be very easy for people who has already used Storybook, to use Dashbook.

It currently supports both mobile and web, having a friendly layout built to work nice on web and large resolutions.

Have any questions or ideas? Join our Discord.

How to use

Add the dependency to your pubspec.yaml

flutter pub add dashbook

Tip โ„น๏ธ: If you use mason, a basic Dashbook brick called dashbook_gallery is available in brickhub.dev, which creates a basic gallery in seconds.

A Dashbook instance has a collection of the app widgets (Stories) and its variants (Chapters). Here you can see a very simple example of how to use it.

import 'package:flutter/material.dart';

import 'package:dashbook/dashbook.dart';

void main() {
  final dashbook = Dashbook();

  // Adds the Text widget stories
  dashbook
      .storiesOf('Text')
      // Decorators are easy ways to apply a common layout to all of the story chapters, here are using onde of Dashbook's decorators,
      // which will center all the widgets on the center of the screen
      .decorator(CenterDecorator())
      // The Widget story can have as many chapters as needed
      .add('default', (ctx) {
        return Container(width: 300, child: Text(
          ctx.textProperty("text", "Text Example"),
          textAlign: ctx.listProperty(
              "text align",
              TextAlign.center,
              TextAlign.values,
          ),
          textDirection: ctx.listProperty(
              "text direction",
              TextDirection.rtl,
              TextDirection.values,
          ),
          style: TextStyle(
              fontWeight: ctx.listProperty(
                  "font weight",
                  FontWeight.normal,
                  FontWeight.values,
              ),
              fontStyle: ctx.listProperty(
                  "font style",
                  FontStyle.normal,
                  FontStyle.values,
              ),
              fontSize: ctx.numberProperty("font size", 20)),
        ));
      });

  dashbook
      .storiesOf('RaisedButton')
      .decorator(CenterDecorator())
      .add('default', (ctx) => RaisedButton(child: Text('Ok'), onPressed: () {}));

  // Since dashbook is a widget itself, you can just call runApp passing it as a parameter
  runApp(dashbook);
}

Actions

Dashbook also provides a way for easily calling methods from its UI, these callbacks can be used for more complex examples which demands user interaction.

For example, a Dialog is something that isn't directly rendered on a page, but rather shows upon an action, an example for a CustomDialog widget could be achieved on Dashbook by using the following code:

final dashbook = Dashbook();

dashbook
  .storiesOf('CustomDialog')
  .add('default', (ctx) {
    ctx.action('Open dialog', (context) {
      showDialog(
        context: context,
        builder: (_) => CustomDialog(),
      );
    });

    return SizedBox();
  });

Example information

Often an example may not be intuitive enough and the user may be lost without some instruction on how to interact with it. To mitigate that, text information can be linked to an example to serve as a guide, or to show any other relevant information.

To do so, simply use the info parameter on the add method of a story:

final dashbook = Dashbook();

dashbook
  .storiesOf('CustomDialog')
  .add('default',
    (ctx) {
      ctx.action('Open dialog', (context) {
        showDialog(
          context: context,
          builder: (_) => CustomDialog(),
        );
      });

      return SizedBox();
    },
    info: 'Use the actions button on the side to show the dialog.',
  );

This will present a small i icon on the side toolbar that once clicked will present the information to the user.

Dashbook also offers the possibility to directly show the information on the preview area, removing the necessity for the user to click on the icon. To do so, pass true to the pinInfo parameter.

final dashbook = Dashbook();

dashbook
  .storiesOf('CustomDialog')
  .add('default',
    (ctx) {
      // omitted ...
    },
    info: 'Use the actions button on the side to show the dialog.',
    pinInfo: true,
  );

Preview area

By default Dashbook will provide the whole screen area for the preview, which means that its controll icons will appear floating above the example.

That behavior can be changed with the use of the usePreviewSafeArea parameter on Dashbook constructors, when setting this parameter to true, Dashbook will make sure that its icons will not appear floating above the example creating a safe area for the example preview.

Managing themes

Dashbook offers three of ways to let you change themes when viewing your stories. Dashbook iteself is built to use the provided theme to stylize its own UI, so whatever theme is provided, the Dashbook UI show works nice.

Single theme

Using the default constructor of the Dashbook, use the optional theme parameter to set the theme.

final dashbook = Dashbook(theme: ThemeData());

Dual theme

When your app has two theme, the dualTheme constructor can be used. Two parameters light and dark can be informed to set which ThemeData represents a light theme, and which represents the dark theme, an additional parameter initWithLight can be used to tell Dashbook which theme should be used initially (defaults to true).

When using this, Dashbook will present an icon for the user to toggle between light and dark themes

final dashbook = Dashbook.dualTheme(
  light: YourLightTheme(),
  dark: YourDarkTheme(),
);

Multiple themes

When an app have more than two themes, the multiTheme contructor can be used. It receives a themes parameter, which is a Map<String, ThemeData>, and an optional parameter initialTheme to inform which theme should be used initially (defaults to the first entry of the map).

When using this, Dashbook will present an icon, which shows a modal with a dropdown menu to enable the user to choose between the informed themes

final dashbook = Dashbook.multiTheme(
  themes: {
    'theme1': Theme1(),
    'theme2': Theme2(),
    'theme3': Theme3(),
  }
);

Visibility control properties

Some more complex Widgets may feature several fields, which can lead to a very long list of properties which will in turn can create a confusing example.

This can be improved by the use of visibility control properties. This API allows a property to be shown or hidden according to the value of another property.

For example, let's imagine a Widget which can show both an information and an error message, controlled by a property called type, this widget also allows the user to customize both the error and information color, with visibility control properties the error color property can be shown only when the type is error.

Example:

dashbook.storiesOf('MessageCard').decorator(CenterDecorator()).add(
    'default',
    (ctx) => MessageCard(
        message: ctx.textProperty('message', 'Some cool message'),
        type: ctx.listProperty('type', MessageCardType.info, MessageCardType.values),
        errorColor: ctx.colorProperty(
            'errorColor',
            const Color(0xFFCC6941),
            // this property will only be shown when type is error
            visibilityControlProperty: ControlProperty('type', MessageCardType.error),
        ),
        infoColor: ctx.colorProperty(
            'infoColor',
            const Color(0xFF5E89FF),
            // this property will only be shown when type is info
            visibilityControlProperty: ControlProperty('type', MessageCardType.info),
        ),
    ),
);

Example

dashbook_13

Structure

Dashbook is just a widget, so it can be ran in any way wanted, as there is no required structure that must be followed, although, we do recommend the following approach:

  • Create a file named main_dashbook.dart on the root source of your project (e.g. lib/main_dashbook.dart)
  • Create the Dashbook instance inside that file, calling the runApp method in the end (look on the example above)
  • Run it with the command flutter run -t lib/main_dashbook.dart

dashbook's People

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

dashbook's Issues

Upgrading dependencies

Right now there are some dependencies that are not updated, which is blocking us from upgrading the freezed-package to the stable version by depending on dashbook. Is it possible to fix this? device_frame in particular:

image

dartdoc support

One useful feature of Storybook is the Docs tab which supports components or MDX.

I feel like one potential way to support this in dashbook is to load the dart docs in an iframe (if web) or a webview (if mobile). Each story could accept a dartDocUrl.

colorProperty is closing the page in Flutter Web

I'm trying to use colorProperty to let users change some widgets color.
The color picker is opened correctly with default color, but when I try to change the color and confirm in "Got it" button, the background page is closed instead of color picker modal.

This is how I'm using the colorProperty:

final bool customize = dc.boolProperty('Customize colors', false);
final Color backgroundColor = dc.colorProperty(
      'backgroundColor',
      Colors.grey,
      visibilityControlProperty: ControlProperty('Customize colors', true),
);

This is what's happening:
Screen Recording 2022-06-18 at 01 45 15 PM

File Structure

๐Ÿ‘‹ Thanks for creating this package. So far it has been super easy and quick to get it running on the few widgets I have created for my project.

I am new to flutter/dart so forgive the beginner question.

I am wondering if there is a way to setup the file structure so that not all the chapters have to be in the same class?

Move device properties to side panel instead of pop-up

Adding interactive side panel device info settings would make it possible for users to quickly try out different device settings.

My idea is something akin to this:
image

If you agree that this is a good idea, you can assign me as I'm taking a stab at this ๐Ÿ‘

Dashbook.dualTheme() doesn't assign any value to the variable theme

Description

I'm trying to access the theme from dashbook and I started receiving null pointers. And them I realised that the constructor Dashbook.dualTheme doesn't assign any value to the variable theme.

This scenario works as expected

final dashbook = Dashbook(
    theme: BahagTheme.light,
  );

dashbook.storiesOf('Colors').decorator(CenterDecorator()).add(
        'Foundation',
        (context) => Padding(
          padding: const EdgeInsets.all(20.0),
          child: Column(
            children: [
              Text(
                'COLORS',
                style: dashbook.theme!.textTheme.headline1!
                    .copyWith(fontSize: 28, color: Colors.black),
              ),

This scenario doesn't work as expected

final dashbook = Dashbook.dualTheme(
    light: BahagTheme.light,
    dark: BahagTheme.dark,
  );

dashbook.storiesOf('Colors').decorator(CenterDecorator()).add(
        'Foundation',
        (context) => Padding(
          padding: const EdgeInsets.all(20.0),
          child: Column(
            children: [
              Text(
                'COLORS',
                style: dashbook.theme!.textTheme.headline1!
                    .copyWith(fontSize: 28, color: Colors.black),
              ),

Screenshot 2022-08-29 at 17 02 01

You can see in the printscreen that the private variable _dualTheme exists with both themes assigned, but the variable theme remains unassigned.

Add navigatorKey to Dashbook

Currently I use navigator key in my app to do navigation. It would be great if the navigatorKey was exposed through Dashbook so it can be set onto the MaterialApp.

Dashbook(navigatorKey: globalNavKey, ...)

[Bug] Crash on flutter run (caused by flutter_colorpicker >= 0.5.0)

Platfrom: Linux
Flutter Version: (Channel stable, 2.2.1)
Device: Android Emulator (Pixel 3a)

Reproduction steps:

  1. Clone this repo
  2. run cd **/dashbook/example
  3. run flutter run --debug

Process exits and the following with Error message is shown:

/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_colorpicker-0.5.0/lib/src/hsv_picker.dart:730:43:
 Error: The parameter 'event' of the method 'AlwaysWinPanGestureRecognizer.addAllowedPointer' has type 
 'PointerDownEvent', which does not match the corresponding type, 'PointerEvent', in the overridden method, 
 'DragGestureRecognizer.addAllowedPointer'.

Description:
The issue is caused by color picker >= 0.5.0.
There is currently an open issue in the color picker repo.

Fix:
Downgrade flutter_colorpicker to 0.4.0

Local fix:
If you run in to this problem before this issue has been resolved in this repos package you can temporarily solve it buy adding an dependency override caluse to you pubspec.yaml, like this:

dependency_overrides:
  flutter_colorpicker: ^0.4.0

Mobile view story list resets

When viewing a story then navigating back to the list of stories, the list will reset losing any scroll position and chapters become un-expanded. This gets annoying when you have a large set of stories and chapters since you have to scroll down everytime to get to the chapter you want.

During development you will be most likely working on a single chapter at a time so being able to easily go forward and back through to them would save a lot of time and frustration

Shrink side bar to fit content

Currently the side bar with all of the stories fill up a large part of the screen, we should shrink it to the content that is inside of it.

Properties list do not render correctly

I think there's a bug with properties list..

I'm using dual theme option and the properties list appears just if I change the theme.

Changing between components have the same issue. Always need to change theme once.

Add option to have the navigation panel always open

Currently navigating through multiple examples is tedious because you need to open the navigation panel every time and find the next example in the list.
An option where the navigation panel could remain always open would make this process much easier.

Dynamic Properties

It would be nice to have dynamic properties that become visible or hidden based on another property.

For instance, you can have a type property that drives subsequent properties that are visible, such as an additional label only present if that type were selected.

Change Preview Tab to include Widget with Code View

We have actually started using this and feel like it's a nice feature to bake into dashbook.

Poached from flutter_catelog. It allows developers to view a preview of the widget but then also see the source code for that widget.

Here is the library that we are currently using in tandem with dashbook.

[HELP] I need some help with custom font/icons in Flutter Web

I'm deploying our Dashbook with Flutter Web, but I'm facing some problems with fonts and custom icons (.ttf)

Building with flutter build web the font-family is Ok, but our font icons don't load.
image

Building with flutter build web --web-renderer html our icons are loaded correctly, but the font-family is wrong...
image

@erickzanardo have you had some problem like this?
I'd searched a lot and couldn't find a solution...

Ability to set viewport directly from canvas screen.

On the canvas/preview screen in storybook, users can select the viewport size. It would be nice to have this feature in dashbook. Here's an example:

Screen Shot 2021-01-21 at 11 36 57 PM

The options provided are:

  • Reset (default)
  • Small mobile
  • Large mobile
  • Tablet

Selecting a viewport shrinks the canvas viewport size. I think this helps usability because the developer no longer has to shrink the browser (if they are using chrome) or open devtools.

Add option to draw Info panel and the bottom and pin it

Currently it is only possible to access the information about a particular example through a small (i) icon in the top-right corner, which presents several challenges:

  • the user may not be aware of this feature,
  • navigating from one side of the screen to another is too much work (esp. if you want to read the description of every example),
  • the info panel opens as an overlay, obscuring the example itself -- this means it is difficult to compare the text of the description with what is being actually rendered on the screen.

As a solution to these problems, I suggest a new option where the info panel would be rendered at the bottom part of the screen (the option could also allow to control how much of screen's estate to spend on that panel). The panel should also be "sticky": its visibility should not change when switching between examples.

Navigation?

We use dashbook as a fullscreen widget
How do we add navigation bar to it?

Support alias for listProperty options

Hi

I'm working on a component that receives a prefix/suffix widget. I was trying to add a short set of example widgets to show how this parameter affects the component.

The problem is the options doesn't have an alias, so they are rendered like this:
image

prefix: context.listProperty(
        'prefix',
        null,
        [
          null,
          Container(
            padding: const EdgeInsets.only(right: 8),
            child:  Icon(Icons.pin_drop, size: 16),
          ),
          Container(
            padding: const EdgeInsets.only(right: 8),
            child:  Icon(Icons.check, size: 16),
          ),
        ],
      ),

I was thinking that a simple alias can resolve this issue.

(Just an example): At the storybook_flutter package there's an Option class, where you can set an alias for each item.
(I've just migrated from this package due to some UI problems that was bothering me)

Add custom languages

There are several hardcoded texts into Dashbook.
Maybe could be added an i18n strategy to allow custom languages.

Null safety support

I'm going to submit a PR for the null safety support.

It is a common practice to keep such a code in a separate branch, i.e. null-safety, to be able to support the main release in legacy mode whilst the null safety compatible release could be released from its branch.

Please, prepare the branch for null safety support PR.

Doc Note

THis is one of the low contributors to Flutter Platform Widgets.

The way I understand how this plugin works is that I could combine this with eBay's Golden Toolkit and Flutter Platform Widgets and mock my app screens as unit tests using this plugin before the screen code is created and so I would have a fullvisual for both MaterialApp and CupertinoApp right in my GoldenTests

For those not familiar with eBay's Golden Toolkit, I am able to do scenarios with that plugin so it shouldfit right into the dashbook stuff quite well :)

Good plugin

Routing support

It would be nice if stories could be broken up by routes, so that a developer could provide links to specific stories in other resources (such as dart docs or design websites). Currently, a user would just be directed to the initial page.

This could be automatically computed from the story name, or an additional route parameter could be added to the storiesOf function.

dashbook.storiesOf('RaisedButton') // Route automatically converted to some type url friendly case.

//or

dashbook.storiesOf('RaisedButton', route: 'raised-button') // Route explicitly defined. 

The "Padding" property value might overflow

Reproduce by overriding the app theme font to something bigger and use EdgeInsets.fromLTRB as the padding value.
The pencil icon is unclickable when this happens.

Version: 0.1.13

image

Removing pubspec.lock

Came across this and thought about this project. Shouldn't the pubspec.lock be removed as this would be classified as a library package? See info here.

Large property fields do not render correctly

Looking at the 2nd property of the following example.

I have changed the list value to include a long text value to show that it does not render correctly.

A few options:

  1. DropdownMenuItem Text uses overflow ellipsis
  2. Input field rendered on a new line below label
  3. DropdownMenuItem Text is wrapped in a FittedBox causing the text to shrink.

Ability to set MediaQuery textScaleFactor

Testing gallery components for different screen sizes is easy with the device picker, but further emulating a user's device with setting a text scale factor would be a neat improvement.

I would love to take a stab at it.

Logo

Yeah, a dash reading a book IDk, this has to have a logo, please.

Join forces with storybook_flutter?

Let's make one great flutter dev-tool instead of many!

Hi! first of all, I want to say that I really appreciate the works in this open-source project, I installed it and all other similar packages, and I think it can be great if the work is unified into a single tool which can become popular and a standard for flutter development.

I will list all the projects that I found here:

These 3 have the same goal, a storybookjs inspired package to showcase flutter widgets.

But there are also these projects that if combined with a flutter storybook, can really become a standard tool for every flutter developer:

I am pasting this same issue to all of these projects, if you don't want it, feel free to close it :D

Tell me what you think!

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.