Company selector
This commit is contained in:
parent
5b50a81d94
commit
b19ab9e45b
|
|
@ -7,6 +7,7 @@ class CustomDrawer extends StatelessWidget {
|
|||
final bool hasMultipleCompanies;
|
||||
final List<CompanyEntity> companies;
|
||||
final String selectedCompanyId;
|
||||
final Function(String) onCompanyChanged;
|
||||
|
||||
CustomDrawer({
|
||||
Key key,
|
||||
|
|
@ -14,6 +15,7 @@ class CustomDrawer extends StatelessWidget {
|
|||
@required this.hasMultipleCompanies,
|
||||
@required this.companies,
|
||||
@required this.selectedCompanyId,
|
||||
@required this.onCompanyChanged,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
|
|
@ -26,6 +28,7 @@ class CustomDrawer extends StatelessWidget {
|
|||
final _multipleCompanies = Align(
|
||||
alignment: FractionalOffset.bottomLeft,
|
||||
child: new DropdownButton<String>(
|
||||
isDense: true,
|
||||
value: this.selectedCompanyId,
|
||||
items: this.companies.map((CompanyEntity company) =>
|
||||
DropdownMenuItem<String>(
|
||||
|
|
@ -35,17 +38,9 @@ class CustomDrawer extends StatelessWidget {
|
|||
).toList(),
|
||||
onChanged: (value) {
|
||||
print('on change: ' + value);
|
||||
this.onCompanyChanged(value);
|
||||
},
|
||||
),
|
||||
/*
|
||||
child: DropdownButton(
|
||||
items: this.companies.map((CompanyEntity company) {
|
||||
return DropdownMenuItem(
|
||||
child: Text(company.name),
|
||||
);
|
||||
}),
|
||||
),
|
||||
*/
|
||||
);
|
||||
|
||||
return Drawer(
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import 'package:redux/redux.dart';
|
|||
import 'package:invoiceninja/ui/app/custom_drawer.dart';
|
||||
import 'package:invoiceninja/redux/app/app_state.dart';
|
||||
import 'package:invoiceninja/redux/company/company_selectors.dart';
|
||||
import 'package:invoiceninja/redux/company/company_actions.dart';
|
||||
import 'package:invoiceninja/data/models/models.dart';
|
||||
|
||||
class CustomDrawerVM extends StatelessWidget {
|
||||
|
|
@ -20,6 +21,7 @@ class CustomDrawerVM extends StatelessWidget {
|
|||
hasMultipleCompanies: vm.hasMultipleCompanies,
|
||||
companies: vm.companies,
|
||||
selectedCompanyId: vm.selectedCompanyId,
|
||||
onCompanyChanged: vm.onCompanyChanged,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
@ -31,12 +33,14 @@ class _ViewModel {
|
|||
final bool hasMultipleCompanies;
|
||||
final List<CompanyEntity> companies;
|
||||
final String selectedCompanyId;
|
||||
final Function(String) onCompanyChanged;
|
||||
|
||||
_ViewModel({
|
||||
@required this.companyName,
|
||||
@required this.hasMultipleCompanies,
|
||||
@required this.companies,
|
||||
@required this.selectedCompanyId,
|
||||
@required this.onCompanyChanged,
|
||||
});
|
||||
|
||||
static _ViewModel fromStore(Store<AppState> store) {
|
||||
|
|
@ -45,6 +49,9 @@ class _ViewModel {
|
|||
hasMultipleCompanies: store.state.companyState2.company.token != null,
|
||||
companies: companiesSelector(store.state),
|
||||
selectedCompanyId: store.state.selectedCompanyId.toString(),
|
||||
onCompanyChanged: (String companyId) {
|
||||
store.dispatch(SelectCompany(int.parse(companyId)));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue