Flutter Heroes
26.1K subscribers
272 photos
2 videos
31.1K links
Download Telegram
New post on /r/flutterdev subreddit:

Some observations about the Flutter router and opening nested routes on the web. onGenerateRoute is called multiple times.
TLDRI request an initial route of /home/1/2/3/4/5 , but onGenerateRoute is called 7 times, 7 states are allocated and 7 widgets are built. One is expected for each.Solution: Use onGenerateInitialRoutes to override the default behavior.Deep Dive:I'm going to share what I've learned out of my own research when facing this issue.When opening a deep link, the flutter router recreates all the prior router/history states of the app.This means that the back button can return the user trough all the screens needed to get there even if it got there via deep linking.This behavior makes sense for mobile devices. However, on the web, this behavior is not wanted.If we load a deep link such as: http://domain/s/lorem-ipsum/all/posts we end up initialising each route level if it has it's own screen definedIf you happen to have the same component on all levels this in turn leads to 5 sets of duplicated API calls which is completely unacceptableTherefore we can use onGenerateInitialRoutes to prevent this behavior from occurring.The default history stack is overridden with a router/history stack with just one statemain.dart
... return MaterialApp( ... initialRoute: user != null ? '/' : '/login', // The default history stack is overridden with a router/history stack with just one state // In this case I used fluro but any other onGenerateRoute method will do the trick onGenerateInitialRoutes: (initialRoute) => [appRouter.generator(RouteSettings(name: initialRoute))!], onGenerateRoute: appRouter.generator, ); 
router.dart
final appRouter = FluroRouter(); void defineAppRoutes() { final routes = { // Auth '/login': LoginPage(), '/register': RegisterPage(), // Pages '/': MainFeed(), '/s': MainFeed(), '/s/:spaceId': MainFeed(), '/s/:spaceId/:activityId': MainFeed(), '/s/:spaceId/:activityId/posts': MainFeed(), ... many more such routes }; routes.forEach((route, page) { appRouter.define(route, handler: Handler( handlerFunc: (BuildContext? context, Map<String, List<String>> params) => page, )); }); // Not found appRouter.notFoundHandler = Handler( handlerFunc: (BuildContext? context, Map<String, dynamic> params) { return NotFoundPage(); }); } 
Performance/Billing concernsSome of you might be using Firebase and possibly planning to run an app with high volumes of traffic. Therefore it is quite important to pay attention to what your router does. You might be sending requests for more data than what you actually need to load for your first view of the app. Especially for sharing links on the web this might be costly if you don't optimize your API calls. Since Firebase does everything via websockets make sure you either place print statements in all your API calls or you can also switch to json-server during development to get a better view of the HTTP calls in the developer tools. There are many ways to handle this optimisation. What matters first of all is to be aware of your API calls and how many. I was able to generate 15K api calls with 3-4 work hours using an unoptimised version of my app.Final NotesinitState will be called as many route segments as you have unless you override onGenerateInitialRoutesbuild is called as many times as flutter thinks there's a change event. As long as you don't do any complex logic or any API calls during the build stage it's not that bad. Similar to React or Angular the change detection algo makes sure that if duplicate builds happen only the relevant changes are computed.I'm still learning some of this stuff so please excuse me if I used some wrong terms. Let me know how can I improve this post or if got something completely wrong. Hopefully it helps you.

November 11, 2021 at 01:31PM by SpaceInstructor
https://ift.tt/3F4wiBV
New post on /r/flutterdev subreddit:

Large examples of Provider + ChangeNotifier architecture?
Does anyone have any good example apps of arobust app architecture using ChangeNotifier + Provider?I am looking for complete app examples that go much further than just the counter example. I have yet to find a good example app that is actually of a quality to ship as a professional production ready app.Thanks!

November 11, 2021 at 05:48PM by scorr204
https://ift.tt/3C1JC8l
New tweet from FlutterDev:

🦋 Chapter 6: Pop Quiz! Which of the following is NOT a benefit of using Provider? #flutterapprentice— Flutter (@FlutterDev) Nov 11, 2021

November 11, 2021 at 10:04PM
https://twitter.com/FlutterDev/status/1458903597014401031
New post on /r/flutterdev subreddit:

How to add signature on pdf
Good evening, I am in a project of digitally signing documents, and I need to add the signatures of each user in a pdf document and I did some research and I can't find much information, any ideas? or any library that can help me.​PD: I have the signatures in image format, I capture them with the syncfusion_flutter_signaturepad package​Thanks in advance

November 11, 2021 at 11:35PM by SirChavero
https://ift.tt/3wD8jqo
New tweet from FlutterDev:

🎉 #DevFest 2021 is an amazing opportunity to get together, catch up on the latest tech news 🌟 and meet fellow developers. You're invited to #DevFestInspire, a European celebration like no other! 🥳 Let's meet on December 9 (5-9 CET). Register now ➡️ https://t.co/LXib4Rnlci https://t.co/QaBMPgn7ny— Flutter (@FlutterDev) Nov 11, 2021

November 12, 2021 at 12:00AM
https://twitter.com/FlutterDev/status/1458932576991825920
New post on /r/flutterdev subreddit:

Smart/Dump components, Functions and\or Providers
I'm a long term developer who just got into Flutter for a side project I'm working on. I've made a ton of progress with an app that a customer is ordering, but I'm kinda struggling with what should hold my application logic ie. executes a series of steps to maintain state for better user experience. Do note that I'm not talking about business logic. That resides somewhere else.I'm curious to know what is your preferred method of working in regards to what block in your Flutter app is the smart one? Is it the components, the provider or some other class\function. I'd love to have some reading material in regards to this. An example:Let's assume you're working on an app that needs to connect to some other device via a WebSocket connection. So you have a button that when pressed initiates the connection. You also have to let the user know that now you have a connection (flip button from red to green). You also have a requirement to auto connect to that device when the app starts, if it was previously connected to. So that means holding information about having to auto-connect or not, somewhere in a local database of sorts, let's say SQLite or Hive.So, what is your preferred solution here?Do you have your component do the connecting, putting that connection in a Provider and putting that connection information (like a device ID or smth) into a local database for auto-connect, ie. your component holds all the cards like WebSocket, Provider and SQLite or Hive?Does your component call a Provider to do all of that stuff for you and the component just listens to changes there and maybe flips a "Connect" button to "Disconnect"Do you create a class or a function that holds application logic and handles orchestration (as small as it is?)Do you just put that stuff all over the place and pull out your hair trying to find it later on.

November 12, 2021 at 08:10AM by rcls0053
https://ift.tt/3F8BVyX
New post on /r/flutterdev subreddit:

Your view on using 3rd party library for responsiveness in flutter application
Is it professional to use 3rd party library like flutter_screenutils for responsive app design?AS IN:Text responsiveness throughout different devices.UI responsiveness throughout the different layoutHandling flutter font size issue, where 20 px will be something else on another device's screenIt's confusing.#Flutter

November 12, 2021 at 10:16AM by Lucky_Looper
https://ift.tt/30jcjAt
New post on /r/flutterdev subreddit:

Tip: How to avoid badly cropped rounded avatars: round your animation values
I've been noticing that in certain cases the avatars of my app tend to be slightly cropped. Although I made sure that all dimensions match from PSD to Widget sometimes this crop shows up. After brainstorming a bit I've figured out that this is due to the animation that I apply to this particular sidebar (Container). Due to the way the numbers are computed the final animation ends up in a state where the position includes a decimal value. This slight missalignment is enough to trick the the image rastering algo to "skip a row of pixels". That is just enough to make the avatar look clipped. The solution was to round the final value thus eliminating the subpixel missalignment.Here's a little demo image to compare the results: https://imgur.com/a/ZfOdjvO

November 12, 2021 at 01:08PM by SpaceInstructor
https://ift.tt/3naGfYy
New post on /r/flutterdev subreddit:

App Feedback Thread - November 12, 2021
This thread is for getting feedback on your own apps.Developers:must provide feedback for othersmust include Play Store, App Store, GitHub, GitLab, or BitBucket linkmust make top level commentmust make effort to respond to questions and feedback from commentersmay be open or closed sourceCommenters:must give constructive feedback in replies to top level commentsmust not include links to other appsTo cut down on spam, accounts who are too young or do not have enough karma to post will be removed. Please make an effort to contribute to the community before asking for feedback.As always, the mod team is only a small group of people, and we rely on the readers to help us maintain this subreddit. Please report any rule breakers. Thank you.- r/FlutterDev Mods

November 12, 2021 at 03:00PM by AutoModerator
https://ift.tt/3c7XoeQ
New post on /r/flutterdev subreddit:

flutter how to install?
/r/archlinux/comments/qsgu9s/flutter_how_to_install/

November 12, 2021 at 06:59PM by infinitecoolname
https://ift.tt/3or5KUz
New post on /r/flutterdev subreddit:

How do you comprehend abstraction
Hey all, I have been learning Bloc and I thought I was at a decent level enough to dive deeper into the tutorials but I don't understand why some things are done at this point. I know that Bloc is famous for its boilerplate but that's not at all the issue here. It's everything else.I know you are supposed to abstract certain details in your app so that they are reusable or can be changed without affecting other components too much but it gets to a point where I'm lost and I don't understand what does what and why we are separating it into its own module.It was a simple weather app that I got lost with and I don't know how anyone can understand production level code. I've only built apps for myself and only recently started collaborating on GitHub so that might be it but the confusion I get from reading some code and not immediately understanding what it does makes me want to give up sometimes.I do understand the code I see in front of me but conceptualizing how everything comes together seems too much for my head. It's strange to look like a chore especially when it comes to testing large swaths of code.

November 12, 2021 at 09:39PM by HenryNanaAdu
https://ift.tt/3FhmS6l
New tweet from FlutterDev:

D. UI whitespace is the correct answer! 🥳— Flutter (@FlutterDev) Nov 12, 2021

November 12, 2021 at 10:30PM
https://twitter.com/FlutterDev/status/1459272312721604610
New post on /r/flutterdev subreddit:

ListView Render Behaviour
I am creating a chat page as part of a project I'm working on. In a demo, I run a bit of logic in the ListView.builder to obtain the details of the next chat message to inform specific UI rendering. To be precise, the structure of the message widget should change if it was the last of its "kind" like WhatsApp does.To test this, I passed two arguments to the message widget; <message> the actual message, and <next>, the one after. If the message was the last in the list, then <next> would be null.I gave it a test run with some dummy data. The messages would not render a date unless they were the last from either myself or someone else. All was well.At least, until I tried to update the dummy message list with new data. The previous "last" message widgets seem to maintain the "null" value of <next> even though they are no longer the last. It's quite an interesting situation because values like the index and message list length were refreshing predictably when I chose to display them. InitState was also being called for each widget.Does anyone have an idea of what is happening behind the scenes?PS: I plan to achieve this differently, in practice. The chat pages are ephemeral, so I assume I can get away with some stuff, but any advice is still welcome.

November 13, 2021 at 01:27AM by GingsWife
https://ift.tt/2YFJzBi
New post on /r/flutterdev subreddit:

Have you switched from stream-based state management to any other and why?
I've been developing Flutter apps since the early 2018, and what got me in love with streams was a 2018 I/O talk by Matt and Filip from the Flutter team, which looks like it has since been deleted.I've lucked out at my current job and got to decide on the state management approach, obviously I've went for something I'm well familiar with, and that's using StreamBuilder, StreamSubscription and Stream objects to handle state management (alongside some setState and StatefulBuilder widgets here and there). We've built a functionally very large webshop, and are on the track to release it! I'm actually surprised by how little bugs we've encountered, so I don't think complexity is an issue.My question is: have you used stream-based solutions in a professional capacity, and have you switched from it to any other solution and why? If it means anything, my colleagues seem to have gotten a good grip on streams, so that's not a concern.Many thanks.EDIT: Any issues you've noticed that resulted in you not choosing stream-based state management?

November 13, 2021 at 01:24AM by No_Appearance4886
https://ift.tt/3C9Hnjd
New post on /r/flutterdev subreddit:

First Flutter-Powered Mobile Banking App in Europe
https://ift.tt/3C6ZuXb

November 13, 2021 at 10:10AM by smbale
https://ift.tt/3FcFgx3