Lab · Flutter and Dart
Lab: slow work in a kirana shop's app
The brief
Make a Dart console project for a kirana shop's app, add the intl package, load prices that arrive later (Futures), handle a failed load, load several at once, follow an order's status as a stream, and count low stock on a background isolate.
Why it matters
Real apps wait all the time: for the server, the database, the payment gateway. A shopping or delivery app that awaits correctly, catches errors, loads things in parallel and keeps heavy work off the main isolate feels fast; one that does not freezes or crashes. This is the Dart under every FutureBuilder and StreamBuilder you will write.
Skills you practise
- dart create and dart pub add
- package imports and intl NumberFormat
- Future, async and await
- try, catch and finally
- Future.wait and Stopwatch
- async* and yield
- await for
- Isolate.run
You need
- The Dart SDK 3.5 or newer (it comes with Flutter; check with dart --version)
- A terminal (PowerShell, Terminal or a VS Code terminal) and an internet connection for dart pub add
What you will have at the end
The kirana_async console project: prices loaded with async/await and error handling, a parallel load timed with a Stopwatch, an order status stream and a stock count on an isolate.
How it is marked (rubric, 100 points)
| Correct outputEvery expected line appears: the caught error, the parallel time near 300 ms, ₹969.00, the four updates before the count, and 25000. | 40 |
|---|---|
| Async done rightawait inside try/catch, Future.wait for independent work, await for over the stream, and Isolate.run only for CPU work. | 30 |
| Project and packageMade with dart create, intl added with dart pub add, money formatted with NumberFormat for en_IN. | 15 |
| ExplainedYou can explain the difference between a Future and a Stream, and between waiting and computing. | 15 |
0/5 steps done
Step 1 of 5
Create the project and add intl
A console project kirana_async exists and the intl package is in its dependencies.
This lab needs dart run on your own machine, not DartPad: DartPad runs Dart on the web, where isolates (step 5) do not work. dart create -t console makes a project with bin/, lib/, test/ and pubspec.yaml.
Go into the folder and add intl, the package that formats money the Indian way (₹1,50,000.00). dart pub add writes it into pubspec.yaml and downloads it. Paste the output of both commands. Then replace bin/kirana_async.dart with the starter file of this lab.
$ dart create -t console kirana_async, then cd kirana_async and dart pub add intlAlso check yourself
Your notes: bin/kirana_async.dart
Write down each command you ran. It goes into your project summary.