DEV Community

ValerianaGitđź’™
ValerianaGitđź’™

Posted on

1

Journey to Bitcoin Ticker medals in Flutter Bootcamp

Once I had gone through the starting tutorial, I followed along to try to get to the medals, this was my journey.

(Using coinAPI.IO, if you are curious)

Bronze Medal - Fetch data from API

Getting data! This was my output in console

 `"time": "2021-04-09T17:21:17.0000000Z",

 "asset": "USD",

 "rate": 58129.784449564185964438276044,

 "volume": 1006691938.9265092649750800000
Enter fullscreen mode Exit fullscreen mode

},

{

 "time": "2021-04-09T17:21:17.0000000Z",

 "asset": "ETH",

 "rate": 58122.310040699224159054898831,

 "volume": 411765352.84316552267440165637
Enter fullscreen mode Exit fullscreen mode

},

{

 "time": "2021-04-09T17:21:17.0000000Z",

 "asset": "BCH",

 "rate": 58113.757733838815756287353973,

 "volume": 25098215.853426955508618248687
Enter fullscreen mode Exit fullscreen mode

}

]`

4 . New bug now

Exception has occurred.
_TypeError (type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'FutureOr<int>')

I had to update the return type to Future<dynamic> in getCurrencyData
And
Make sure that the async work is done outside of setState
void updateUI() async {
var coinData = await coin.getCoinExchangeRateForCurrency("BTC", "USD");
setState(() {
double doubleRate = coinData['rate'];
rate = doubleRate.toInt();
});
}

Silver Medal - Get pickers working

Cupertino picker - Set the initial index of the picker to USD
scrollController: FixedExtentScrollController(initialItem: 19),

I hardcoded the 19 for now (USD is the 19th item in the list). will change this to be dynamic later, but for now, this works.

Gold Medal - Fetch price for other cryptocurrencies

Add 3 more Text cards to include the value of all 3 cryptos in project. Bitcoin, Litecoin and Ethereum.

This will be a good place to keep DRY(don’t repeat yourself) in mind. Extract current card widget to create the 3 new ones . But lets not get ahead of ourselves for now, just focus on functionality

! - since we get all 3 cryptos with any call, I only need to create 2 additional variables to keep track of ethereum and litecoin and pass those to their Text widgets

Created
int ltcRate;
int ethRate;

It works!! Now - time to refactor

Sentry mobile image

App store rankings love fast apps - mobile vitals can help you get there

Slow startup times, UI hangs, and frozen frames frustrate users—but they’re also fixable. Mobile Vitals help you measure and understand these performance issues so you can optimize your app’s speed and responsiveness. Learn how to use them to reduce friction and improve user experience.

Read full post →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay