crashes on 0
willardjansen opened this issue · 18 comments
seems to be something else, don't know what though, yet.
@willardjansen Thank you for letting me know.
I've added 0 exception for that. :)
Ok Thanks for the quick response. Crash has something to do with the package though. When I take it out everything works.
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following UnsupportedError was thrown building Now(dirty, dependencies: [MediaQuery,
_InheritedTheme, _LocalizationsScope-[GlobalKey#68977]], state: _NowState#6ef16):
Unsupported operation: NaN
The relevant error-causing widget was:
Now
lib/main.dart:34
When the exception was thrown, this was the stack:
dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 214:49 throw
dart-sdk/lib/_internal/js_dev_runtime/private/js_number.dart 109:5 round]
packages/hrm_rekentools/pages/now.dart 366:88 build
packages/flutter/src/widgets/framework.dart 4663:28 build
packages/flutter/src/widgets/framework.dart 4546:15 performRebuild
packages/flutter/src/widgets/framework.dart 4719:11 performRebuild
packages/flutter/src/widgets/framework.dart 4262:5 rebuild
packages/flutter/src/widgets/framework.dart 2667:31 buildScope
packages/flutter/src/widgets/binding.dart 866:20 drawFrame
packages/flutter/src/rendering/binding.dart 286:5 [_handlePersistentFrameCallback]
packages/flutter/src/scheduler/binding.dart 1115:15 [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1054:9 handleDrawFrame
packages/flutter/src/scheduler/binding.dart 970:5 [_handleDrawFrame]
lib/_engine/engine/window.dart 739:13 _invoke
lib/_engine/engine/window.dart 352:5 invokeOnDrawFrame
lib/_engine/engine.dart 214:18
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
The following UnsupportedError was thrown building Now(dirty, dependencies: [MediaQuery, _InheritedTheme, _LocalizationsScope-[GlobalKey#68977]], state: _NowState#6ef16):
Unsupported operation: NaN
The relevant error-causing widget was
Now
lib/main.dart:34
When the exception was thrown, this was the stack
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 214:49 throw_
dart-sdk/lib/_internal/js_dev_runtime/private/js_number.dart 109:5 round]
packages/hrm_rekentools/pages/now.dart 366:88 build
packages/flutter/src/widgets/framework.dart 4663:28 build
packages/flutter/src/widgets/framework.dart 4546:15 performRebuild
...
TextField(
cursorColor: Colors.grey[600],
keyboardType: TextInputType.number,
style: Theme.of(context).textTheme.caption,
decoration: InputDecoration(
labelText: 'Loonsogedeelte boven $max'),
inputFormatters: [
CurrencyTextInputFormatter(
locale: 'nl',
decimalDigits: 0,
symbol: '€ ',
)
],
onChanged: (String value) {
try {
if (reserveertVakantieBijslag == true) {
loonsomOpMaandBasis = loonsomOpMaandBasis;
} else {
loonsomOpMaandBasis =
(loonsomOpMaandBasis * 0.926);
}
loonsomGedeelteBovenMaxExVakantieInJanuari =
double.parse(value);
} catch (exception) {
loonsomGedeelteBovenMaxExVakantieInJanuari =
0;
}
loonsomOpMaandBasis = loonsomOpMaandBasis -
loonsomGedeelteBovenMaxExVakantieInJanuari;
grondslagNowFactorBopMaandbasis =
loonsomOpMaandBasis;
setState(() {
grondslagNowFactorBopMaandbasisVermeerderdMetDertigProcent =
(((loonsomOpMaandBasis / 100) * 30) +
loonsomOpMaandBasis);
});
if (rechtOpNow = true) {
setState(() {});
totaalRecht =
((grondslagNowFactorBopMaandbasisVermeerderdMetDertigProcent *
0.9) *
3) *
percentageOmzetVerlies /
100;
} else {
setState(() {
totaalRecht = 0.00;
});
}
setState(() {
verwachtVoorschotTachtigProcent =
totaalRecht * 0.8;
verwachtVoorschotTachtigProcentPerMaand =
verwachtVoorschotTachtigProcent / 3;
});
print(
'totaal recht is € ${totaalRecht.round()}');
print(
'verwachtVoorschotTachtigProcent is € ${verwachtVoorschotTachtigProcent.round()}');
print(
'verwachtVoorschotTachtigProcentPerMaand is € ${verwachtVoorschotTachtigProcentPerMaand.round()}');
}),
uhm. for me everything is fine. Please use 0.1.1 version.
Is your emulator iOS or Android?
and then flutter clean
might me helpful? :)
I'm using the web emulator (chrome). When I input a 0 nothing gets echoed in the textfield. The red chart window says Unsupported operation NaN.
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
path_provider: ^1.6.10
adobe_xd: ^0.1.4
dropdownfield: ^1.0.3
date_range_picker: ^1.0.6
provider: ^4.1.2
intl: ^0.16.1
flutter_localizations:
sdk: flutter
The following adds the Cupertino Icons font to your application.
Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
html: ^0.14.0+3
back_button_interceptor: ^4.2.4
currency_text_input_formatter: ^0.1.1
I'll thy the iOS emulator and flutter clean
I'll deploy the web app and send you a link. Just follow the NOW button on the homescreen. It's in dutch but the bottom two fields will get 0 by most users.
Thank you. If you send me the link.
I'll check it :)
I've tried for web chrome.
everything is fine.
I am really curious. and I have to get the problem :)
Lucky I've got the whole part on one page still, Have to refactor it, I know :-)
import 'package:flutter/material.dart';
import 'package:dropdownfield/dropdownfield.dart';
import 'package:currency_text_input_formatter/currency_text_input_formatter.dart';
enum periode { MaartAprilMei, AprilMeiJuni, JuniJuliAugustus }
enum loonBetalingPeriode { Maand, VierWeken }
class Now extends StatefulWidget {
@override
_NowState createState() => _NowState();
}
class _NowState extends State<Now> {
double jaarOmzetVorigJaar = 0.0;
double gemKwartaalOmzet = 0.0;
double verwachteOmzetInSubsidiePeriode = 0.0;
double omzetVerschil = 0.0;
double percentageOmzetVerlies = 0.0;
double totaleSvLoonSomJanuari = 0.0;
double loonsomMaartAprilMei = 0.0;
double tussentijdseVakantieUitbetalingJanuari = 0.0;
double loonsomOpMaandBasis = 0.0;
double loonsomGedeelteBovenMaxExVakantieInJanuari = 0.0;
double max = 9538.0;
double grondslagNowFactorBopMaandbasis = 0.0;
double grondslagNowFactorBopMaandbasisVermeerderdMetDertigProcent = 0.0;
double totaalRecht = 0.0;
double verwachtVoorschotTachtigProcent = 0.0;
double verwachtVoorschotTachtigProcentPerMaand = 0.0;
bool rechtOpNow = false;
bool reserveertVakantieBijslag = false;
final formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
final width = MediaQuery.of(context).size.width;
if (width > 500) print('current width is $width');
return Scaffold(
appBar: AppBar(
title: Text('NOW voorschot/subsidie'),
),
body: Center(
child: Container(
width: width > 768 ? 600 : width * 0.95,
child: Center(
child: ListView(
children: [
SizedBox(height: 30),
//form
Card(
child: Padding(
padding:
EdgeInsets.symmetric(horizontal: 20, vertical: 20),
child: Form(
key: formKey,
child: Column(children: <Widget>[
Text(
'Berekening NOW op basis van loonsom en omzetverlies'),
SizedBox(height: 15),
Text(
'Wat is de totale omzet over 2019',
style: Theme.of(context).textTheme.headline4,
),
TextField(
cursorColor: Colors.grey[600],
keyboardType: TextInputType.number,
style: Theme.of(context).textTheme.caption,
decoration: InputDecoration(
labelText: 'Totale omzet 2019 '),
inputFormatters: [
CurrencyTextInputFormatter(
locale: 'nl',
decimalDigits: 0,
symbol: '€ ',
)
],
onChanged: (String value) {
try {
jaarOmzetVorigJaar = double.parse(value);
} catch (exception) {
jaarOmzetVorigJaar = 0.0;
}
setState(() {
gemKwartaalOmzet = jaarOmzetVorigJaar / 4;
});
}),
SizedBox(height: 15),
Text(
'Gemiddelde Kwartaalomzet is $gemKwartaalOmzet',
),
SizedBox(
height: 20.0,
),
SizedBox(height: 15),
Text(
'Kies de periode waarover u NOW wilt aanvragen',
style: Theme.of(context).textTheme.headline4,
),
SizedBox(height: 15),
DropDownField(
controller: periodeSubsidieSelected,
hintText: 'Selecteer Periode',
hintStyle: TextStyle(
color: Theme.of(context).primaryColor,
),
labelStyle: TextStyle(
color: Theme.of(context).primaryColor,
),
textStyle: TextStyle(
color: Theme.of(context).primaryColor,
),
enabled: true,
items: periodeSubsidie,
onValueChanged: (value) {
setState(() {
selectPeriode = value;
});
},
),
SizedBox(height: 15),
SizedBox(height: 15),
Text(
'Wat is de verwachte omzet in de periode waarvoor u subsidie aanvraagt',
style: Theme.of(context).textTheme.headline4,
),
TextField(
cursorColor: Colors.grey[600],
keyboardType: TextInputType.number,
style: Theme.of(context).textTheme.caption,
decoration: InputDecoration(
labelText:
'Verwachte omzet in subsidieperiode '),
inputFormatters: [
CurrencyTextInputFormatter(
locale: 'nl',
decimalDigits: 0,
symbol: '€ ',
)
],
onChanged: (String value) {
try {
verwachteOmzetInSubsidiePeriode =
double.parse(value);
} catch (exception) {
verwachteOmzetInSubsidiePeriode = 0.0;
}
setState(() {
omzetVerschil = gemKwartaalOmzet -
verwachteOmzetInSubsidiePeriode;
percentageOmzetVerlies =
omzetVerschil / (gemKwartaalOmzet / 100);
});
}),
SizedBox(height: 15),
Divider(
color: Theme.of(context).primaryColor,
thickness: 5,
),
SizedBox(height: 15),
Text(
'Verwacht percentage omzetverlies is ${percentageOmzetVerlies.toStringAsFixed(2)} %',
),
SizedBox(height: 15),
Divider(
color: Theme.of(context).primaryColor,
thickness: 5,
),
SizedBox(height: 15),
Text(
'Recht op NOW? ${percentageOmzetVerlies > 20 ? "Ja" : "Nee"}',
),
SizedBox(height: 15),
Divider(
color: Theme.of(context).primaryColor,
thickness: 5,
),
SizedBox(height: 15),
Text(
'Wanner betaalt u de salarissen?',
style: Theme.of(context).textTheme.headline4,
),
SizedBox(height: 15),
DropDownField(
controller: salarisBetaalPeriodeSelected,
hintText: 'Betaling Salarissen is per:',
hintStyle: TextStyle(
color: Theme.of(context).primaryColor,
),
labelStyle: TextStyle(
color: Theme.of(context).primaryColor,
),
textStyle: TextStyle(
color: Theme.of(context).primaryColor,
),
enabled: true,
items: salarisBetaalPeriode,
onValueChanged: (value) {
setState(() {
selectPeriode2 = value;
});
},
),
SizedBox(height: 15),
Divider(
color: Theme.of(context).primaryColor,
thickness: 5,
),
SizedBox(height: 15),
Text(
'Wat is de totale SV-Loonsom in januari',
style: Theme.of(context).textTheme.headline4,
),
TextField(
cursorColor: Colors.grey[600],
keyboardType: TextInputType.number,
style: Theme.of(context).textTheme.caption,
decoration: InputDecoration(
labelText: 'totale SV-Loon in januari '),
inputFormatters: [
CurrencyTextInputFormatter(
locale: 'nl',
decimalDigits: 0,
symbol: '€ ',
)
],
onChanged: (String value) {
try {
totaleSvLoonSomJanuari = double.parse(value);
loonsomOpMaandBasis = totaleSvLoonSomJanuari;
} catch (exception) {
totaleSvLoonSomJanuari = 0.0;
}
}),
Container(
child: CheckboxListTile(
title: Text('Reserveert u vakantiegeld?'),
secondary: Icon(Icons.hotel),
value: reserveertVakantieBijslag,
onChanged: (bool value) {
setState(() {
reserveertVakantieBijslag = value;
});
},
),
),
SizedBox(height: 15),
SizedBox(height: 15),
SizedBox(height: 15),
Text(
'Wat is er in januari uitgekeerd aan vakantietoeslag',
style: Theme.of(context).textTheme.headline4,
),
SizedBox(height: 15),
TextField(
cursorColor: Colors.grey[600],
keyboardType: TextInputType.number,
style: Theme.of(context).textTheme.caption,
decoration: InputDecoration(
labelText: 'vakantiegeld in januari ',
),
inputFormatters: [
CurrencyTextInputFormatter(
locale: 'nl',
decimalDigits: 0,
symbol: '€ ',
)
],
onChanged: (String value) {
try {
tussentijdseVakantieUitbetalingJanuari =
double.parse(value);
} catch (exception) {
tussentijdseVakantieUitbetalingJanuari = 0;
}
}),
SizedBox(height: 15),
Text(
'Loonsom op maandbasis is (deze wordt gecorrigeerd als er geen vakantiegeld wordt gereserveerd is $loonsomOpMaandBasis) ',
style: Theme.of(context).textTheme.headline4,
),
SizedBox(height: 15),
Text(
'Loonsomgedeelte boven $max excl. uitbetaald vakantiegeld \nin januari per werknemer',
style: Theme.of(context).textTheme.headline4,
),
SizedBox(height: 15),
TextField(
cursorColor: Colors.grey[600],
keyboardType: TextInputType.number,
style: Theme.of(context).textTheme.caption,
decoration: InputDecoration(
labelText: 'Loonsomgedeelte boven $max'),
inputFormatters: [
CurrencyTextInputFormatter(
locale: 'nl',
decimalDigits: 0,
symbol: '€ ',
)
],
onChanged: (String value) {
try {
if (reserveertVakantieBijslag == true) {
loonsomOpMaandBasis = loonsomOpMaandBasis;
} else {
loonsomOpMaandBasis =
(loonsomOpMaandBasis * 0.926);
}
loonsomGedeelteBovenMaxExVakantieInJanuari =
double.parse(value);
} catch (exception) {
loonsomGedeelteBovenMaxExVakantieInJanuari =
0;
}
loonsomOpMaandBasis = loonsomOpMaandBasis -
loonsomGedeelteBovenMaxExVakantieInJanuari;
grondslagNowFactorBopMaandbasis =
loonsomOpMaandBasis;
setState(() {
grondslagNowFactorBopMaandbasisVermeerderdMetDertigProcent =
(((loonsomOpMaandBasis / 100) * 30) +
loonsomOpMaandBasis);
});
if (rechtOpNow = true) {
setState(() {});
totaalRecht =
((grondslagNowFactorBopMaandbasisVermeerderdMetDertigProcent *
0.9) *
3) *
percentageOmzetVerlies /
100;
} else {
setState(() {
totaalRecht = 0.00;
});
}
setState(() {
verwachtVoorschotTachtigProcent =
totaalRecht * 0.8;
verwachtVoorschotTachtigProcentPerMaand =
verwachtVoorschotTachtigProcent / 3;
});
print(
'totaal recht is € ${totaalRecht.round()}');
print(
'verwachtVoorschotTachtigProcent is € ${verwachtVoorschotTachtigProcent.round()}');
print(
'verwachtVoorschotTachtigProcentPerMaand is € ${verwachtVoorschotTachtigProcentPerMaand.round()}');
}),
Text(
'Grondslag NOW (factorB) op maandbasis is € ${grondslagNowFactorBopMaandbasis.round()}',
),
SizedBox(height: 15),
Text(
'Grondslag NOW op maandbasis vermeerderd met 30% is € ${grondslagNowFactorBopMaandbasisVermeerderdMetDertigProcent.round()}',
),
SizedBox(height: 15),
Text(
'Totale subsidie waarop voorlopig recht is € ${totaalRecht.round()}',
),
SizedBox(height: 15),
Text(
'Verwacht voorschot van 80% is € ${verwachtVoorschotTachtigProcent.round()}',
),
SizedBox(height: 15),
Text(
'Verwacht voorschot 80% per maand is € ${verwachtVoorschotTachtigProcentPerMaand.round()}',
),
Divider(
color: Theme.of(context).primaryColor,
thickness: 5,
),
SizedBox(height: 15),
SizedBox(height: 15),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: RaisedButton(
onPressed: () {
formKey.currentState?.reset();
setState(() {});
},
child: Text(
'reset',
style:
Theme.of(context).textTheme.headline5,
)),
)
],
),
]),
),
),
),
],
),
)),
),
);
}
}
String selectPeriode = '';
final periodeSubsidieSelected = TextEditingController();
List<String> periodeSubsidie = [
"maart-april-mei",
"april-mei-juni",
'mei-juni-juli'
];
String selectPeriode2 = '';
final salarisBetaalPeriodeSelected = TextEditingController();
List<String> salarisBetaalPeriode = [
"Maand",
"vier weken",
];
There something going on with the last field. No matter what I input it still crashes. And when I type a 0, there nothing in the text field. Maybe locale settings, if it works for you?
@willardjansen
Ok. I found it.
without filling all other field and fill last field - working fine.
with filling all other field and fill last field - crashed :)
You can check if where is the problem :)
Good luck!
Thanks, will carry on debugging.But can you tell me Why I don't see any zeros in any of the text field when I enter them.
I mean why the first digit is a 0.
@willardjansen
Because This is currency. So There is no first digits with 0 currency.
Ok thanks very much for your help.
No problem. :)