Giter VIP home page Giter VIP logo

flutter_storybook's Introduction

flutter_storybook

Storybooks for Flutter.

Run on macOS for fast development or the web to share results.

Easily have golden tests for all your stories.

Early development.

Getting Started

  • Install 'flutter_storybook' TODO: how to install

  • Create another target file

// lib/stories.dart

import 'package:flutter/foundation.dart'
    show debugDefaultTargetPlatformOverride;
import 'package:flutter/material.dart';
import 'package:flutter_storybook/flutter_storybook.dart';

void main() {
  // Only needed for macOS
  // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override
  debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;

  runApp(
    // Use StoryApp, a MaterialApp wrapper
    StoryApp(
      stories: [
        SmallCardStory(),
      ],
    ),
  );
}


// Extend StoryBase to be able to use the hooks
// and have the type checker make sure name is implemented.
class SmallCardStory extends StoryBase {
  // This is the unique id and display text of this story
  @override
  String get name => 'Small Card';

  @override
  Widget build(BuildContext context) {
    // only bool, int and String knobs are supported
    final bool online = useKnob(false, 'Online');
    final int age = useKnob(55, 'Age');
    final String name = useKnob('Jhon', 'Name');

    // use action will log it to the actions pannel
    final void Function(String) logStars = useAction('Gave Star');

    // go to another story
    final void Function() goToMore = useStory('Big Card');

    // Remember to return a StoryPage
    return StoryPage(
      builder: (BuildContext context) =>
        // SmallCard is any custom widget
        SmallCard(
          online: online,
          age: age,
          name: name,
          onStarsPressed: (int stars) => logStars('$stars'),
          seeMore: goToMore,
        ),
    );
  }
}
  • Run it

macOS

$ flutter run -d macOS -t lib/stories.dart

web

$ flutter run -d chrome -t lib/stories.dart

Golden Tests

// lib/golden.dart
import 'package:flutter_storybook/flutter_storybook.dart';

void main() async {
  await loadDefaultGoldenFonts();
  goldenStories(
    stories: [
      SmallCardStory(),
    ],
  );
}

Run it

$ flutter test lib/golden.dart

flutter_storybook's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.