Last active
September 18, 2019 10:24
-
-
Save arifai/1644a70f17f0fe0922d342bf916c8468 to your computer and use it in GitHub Desktop.
The getter 'state' was called on null.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EditAddressForm extends StatefulWidget { | |
final AccountBloc accountBloc; | |
EditAddressForm(this.accountBloc, {Key key}) | |
: super(key: key); | |
@override | |
State<EditAddressForm> createState() => | |
_EditAddressFormState(accountBloc); | |
} | |
class _EditAddressFormState extends State<EditAddressForm> { | |
final _formKey = GlobalKey<FormState>(); | |
final _addressController = TextEditingController(); | |
final _provinceController = TextEditingController(); | |
final _regencyController = TextEditingController(); | |
final _subDistrictController = TextEditingController(); | |
final _villageController = TextEditingController(); | |
final AccountBloc accountBloc; | |
bool _inProgress = false; | |
StoreLocation address; | |
StreamSubscription subs; | |
BuildContext _context; | |
Map<String, String> territory = Map(); | |
_EditAddressFormState(this.accountBloc) { | |
subs = accountBloc.state.listen((AccountState state) { | |
if (state is AddressUpdated) { | |
Navigator.pop(_context, true); | |
} else if (state is EditAddressFailure) { | |
Scaffold.of(_context).showSnackBar( | |
SnackBar( | |
content: Text(state.error), | |
backgroundColor: Colors.red, | |
), | |
); | |
} | |
}); | |
} | |
@override | |
void dispose() { | |
super.dispose(); | |
subs.cancel(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
disableApiErrorHandler(); | |
_onAddressButtonPressed() { | |
accountBloc.dispatch(EditAddress({ | |
"address": _addressController.text, | |
"province": _provinceController.text, | |
"regency": _regencyController.text, | |
"sub_district": _subDistrictController.text, | |
"village": _villageController.text, | |
})); | |
} | |
return BlocBuilder<TerritoryBloc, TerritoryState>( | |
builder: (context, state) { | |
return Center( | |
child: ListView( | |
children: <Widget>[ | |
Padding( | |
padding: EdgeInsets.all(10.0), | |
child: Form( | |
key: _formKey, | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
mainAxisAlignment: MainAxisAlignment.start, | |
children: <Widget>[ | |
Padding( | |
padding: EdgeInsets.only(top: 16, bottom: 10), | |
child: Text( | |
'Alamat Lengkap', | |
style: TextStyle(fontWeight: FontWeight.bold), | |
), | |
), | |
BaseFormField( | |
controller: _addressController, | |
hintText: "Alamat Lengkap", | |
), | |
TerritoryDropdownView( | |
onSelectTerritory: (value, type) { | |
switch (type) { | |
case TerritoryType.province: | |
_provinceController.text = value.name; | |
break; | |
case TerritoryType.district: | |
_regencyController.text = value.name; | |
break; | |
case TerritoryType.subDistrict: | |
_subDistrictController.text = value.name; | |
break; | |
case TerritoryType.village: | |
_villageController.text = value.name; | |
} | |
}, | |
territory: territory ?? Map(), | |
), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: <Widget>[ | |
Padding( | |
padding: EdgeInsets.only(top: 30.0, bottom: 20.0), | |
child: ButtonTheme( | |
// minWidth: MediaQuery.of(context).size.width, | |
child: RaisedButton( | |
onPressed: () { | |
// Navigator.of(context).push(null); | |
}, | |
child: new Text( | |
"Batalkan".toUpperCase(), | |
style: TextStyle(color: Colors.grey), | |
), | |
shape: new RoundedRectangleBorder( | |
side: BorderSide(color: Colors.grey)), | |
color: Colors.white), | |
), | |
), | |
Padding( | |
padding: EdgeInsets.only(top: 30.0, bottom: 20.0), | |
child: ButtonTheme( | |
// minWidth: MediaQuery.of(context).size.width, | |
child: RaisedButton( | |
onPressed: !_inProgress | |
? _onAddressButtonPressed | |
: null, | |
child: new Text( | |
"Simpan".toUpperCase(), | |
style: TextStyle(color: Colors.white), | |
), | |
shape: new RoundedRectangleBorder( | |
side: BorderSide(color: Color(0xff039fc0))), | |
color: Color(0xff039fc0), | |
), | |
), | |
), | |
], | |
), | |
], | |
), | |
), | |
), | |
], | |
), | |
); | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment