Created
June 5, 2020 09:42
-
-
Save dukesteen/bda82b62e8d36aad91455a2a151fc996 to your computer and use it in GitHub Desktop.
Stat card code
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
import 'package:flutter/material.dart'; | |
import 'package:salarix/styles.dart'; | |
import 'package:salarix/ui/views/smart_widgets/salary_entry_card/stat_card/stat_card_types.dart'; | |
import 'package:salarix/ui/views/smart_widgets/salary_entry_card/stat_card/stat_card_viewmodel.dart'; | |
import 'package:stacked/stacked.dart'; | |
class StatCard extends ViewModelWidget<StatCardTypes> { | |
final StatCardTypes cardType; | |
StatCard({Key key, this.cardType}); | |
@override | |
Widget build(BuildContext context, StatCardTypes cardType) { | |
return ViewModelBuilder<StatCardViewModel>.reactive( | |
viewModelBuilder: () => StatCardViewModel(cardType: cardType), | |
builder: (context, model, child) => Container( | |
//width: 190.0, | |
height: 120.0, | |
child: Card( | |
margin: EdgeInsets.only( | |
left: 19.0, | |
bottom: 28.0, | |
), | |
shape: RoundedRectangleBorder( | |
borderRadius: BorderRadius.circular(22.0), | |
), | |
child: Padding( | |
padding: EdgeInsets.only(left: 18.0, top: 18.0, right: 18.0), | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.start, | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: <Widget>[ | |
Text( | |
model.title, | |
style: UiTextStyles.montserrat16ptSemiBoldRed, | |
), | |
SingleChildScrollView( | |
scrollDirection: Axis.horizontal, | |
child: Text( | |
model.dataToDisplay.toString(), | |
style: UiTextStyles.montserrat30ptBoldSpaceCadet, | |
), | |
), | |
], | |
), | |
), | |
), | |
), | |
); | |
} | |
} |
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
import 'package:intl/intl.dart'; | |
import 'package:salarix/app/locator.dart'; | |
import 'package:salarix/models/salary_model.dart'; | |
import 'package:salarix/services/salary_service.dart'; | |
import 'package:salarix/ui/views/smart_widgets/salary_entry_card/stat_card/stat_card_types.dart'; | |
import 'package:stacked/stacked.dart'; | |
class StatCardViewModel extends ReactiveViewModel { | |
SalaryService _salaryService = locator<SalaryService>(); | |
final currencyFormatter = new NumberFormat("#,##0.00", "en_US"); | |
String _title; | |
String get title => _title; | |
List<SalaryModel> get salaryModels => _salaryService.salaryModels; | |
String get dataToDisplay { | |
if (cardType == StatCardTypes.SALARY) { | |
return '€ ' + | |
currencyFormatter.format(salaryModels.fold( | |
0, | |
(previousValue, element) => | |
previousValue + (element.hoursWorked * element.hourlyWage))); | |
} else if (cardType == StatCardTypes.HOURS) { | |
return salaryModels | |
.fold(0, | |
(previousValue, element) => previousValue + element.hoursWorked) | |
.toString(); | |
} | |
return null; | |
} | |
final StatCardTypes cardType; | |
StatCardViewModel({this.cardType}) { | |
print('StatCard initialised'); | |
if (cardType == StatCardTypes.SALARY) { | |
_title = 'Totaal bedrag'; | |
} else if (cardType == StatCardTypes.HOURS) { | |
_title = 'Totaal uren'; | |
} | |
} | |
@override | |
List<ReactiveServiceMixin> get reactiveServices => [_salaryService]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment