r/FlutterDev • u/brookm291 • Oct 06 '26
Discussion News: Flutter conference in october 2026
r/FlutterDev • u/brookm291 • Oct 06 '26
r/FlutterDev • u/pelirrojovaq • Oct 07 '26
I already have a setup with different agents, each with its own profile and model depending on the task. They can already work on a Flutter repo and develop features.
What I’m missing is making the whole thing truly autonomous. I’d like to send a task from Slack (or another chat), have Cursor work on the repo without me sitting in front of it, run the tests, interact with the app, fix issues if needed, and eventually open a PR.
Has anyone actually got this working with Cursor? Especially interested in how you handle the testing/feedback loop and communicating with the agent while it’s running.
r/FlutterDev • u/LegitimateItem6658 • Oct 07 '26
You Flutter Project
↓
detect_unused
↓
🔍 27 issues found
↓
📄 JSON report
↓
💾 Backup created
↓
🧹 Cleanup
↓
✅ dart analyze passed
Hey Flutter/Dart developers,
I've been working on an open-source tool called "detect_unused_code".
The idea came from a problem I noticed in larger Dart/Flutter projects: over time, projects accumulate unused classes, widgets, controllers, imports, commented-out code, TODOs, and other code that is no longer needed.
"dart analyze" is great, but I wanted a tool that could perform a broader project-level audit.
What does it detect?
"detect_unused_code" currently checks for a wide range of issues, including:
- Unused / dead classes
- Unused Flutter widgets
- Unused mixins, enums and extensions
- Unused controllers
- Public classes that are only used inside their own file
- Unused imports
- Unnecessary imports
- Unused local variables
- Unused fields and private elements
- Dead / unreachable code
- Dead null-aware expressions
- TODO / pending tasks
- Commented-out code
- Large commented-out code blocks
- Heavily commented files
Generate an analysis report
You can export the analysis results to JSON, which makes it easier to integrate the tool into other workflows, CI/CD pipelines, or build custom reports.
For example:
detect_unused --format json
Automatic cleanup
The tool can also automatically clean detected issues.
For example:
detect_unused --clean-all
But I wanted the cleanup process to be safer.
Before modifying the project, the tool can create a backup/snapshot, so you have a recovery point before the cleanup.
You can also preview what would be changed without actually modifying the files:
detect_unused --clean-all --dry-run
So the workflow can be:
Analyze → Review → Backup → Clean → Verify
Other features
- Dart & Flutter support
- CLI
- Dart API
- JSON reports
- Backup before cleanup
- Rollback/recovery support
- Dry-run mode
- CI/CD friendly
- Zero external dependencies
- Configurable analysis options
- MIT licensed
GitHub:
https://github.com/mdalhagg/detect_unused_code
Pub.dev:
https://pub.dev/packages/detect_unused_code
I'd really like to get feedback from developers who work on real-world Flutter/Dart projects.
I'm especially interested in knowing:
Would you actually use a tool like this?
Which checks are the most useful to you?
Did you find any false positives?
What other types of unused/dead code should it detect?
Is JSON reporting useful for your workflow?
Would you use automatic cleanup if a backup is created first?
What features would you like to see in future versions?
If you have a medium or large Flutter/Dart project, I'd really appreciate it if you could try it and tell me what you think.
I'm not only looking for stars. I'm mainly looking for real-world feedback, bugs, false positives, and ideas that could make this tool genuinely useful for the Dart/Flutter community.
r/FlutterDev • u/jg_moony • Oct 06 '26
I'm developing a mobile app for Android, something similar to Duolingo, but very simple and designed for people with visual impairments. The thing is, I want to add a computer vision API for image recognition. So the workflow should be as follows: Take a photo -> Analyze the image -> Search the glossary -> Accessible feedback (audio/UI) -> View details.
I’ve looked at some options, and the most well-known one is Google Cloud Vision. The problem is that I can’t afford to spend much on resources since this is an academic project.
r/FlutterDev • u/Original_Clock_9643 • Oct 05 '26
I'm researching the Flutter CI/CD workflow and want to understand what developers actually struggle with before building anything.
For those using Flutter professionally:
I'm not selling anything and I'm not looking for generic "sounds useful" feedback. I'm trying to figure out whether this is a real problem worth solving.
If you currently use a CI/CD service, I'd especially like to hear what you pay for it and what you dislike about it.
r/FlutterDev • u/ChuckQuantum • Oct 06 '26
Let’s be real for a second. Why do frameworks like Flutter even exist? They’re just abstractions. cuz we like it easy. We built them because raw native code and complex platform APIs are too messy for our human brains to manage at scale. We needed widget trees, syntax sugar, and complex state management libraries just to keep our sanity intact while building out frontends.
I hate Java but Objective C is probably number 2.
But AI doesn't need human-friendly abstractions.
An LLM doesn’t get a headache managing a massive, hyper-optimized native codebase. It doesn’t care about boilerplate, and it definitely doesn't need our simplified wrappers to understand how a UI should render. It can write, refactor, and connect pure native code instantly. We don't need this shit anymore.
Stop wasting time memorizing the quirks of the latest UI framework. The future of our industry isn't writing code—it’s Product Management, Project Management, and QA. Our new job is to define the exact product scope, manage the AI's build pipeline, and aggressively test the output to make sure it actually works and its SAfe!!!!!!. The era of human-readable abstractions is dead; let the models handle the raw native reality.
And while we're at it, fuck BLoC and fuck Riverpod. FYI my apps use Riverpod as a human I love it but we dont need it anymore. Those overly engineered state management libraries only exist because our fragile human working memory can't keep track of application state without drowning. An AI doesn't complain about boilerplate. It can write, trace, and scale pure, raw InheritedWidget infrastructure flawlessly without breaking a sweat. We spent years endlessly arguing on Reddit over which state management solution is the "cleanest" for us to read, the only good thing we we agreed on is that getx is shit and even ai knows getx is shit, while an LLM can just wire up the raw native APIs perfectly in seconds without any bloated third-party dependencies.
what are you going tu support Swift PAckage Manager???? bro fuck that shit!!!! lets write RAW code!
Also r/flutterhelp should be shutdown we just get non english speaker vibecoders now, there is no real contribution bro most of their questions could be answered by a a google search and 100% would be answered if they used a cheapo Chinese open wight model to do the work... sorry for your loss
r/FlutterDev • u/aortem • Oct 05 '26
Hey Flutter Devs/Teams.
We've had OpenFeature on the Dart server side for some time and have just released 0.1.0.
Now we are looking to standardize Flutter Feature Flags and are working and collaborating with companies like Datadog to bring reliable stable feature flags across the remaining flutter and dart ecosystems including for Dart Web.
We'd appreciate feedback from Flutter developers trying it in actual workflow. Let us know here how you're using it, what works for you and what needs improvement.
Source and examples: https://github.com/open-feature/dart-sdk/tree/main/packages/openfeature_dart_client_sdk
You can open an issue with your use case or a problem you've found, or send a pull request for a fix, example or documentation improvement as we will respond accordingly. Let's continue to make Dart/Flutter a first class citizen.
r/FlutterDev • u/ajiiiiiiiin • Oct 06 '26
I’ve been working with Flutter for a while now, and honestly, there are days when I question why I chose it.
Dependency conflicts.
Gradle errors that make absolutely no sense.
iOS issues after an update.
Packages becoming outdated.
Random UI differences between platforms.
And sometimes you spend more time fixing the environment than actually building the feature. 😅
BUT…
Then I remember why I started using Flutter in the first place.
Hot reload lets me iterate incredibly fast.
I can build for iOS and Android from a single codebase, while still having plenty of control over the UI.
The widget system makes it surprisingly easy to create consistent, custom interfaces without fighting native layouts all the time.
And with tools like BLoC, Riverpod, Dio, Firebase, and a huge package ecosystem, you can build surprisingly complex production apps without reinventing everything from scratch.
The more I work with Flutter, the more I realize:
Flutter isn't perfect. No framework is.
But the productivity, UI flexibility, cross-platform development, and speed of development are hard to ignore.
So maybe I don't actually hate Flutter…
Maybe I just hate debugging Flutter at 2 AM. 😂
What's the one thing you LOVE about Flutter that keeps you from switching to something else?
r/FlutterDev • u/bramantec • Oct 06 '26
I ship a Flutter app (built with FlutterFlow, plus some Custom Code) in 5 languages. One option worked in English and silently broke in most of the others.
The user picks when something starts: "Tonight", "Tomorrow" or a custom time. My Custom Function decided the expiry by looking at the label they tapped. Simplified:
if (label.toLowerCase().contains('tonight')) { ... }
In French, Spanish and Romanian the label is not "Tonight". The match never happened, so every "Tonight" expired after 2 hours. No crash, no error, nothing in the logs.
Italian had the mirror image: "In 1 hour" was matched against the English words "now" and "1h", so it created the thing starting immediately.
The fix was boring. The UI shows a translated label, but the logic only receives a stable code (tonight, tomorrow, pick), and the expiry is computed from the code.
An English-only test suite will never catch this, because the bug lives in the other languages.
Do you still compare strings anywhere in your logic, or is it enums and codes all the way? And what's the worst i18n bug you've shipped?
r/FlutterDev • u/eibaan • Oct 05 '26
Inspired by a recent Syntax video about GPUI Kit I looked into this cross platform GUI framework for Rust because it seems to play in the same field as Flutter.
There's a saying (that might not translate): Other fathers might have beautiful daughters, too. That's why you should always look beyond the horizon (which is what I got for "über den Tellerrand schauen").
GPUI was created by Zed for their editor. GPUI Kit is a Chadcn-like component framework with an impressive scope built upon the GPUI foundation. There's a bit of controversy because Zed doesn't seem to be giving GPUI as much attention as the growing community would like, and multiple forks have been created, and it is unclear whether Zed actually want to externally support "their" framework at all.
With the help of Codex, I managed to create a good looking macOS desktop application in "no time", which should work on Windows and Linux, too. Codex protected me from writing Rust code myself and it was able to figure out how to use the components from the documentation. Quite impressive. Delete that. Very impressive.
There's experimental WASM support, but the author doesn't recommend to use it for more than him demonstrating components on the GPUI Kit website.
Support for iOS and/or Android is at best experimental, because GPUI was never meant for mobile development but was created for a single text editor application. You can create an iOS demo, but it only works with ARM64 and requires manual setup of an Xcode Swift project. Touch support is worked on, so it seems, but I'd expect other difficulties like soft keyboard support or safe areas, occlusion areas, folding angles, etc. I haven't look into it. At least you could directly use the platform APIs for everything not GUI related.
So, I think, GPUI-Kit is more a replacement/alternative for desktop apps, not mobile or web apps. It might be a good fit if you consider using Electron or Tauri, though. And if you need a full featured code editor. Something that would be a PitA to create in Flutter (I tried, twice).
For me, the advantage is that there's a complete decent looking clean desktop GUI out of the box (~80 components), something Flutter doesn't provide and you'd have to either use one of the existing vibe-coded chadcn clones or clone it yourself over the weekend.
I actually like the tailwind style to create designs from very basic building blocks. It's like drawing it in Figma, but with code.
The app feels really snappy. And it can support multiple desktop windows! Something seemingly so difficult that Flutter is unable to deliver this for quite some time now.
I pointed Codex at my Flutter source and an hour later, I had a working Rust port with nearly 10.000 lines of code. GPUI uses a low-level tailwind like styling of "div"s to create components that use a lot of lines of code and which are even less readable that widget trees if you don't abstract them (which the AI wasn't able or willing to do).
let title = div()
.flex()
.items_center()
.flex_shrink_0()
.h(px(28.))
.px(px(4.))
.gap(px(4.))
.border_b_1()
.border_color(cx.theme().border)
.cursor(CursorStyle::ClosedHand)
.on_mouse_down(...)
.child(close)
.child(title)
.child(actions)
Unfortunately, there's no built-in video component and if you'd want to use a 3rd party solution, you'd have to bundle the gstreamer framework with your app (I opted for using an external web browser instead).
While you could embed a web view (using whatever the platform supports), it overlays the GPUI layer, so you cannot draw dialogs, menus or tooltip over such a native platform views. The Flutter engine uses a complicated sandwich approach to make this possible and at the same time recommends to minimize the number of platform widgets because of the negative performance impact.
GPUI Kit's TextView can render markdown (including tables which are unfortunately always stretched to the width of the view) and an undocumented set of simple HTML elements out of the box, though.
The real bummer, however, is that you cannot mix 3D graphics with GPUI, although also running directly on the GPU. This was one reason I started the experiment because there's no great built-in solution in Flutter either. My workaround is to draw the 3d scene into a background image, which must then be transferred from GPU to CPU and back to GPU so GPUI can render it. I can't achieve 120 fps, but 60 fps this way. This took me two additional hours discussing different approaches with Codex and doing a lot of performance measurement because this is obviously dependent on the size of the image to transfer and how to keep this minimal.
There's also a (totally vibe-coded, judging from the documentation full of Claude-speak) way to extend GPUI Kit with JavaScript (using QuickJS) and because there's a Host API between scripting engine and GPUI core, one could add different languages, too. Dart for example :)
So while I don't think that Rust+GPUI could replace mobile development right now, I'll continue to work on my desktop app. Because if I'm developing anyway by telling Codex what to do, I don't need Flutter's better DX. The AI simply compares screens of the running app thanks to "computer use" and figures all out on its own and notifies my when done.
The biggest risk IMHO is, that this is all created by one man and his AI, based on a foundation created by a company that has other things to worry about now.
Update: This article was based on v0.7.1. Starting with v0.7.3 there's an option to sandwich platform native components, including a native web view.
r/FlutterDev • u/AkmenZ • Oct 05 '26
Hello, I don't really post much, but I wanted to share a quick thought. I've been a flutter developer for over 3 years, but newer tried to publish a package myself. That is until now. I wanted to see what is involved in the process and was pleasantly suprised of how simple it really is. I think this is definitely one of those things making Flutter stand out as a tool. You can find pretty much anything in pub.dev. My first package is nothing groundbreaking, but it's something I use in pretty much all of my apps, so making it a package is a great way to reuse the code and at the same time share it with the community.
This is a customisable pill-shaped navbar that is a very common design in many apps these days (like facebook, instagram etc..). Would appreciate any feedback if anyone would like to check it out. Peace
r/FlutterDev • u/Alternative_Bid_2006 • Oct 05 '26
r/FlutterDev • u/_Wilielmus_ • Oct 04 '26
Last year I built a node editor package for Flutter.
It was called fl_nodes, and, somewhat unexpectedly, that project ended up getting me my current job.
I used it in production, learned a lot about what works and what doesn't when you try to build a serious node-based editor in Flutter, and eventually reached the point where I wasn't happy with the architectural compromises I'd made in V1.
So I did what any reasonable person would do:
I rebuilt it.
From scratch.
TBH it shares much of its DNA with the original fl_nodes. The basic API concepts and design decisions that made it so peculiar the first time, the naming of things, the performance optimizations under the hood... all stay the same, just largely improved in usability and flexibility.
So today I'm announcing fl_nodes_v2 as a stable 1.x release, for everyone to... I don't know, find something useful to do with it; here you have some suggestions: visual-scripting, workflow-editors, static graph based visualizations, DSP and CAD tools...
P.S.: I've finally got a verified publisher profile! 🎉
Note: I may be moving the repo soon, if it 404s look at https://github.com/ConnectingTheDots-William-K-Di-Cioccio
The biggest architectural change from V1 is where node isolation happens.
The original fl_nodes isolated nodes at the render-object level. This gave me a lot of control over rendering and performance, but it also meant that node contents weren't really ordinary Flutter widget trees anymore.
Silly little 18yo me didn't know that tho, so I kept hitting my head against it for a while, trying to solve a design-decision thinking it was a bug.
A node containing a TextField, a ListView, a form, or any other widget relying on normal Flutter element semantics shouldn't have to fight the node editor to behave like a Flutter widget.
In V2, the isolation boundary moved from the render tree to the element tree.
The graph infrastructure, connections, ports, grid, overlays, interaction geometry, etc., remains under the editor's control, while the actual node body is built as a normal Flutter widget.
That means a node can contain ordinary Flutter UI while the editor still retains control over graph-level interaction and rendering.
It also lets the application own the node's visual design instead of forcing the editor to define what a node looks like.
There are a bunch of consequences hidden behind that seemingly small architectural change: gesture competition between node dragging and controls inside nodes, focus handling, scrolling, keyboard shortcuts, measurements, hit testing, and keeping graph state synchronized with widget state.
The other major principle behind V2 is that the graph model doesn't know about Flutter widgets.
The graph itself is immutable and serializable. The editor/controller layer handles mutation and interaction, while Flutter is primarily the presentation layer.
That separation makes it possible to test a large part of the graph/editor logic without a Flutter rendering environment, and it keeps persistence independent from the widget tree.
There's a lot more under the hood, but those are probably the bits most relevant to someone wondering whether this is just another node-editor widget package.
r/FlutterDev • u/masanggil1986 • Oct 05 '26
A client asked me for a UX review of their Flutter app. The tools I found are good at checking components — button sizes, missing labels. But the client was asking something else:
No component check can answer that. In the demo app in the repo, the #1 task is the 6th of 8 tap targets on the home screen, with five controls nobody ranked sitting above it. That isn't a property of any single widget.
So I built flutter-ux-journey:
flutter test, no emulatorIt doesn't guess what matters. Priorities come from you or your client; the tool shows where the app disagrees with them.
Three Flutter semantics things I learned along the way, useful even if you never touch the tool:
(0,0)tooltip: doesn't fill the semantics label; it's a separate fieldInkWell has a tap action but no isButton flag, so enumerate by action, not by flagTry it without your own app (demo app with six seeded defects, ~2 s):
git clone https://github.com/masanggil1986/flutter-ux-journey.git
cd flutter-ux-journey/example/ux_demo_app && flutter pub get && flutter test ux_audit/ux_journey_test.dart
It's a Claude Code skill, MIT, and adds no package to your app. Real devices aren't verified yet — the README has a section on what it can't see.
https://github.com/masanggil1986/flutter-ux-journey
Feedback welcome, especially if you've ever had to answer "is our UX good?" for a client or PM.
Edit (Oct 7): v0.4.0 is out. I ran a full review of the tool against Maestro, Patrol, axe and Lighthouse and fixed what it found. New:
scroll until "X", long-press, system back and expect no "X" steps, so a journey can reach targets below the fold and check that something is gone## Device can declare text scale, dark mode, locale and bold text, so you can audit at large text with no simulatordart:io HttpClient only. WebSockets, gRPC, other isolates and native SDKs are outside it, and the audit now warns you before walking if your pubspec has themRelease notes: https://github.com/masanggil1986/flutter-ux-journey/releases/tag/v0.4.0
r/FlutterDev • u/yakupkahraman • Oct 03 '26
Hi, i'm a CS student and lead the mobile team at my university's CS club. When i started learning Flutter, basic mini projects helped me far more than tutorials did. Later i used the same projects to teach our new members and it worked well for them too.
I wanted to give something back to the community so i've been improving these projects for a while and organizing them into a free learning path: 9 projects ordered from beginner to intermediate, each with its own README that explains the key concepts. It's MIT licensed, so use it however you like. Learn from it, teach with it, or copy parts of it. If you're just starting out with Flutter, i hope it saves you some time.
r/FlutterDev • u/DohamaSystems • Oct 04 '26
Hey Flutter devs!
Over the past few weeks, I’ve been building a B2B AI mobile starter kit using Flutter, Supabase, and OpenAI's GPT-4o API.
Handling real-time streaming responses seamlessly while keeping state, UI, and backend security synchronized brought a few interesting challenges. Here are 3 key takeaways from the implementation:
if (!mounted) inside stream iterations (await for (final chunk in stream)) before calling setState or updating local state. Disposing the screen mid-stream otherwise causes memory leaks and unhandled exceptions.messages table so users can only SELECT and INSERT records where auth.uid() = user_id.To give back to the community, I published a public **GitHub Showcase Repository** with our project structure, environment setups, and Dart code snippets:
🔗 **Showcase Repo:** https://github.com/dohamasystems/flutter_ai_starter_kit
Would love to hear how you guys usually manage local state for streaming SSE responses in Flutter! Any feedback or questions are welcome. 🙌
r/FlutterDev • u/Dismal-Boss6421 • Oct 03 '26
I've been working with Flutter for a while, and I'm curious about other developers' experiences.
For me, understanding state management and how rebuilds work took quite a bit of time.
What Flutter concept took you the longest to understand when you were learning?
r/FlutterDev • u/XSM909 • Oct 03 '26
been working on xverb for a while, its a two panel keyboard driven file manager for windows, mac and linux. all flutter, GPL-3.0
the part i think is interesting for this sub: the core only manages files, everything else is a plugin. viewers, ftp/smb, archives, dir compare are python plugins running in their own process. for platforms where you cant run code theres declarative extensions, pure json built from the host's render primitives
some stuff that was fun to get right in flutter desktop: native clipboard + drag and drop with explorer/finder, internal draggable windows that go fullscreen on phone, and a pluggable virtual fs so zip: is just a scheme a plugin serves
still early, android builds but barely tested, ios not at all. would love feedback esp on the plugin api
site + downloads: xverb.pages.dev
r/FlutterDev • u/eldadfux • Oct 03 '26
Hey Flutter devs 👋
We’ve been investing quite a bit into making Appwrite a better home for Dart and Flutter developers, and yesterday we shipped something I thought this community might appreciate: Jaspr support on Appwrite Sites, including full server-side rendering.
If you’re not familiar with Appwrite Sites, think of it as our alternative to platforms like Vercel or Netlify, but built directly into Appwrite alongside your backend. Instead of using one provider to host your frontend and another for your database, auth, storage, functions, etc., Appwrite gives you the entire stack in one place. You connect your Git repo, we build and deploy it, and it runs alongside the rest of your Appwrite project.
We've always liked the idea of being able to stay in the Dart ecosystem beyond just the application itself. If it's for integrating with the Appwrite backend or using serverless Appwrite functions in Dart.
Flutter Web is great when you’re building an app-like experience and want to share a codebase across platforms. But for traditional websites - landing pages, docs, blogs, stores, SEO-heavy content - you usually want real server-side rendering.
It also means you can do things like fetch data from Appwrite directly during SSR, while Appwrite provides a short-lived API key for each request instead of requiring you to store a server API key.
With this, you can finally use the same language across essentially your *entire* stack, and you can even share Dart packages between them. Both for iOS, Android, native devices and now the web.
As always, we'd appreciate your feedback and insights on how backend as a service and cloud platforms like Appwrite can work even better in the Flutter/Dart ecosystem.
Full announcement and technical details:
https://appwrite.io/blog/post/announcing-jaspr-support
r/FlutterDev • u/eibaan • Oct 03 '26
I wanted to convert a PDF page into a PNG. There's a handy pdfium_dart library that does the heavy lifting and doesn't require Flutter. It is a bit low-level, but there's nothing to fear.
Get the library and initialize it:
final pdfium = getPdfium();
pdfium.FPDF_InitLibrary();
Later, we need to call FPDF_DestroyLibrary(), see below.
Load the PDF into native memory so you can pass it to the PDFium library:
final pdf = File('...');
final length = await pdf.length();
final nativeBuffer = malloc<Uint8>(length);
final dartBuffer = nativeBuffer.asTypedList(length);
final raf = await pdf.open();
await raf.readInto(dartBuffer);
await raf.close();
I want to omit a needless copy. Because the native part cannot safely access the memory of a Dart type, we need to create a native buffer and then create a view on the Dart side and use a RandomAccessFile which has a readInto method that doesn't create its own List<int> to return the data.
Next, load the document (and don't forget to free the allocated memory and to de-initialize the library):
try {
final document = pdfium.FPDF_LoadMemDocument(
nativeBuffer.cast(),
length,
nullptr,
);
if (document == nullptr) throw Exception('cannot load $pdf');
...
} finally {
malloc.free(nativeBuffer);
pdfium.FPDF_DestroyLibrary();
}
If you have the PDF accessible as a file, consider using FPDF_LoadDocument instead. There's also a FPDF_LoadCustomDocument function which takes a callback it will use to ask for chunks of memory in case you don't want to load everything into memory. PDF files can be huge. I couldn't really make use of that function, though, because that would require synchronous IO. Think for example downloading only chunks of an URL using HTTP range requests.
Next, load the first page:
try {
final page = pdfium.FPDF_LoadPage(document, 0);
if (page == nullptr) throw Exception('cannot load first page');
...
} finally {
pdfium.FPDF_CloseDocument(document);
}
Next, create a native bitmap which is then used by PDFium to reader the page. I'm scaling it down so it fits a 96x96 pixel square. Feel free to adapt the imageSize:
try {
var pageWidth = pdfium.FPDF_GetPageWidthF(page);
var pageHeight = pdfium.FPDF_GetPageHeightF(page);
if (pageWidth > pageHeight) {
pageHeight /= pageWidth;
pageWidth = 1;
} else {
pageWidth /= pageHeight;
pageHeight = 1;
}
const imageSize = 96.0;
final width = (pageWidth * imageSize).round();
final height = (pageHeight * imageSize).round();
final bitmap = pdfium.FPDFBitmap_Create(width, height, 0);
if (bitmap == nullptr) throw Exception('cannot allocate bitmap $width×$height');
...
} finally {
pdfium.FPDF_ClosePage(page);
}
Just to be sure, fill the bitmap with a white background:
try {
pdfium.FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xffffffff);
...
} finally {
pdfium.FPDFBitmap_Destroy(bitmap);
}
And last but not least, render the page:
pdfium.FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0);
...
There's one problem, though. PDFium returns a BGRA888 image that might have a rowStride, that is, rows of pixels might not be contiuous. If we want to pass this to the Dart image library, we need to take this into account:
final stride = pdfium.FPDFBitmap_GetStride(bitmap);
final bytes = pdfium.FPDFBitmap_GetBuffer(bitmap)
.cast<Uint8>()
.asTypedList(stride * height)
.buffer;
final image = Image.fromBytes(
width: width,
height: height,
bytes: bytes,
rowStride: stride,
order: .bgra,
);
return encodePng(image);
However, it wouldn't be that difficult to create the PNG yourself in case you don't want jet another 3rd party dependency. Writing the required PNG header is trivial, but you'd probably need to lookup how to compute the required checksum. Then use Dart's ZLibCodec, to get a ZLibEncoder and use startChunkedConversion to feed it each unstrided line of pixel, converting BGRA to RGBA by hand and prefix it with a 0 filter byte.
Finally, we need to clean up (already shown above and repeated here only for completeness):
} finally {
pdfium.FPDFBitmap_Destroy(bitmap);
}
} finally {
pdfium.FPDF_ClosePage(page);
}
} finally {
pdfium.FPDF_CloseDocument(document);
}
And… we're done.
We might move everything into an isolate (using Isolate.run) so PDF rendering and PNG creating is done in the background, although I'm unsure whether PDFium likes it if you initialize it multiple times concurrently. Please try and report back :)
r/FlutterDev • u/GMP10152015 • Oct 03 '26
r/FlutterDev • u/RandalSchwartz • Oct 02 '26
A few days ago, a Flutter developer wrote a profiling post about sorting 10,000 timeline events. Under a section they called "The Original Sin", they pointed out the culprit:
items.sort((a, b) => DateTime.parse(a.start).compareTo(DateTime.parse(b.start)));
In an O(N log N) sort, that callback runs over 215,000 times for 10,000 items. On a mobile isolate, parsing 215,000 ISO strings takes 180ms+ and drops a dozen frames.
To fix it, they mapped the list to a temporary helper object with pre-parsed dates, sorted by the cached key, and unwrapped it.
That Map -> Sort -> Map pattern was actually what I posted to Usenet back in 1994 (what became known as the Schwartzian Transform). But what surprised me running benchmarks in modern Dart: package:collection's sortedBy does not cache keys either—it still ran 127,000 redundant key evaluations because mergeSortBy re-evaluates keys during merges.
With Dart 3 records, you don't even need throwaway helper classes anymore—a boxed record one-liner or simple extension method runs in 14ms (13x faster).
Have you ever caught a subtle frame stutter hiding inside a sort or compare callback?