BladeMechanics

Kefa Ngunjiri

Jan 29th, 2021
901
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //run this in https://dartpad.dev
  2. void main() {
  3.   //I'm assuming you saved the data in this form
  4.   var myGift = {"value": 1};
  5.   print(myGift);
  6.   //so I'm also seeing a problem here where value is not being accessed properly
  7.   //it should be '${myGift["value"]}'instead of '${'myGift[value]'}';
  8.   var amount = '${myGift["value"]}';
  9.   print(amount);
  10.   print(amount.runtimeType);
  11. //so now that we got it as a proper string, time to convert
  12.   var num = int.parse(amount);
  13.   print(num.runtimeType);
  14. //some operations
  15.   var result = 1 + num;
  16.   print(result);
  17.   print("however what happens if you put a float instead?");
  18.   var myGift2 = {"value": 1.25};
  19.   print(myGift2);
  20.   var amount2 = '${myGift2["value"]}';
  21.   print(amount2);
  22.   print(amount2.runtimeType);
  23.   var num2 = int.parse(amount);
  24.   print(num2);
  25.   print("as you can see it gets truncated");
  26. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×