Flutter | Because a widget-driven development requires a widget-driven preview.

Overview


Create samples of your widgets and preview them in real time

This project is experimental but safe to use as not code is added during compilation. It won't be stable until Flutter web or desktop reaches a stable version too.

Getting Started

Install

Run the preview

  • Open a dart file in vscode and the preview button will appear

  • Click the button to launch Flutter Preview

  • If a devices is not active yet, it will ask you to select the device where you want to run Flutter Preview. Read more about how to choose a device to run Flutter Preview.

Using macos? We use the local network layer to communicate between the preview and the damenon service. Macos limits all network requets by default and so you will need to allow it during debug by adding: com.apple.security.network.client to macos/Runner/DebugProfile.entitlements

Adding a preview

A vscode snippet is availabe for creating a preview, just type preview and it will appear.

  • Create a new class that extends PreviewProvider
class MyPreview extends PreviewProvider {

  List<Preview> get previews {
    return [
      
    ];
  }
}
  • Add as many Preview widgets as samples you want to display
  List<Preview> get previews {
    return [
      Preview(
        frame: Frames.ipadPro12,
        child: MyApp(),
      ),
      Preview(
        frame: Frames.iphoneX,
        child: MyApp(),
      ),
    ];
  }

And and the examples will appear in the preview window as soon as you save your file.

They will appear there every time you come back to that file.

Taking the most of Flutter Preview

Preview Widget

The Preview widget allows you to give default values that will impact your widget inside. The current availabe values are:

  • theme: Add your app theme to see your widget with your styles.
  • height, width: Set the size you want to set to the widget in case the widget has not size specified.
  • frame: See widget in different device scenarios: an android phone? or maybe an apple watch? More than 20 models and you can create your own (This is done thanks to the amazing package device_frame built by Aloïs Deniel
  • Need more? We are working to add more in a close future: Locale, Brightness, constraints...

Also you can set a update mode for each preview from hot-reload to hot-restart;

PreviewProvider

You can use multiple classes that extend PreviewProvider and they will be displayed in different tabs.

By default the name of the tab will be the class name but you can override the title param to customize it.

Custom Providers

PreviewProvider allows you to group different Previews in a single file. While this can be enough for most, you might want to create your own previews. For that you can extend any widget that extends StatelessWidget and make it implement the mixin Previewer;

class MyCustomPreview extends StatelessWidget with Previewer {
 @override
 Widget build(BuildContext context) {
    return Container();
  }
}

It is important to add with Previewer always when extending any class, otherwise it won't be recognized by Flutter Preview.

A already built-in custom provider is ResizablePreviewProvider that gives you the freedom to resize a widget to see how it could look in different scenarios.

class Resizable extends ResizablePreviewProvider with Previewer {
  @override
  Preview get preview {
    return Preview(
      mode: UpdateMode.hotReload,
      child: MusicCard(
        title: 'Blond',
        singer: 'Frank Ocean',
        image: PreviewImage.asset('preview_assets/cover1.jpg'),
        onTap: () => {},
      ),
    );
  }
}

You can build any other previews or use any packages if you respect this two important rules

  • All preview providers except the default one needs to have with Previewer
  • They need to have an empty constructor without any params.

Let's see a cool example using the device_preview package

class DevicePreviewProvider extends StatelessWidget with Previewer {
  @override
  String get title => 'Device Preview';

  @override
  Widget build(BuildContext context) {
    return DevicePreview(
      builder: (context) => MyApp(),
    );
  }
}

Using sample assets

Adding sample assets to your flutter can increase the app without no need.

For images, you can NetworkImage as before.

But if you want to use local images, don't add them to your flutter project!

You can use PreviewImage instead.

//DON'T
AssetImage('images/example.png')

//DO
PreviewImage('debug_images/example.png')
# pubspec.yaml

assets:
  images/dart.png

Other assets will be supported soon

Something is not working as expected?

Create a new issue and I will take it a look

Comments
  • dependency conflict with freezed package

    dependency conflict with freezed package

    there is a dependency conflict with freezed package which both use freezed_annotation

    here is the error log:

    Because preview >=0.0.1+7 depends on device_frame ^0.1.0 which depends on freezed_annotation ^0.7.1, preview >=0.0.1+7 requires freezed_annotation ^0.7.1.
    So, because my_project depends on both freezed_annotation ^0.11.0+1 and preview ^0.0.8, version solving failed.
    Running "flutter pub get" in my_project...
    pub get failed (1; So, because my_project depends on both freezed_annotation ^0.11.0+1 and preview ^0.0.8, version solving failed.)
    
    opened by easazade 1
  • Bump lodash from 4.17.15 to 4.17.19 in /vscode-extension

    Bump lodash from 4.17.15 to 4.17.19 in /vscode-extension

    Bumps lodash from 4.17.15 to 4.17.19.

    Release notes

    Sourced from lodash's releases.

    4.17.16

    Commits
    Maintainer changes

    This version was pushed to npm by mathias, a new releaser for lodash since your current version.


    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump flat and mocha in /vscode-extension

    Bump flat and mocha in /vscode-extension

    Bumps flat to 5.0.2 and updates ancestor dependency mocha. These dependencies need to be updated together.

    Updates flat from 4.1.0 to 5.0.2

    Commits
    • e5ffd66 Release 5.0.2
    • fdb79d5 Update dependencies, refresh lockfile, format with standard.
    • e52185d Test against node 14 in CI.
    • 0189cb1 Avoid arrow function syntax.
    • f25d3a1 Release 5.0.1
    • 54cc7ad use standard formatting
    • 779816e drop dependencies
    • 2eea6d3 Bump lodash from 4.17.15 to 4.17.19
    • a61a554 Bump acorn from 7.1.0 to 7.4.0
    • 20ef0ef Fix prototype pollution on unflatten
    • Additional commits viewable in compare view
    Maintainer changes

    This version was pushed to npm by timoxley, a new releaser for flat since your current version.


    Updates mocha from 7.2.0 to 10.2.0

    Release notes

    Sourced from mocha's releases.

    v10.2.0

    10.2.0 / 2022-12-11

    :tada: Enhancements

    • #4945: API: add possibility to decorate ESM name before import (@​j0tunn)

    :bug: Fixes

    :book: Documentation

    v10.1.0

    10.1.0 / 2022-10-16

    :tada: Enhancements

    :nut_and_bolt: Other

    v10.0.0

    10.0.0 / 2022-05-01

    :boom: Breaking Changes

    :nut_and_bolt: Other

    ... (truncated)

    Changelog

    Sourced from mocha's changelog.

    10.2.0 / 2022-12-11

    :tada: Enhancements

    • #4945: API: add possibility to decorate ESM name before import (@​j0tunn)

    :bug: Fixes

    :book: Documentation

    10.1.0 / 2022-10-16

    :tada: Enhancements

    :nut_and_bolt: Other

    10.0.0 / 2022-05-01

    :boom: Breaking Changes

    :nut_and_bolt: Other

    ... (truncated)

    Commits

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Version issue every time

    Version issue every time

    And because flutter_cache_manager >=3.0.0-nullsafety.0 depends on http ^0.13.0 and preview >=0.0.5+2 depends on http ^0.12.0+2, cached_network_image ^3.1.0 is incompatible with preview >=0.0.5+2. So, because Vliv_B2B depends on both cached_network_image ^3.1.0 and preview ^0.0.8, version solving failed. pub get failed (1; So, because Vliv_B2B depends on both cached_network_image ^3.1.0 and preview ^0.0.8, version solving failed.) exit code 1

    opened by Ankit0080 1
  • Join forces with dashbook?

    Join forces with dashbook?

    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:

    • https://github.com/erickzanardo/dashbook
    • https://github.com/ookami-kb/storybook_flutter
    • https://github.com/ilikerobots/storyboard

    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:

    • https://github.com/jamesblasco/flutter_preview (preview any widget in vs code)
    • https://github.com/aloisdeniel/flutter_device_preview (emulate any device size)
    • https://github.com/rodydavis/storyboard (see all routes at once)

    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!

    opened by MuathAmer 0
  • I can't run the example that comes with the package

    I can't run the example that comes with the package

    Hello, I tried to run the example that comes with the package to learn how it works, but it allows gives me the following message appears in the middle of the emulator : Select a file from /lib folder to see the preview

    I tried to select files, refresh, hor reload, etc. nothing works with me. Please what I can do to run the example?

    opened by waheed11 0
Releases(v0.0.8)
Owner
Jaime Blasco
Google Developer Expert in Flutter
Jaime Blasco
A flutter app for beginners when using flutter and Dart packages to speed up development

xylophone A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if thi

Trần Văn Nguyên 1 Nov 15, 2021
This is mobile application fortune telling using Flutter for development.

Flutter Tarot Card Description: This is mobile application fortune telling using Flutter for development. How I can run it? ?? Clone this repository ?

Dao Hong Vinh 17 Sep 25, 2022
This is the semester 6 Mobile App Development Course project. So maybe the final project may not make sense ;) but it is a good place to start learning Flutter.

?? Overview MAD-Sem6 is a Mobile Development Course Project that contains Basic ➡️ Medium implementation of different widgets. As a whole it doesn't m

Muhammad Tayyab Asghar 3 Aug 9, 2021
A simple app to make Flutter development more delightful

Flutter Sidekick Sidekick is an app that provides a simple desktop interface to tools that enhance Flutter development experience to make it even more

Leo Farias 1.1k Jan 9, 2023
Chat App Development Front-End and Back-End using Flutter, SocketIo, and NodeJS. (Limited code)

Chat App Development Front-End and Back-End using Flutter, SocketIo, and NodeJS. (Limited code) ( You can buy the full code on $30 (mail me): devstack

Balram Rathore 364 Dec 31, 2022
Portfolio App using Flutter Development 💖  

??  Portfolio App Portfolio App using Flutter Development ??   ✌  Screenshot ⚡  Social Media  Instagram: @bimsp___  Facebook: @mrbrelax.56  LinkedIn:

Bimantara Sutato Putra 3 Aug 14, 2022
Flutter Development - Hybrid App Dev by Amit Maity

Flutter Development - Hybrid App Dev by Amit Maity

Amit Maity 4 Jul 3, 2022
This is a project we created for our Mobile App Development task under The Sparks Foundation Internship.

Hello everyone! This is a project we created for our Mobile App Development task under The Sparks Foundation Internship. We hope you like it!

Eyosiyas Tibebu 4 Jun 14, 2022
Flutter Widget Quiz, made for Flutter Create (Source code size is limited to 5KB)

widget_quiz The branch for Flutter Create: https://github.com/mono0926/widget-quiz/tree/5k Getting Started This project is a starting point for a Flut

Masayuki Ono (mono) 50 Oct 14, 2022
(Complete flutter application) Exam and training app as social media, prepared with Firebase backend services, Bloc State management, Singleton design pattern, Unit and widget tests, firebase mocking, Custom local libraries, etc.

(Complete flutter application) Exam and training app as social media, prepared with Firebase backend services, Bloc State management, Singleton design pattern, Unit and widget tests, firebase mocking, Custom local libraries, etc.

Ismael Shakverdiev 45 Jul 14, 2022
This app I used for my daily practice flutter widget and code from afgprogrammer.

inspiration_app A new Inspiration App Flutter project. design view Code by afgprogrammer. Getting Started This project is a starting point for a Flutt

Arief Syahroni 4 Oct 7, 2021
Wraps flutter_svg and the Flutter SDK image providers and picks the right widget based on the file extension

Hybrid Image Wraps flutter_svg and the Flutter SDK image providers and picks the right widget based on the file extension Features As of right now it'

Dutch Coding Company 1 Jun 18, 2022
Simple Counter App in Flutter with unit, widget and integration tests

Simple Counter App in Flutter with unit, widget and integration tests

Guilherme Haddad 0 Nov 12, 2021
Flutter widget example.

Flutter examples Here you can find some Flutter examples. Development Setup Clone the repository and run the following commands: flutter pub get flutt

Mohammad Rahmani 355 Dec 27, 2022
FTFS is a Flutter package which uses a TextField Widget to search and select a value from a list

FTFS is a Flutter package which uses a TextField Widget to search and select a value from a list. It's a simple, lightweight, and fully tested package unlike other "autocomplete" or textfield search packages.

null 1 Jan 5, 2022
UnDraw is a Flutter widget that provides 700+ illustrations

undraw/UnDraw UnDraw is a Flutter widget that provides 700+ illustrations, designed by Katerina Limpitsouni and developed by westdabestdb. Getting Sta

Görkem Erol 118 Oct 12, 2022
Flutter_weather_forecast - A weather forecast widget for Turkey

Flutter_weather_forecast - A weather forecast widget for Turkey.Weather data provided by the General Directorate of Meteorology.

emre 7 Nov 2, 2022
Flutter Responsive Game of Thrones Flutter App Flutter Responsive Game of Thrones Flutter App

got_2019 A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this

Pawan Kumar 16 Jun 9, 2022