So I was working on SwiftUI last week and found the #Preview feature which is similar to the @Preview feature in Jetpack Compose. So I thought it would be great to have this feature in Flutter in-build DevTool as well. Although we can argue that hot-reload is fast enough to make this all work, but here are the reasons I would love to have them:
Prototype a small widget in isolation: This is especially helpful in big projects where you need to design a small widget that is deeply embedded within a user workflow. In order to test with hot-reload, you need to go through that workflow and test it. There are tool like Storybooks, but then I would have to create all my reusable theme and style components to be there and also keep them up to date.
Live test with different inherited models: SwiftUI provides a .environment modifier which takes the model we want to use in our SwiftUI View. A similar idea could be used in Flutter for an InheritedWidget or a third-party package that supports it.
Interaction in small widgets: The #Preview feature in SwiftUI is interactive. I can test small UI changes easily in the preview itself. Like show/hide and toggles.
I am aware that there are some third-party packages available for similar things, but they require some additional Dart code to set up inside the app.
I also recommend WidgetBook. You get a list of all widgets prepared for preview, can switch locals, devices, change texts, bools, select from option lists and more. Is quite convenient for developing widgets in isolation.
Yes, I am aware of that. I think it’s good for prototyping in isolation, but what I am really talking about is the ability to prototype within my codebase using existing styles I have and also the core UI components I have in the codebase.
Apparently, you can have your widgetbook as part of your app, or even adjacent to your app in a monorepo (makes splitting out for re-use later easier). And when you do that, your widgetbook can adopt the Themes etc from the host project.
I am working on a project where we use Monarch. It’s easy to setup, it’s similar to React’s StoryBook (and I guess WidgetBook), the code can reside in your app repo in a stories/ directory and reference your themes and so forth. Not sure what preview offers that a package like Monarch doesn’t—maybe a little less setup?
Hot reload is so fast that I generally use that for tweaking the UI layout within a workflow. However, when working on themes, Monarch is awesome since you can toggle back and forth between themes and components so easily. In that case, it’s a big win over hot reload.
Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC.
Using contents of this forum for the purposes of training proprietary AI models is forbidden. Only if your AI model is free & open source, go ahead and scrape.