Line data Source code
1 : import 'package:flutter/material.dart';
2 : import 'package:flutter_redux/flutter_redux.dart';
3 : import 'package:redfire/extensions.dart';
4 :
5 : import '../../app_state.dart';
6 : import '../../projects/actions/tap_projects_action.dart';
7 : import '../actions/set_selected_organisation_action.dart';
8 : import '../models/organisation_model.dart';
9 : import '../models/organisation_selector_view_model.dart';
10 :
11 : class OrganisationSelector extends StatelessWidget {
12 2 : const OrganisationSelector({Key? key}) : super(key: key);
13 :
14 1 : @override
15 : Widget build(BuildContext context) {
16 1 : return StoreConnector<AppState, OrganisationSelectorViewModel>(
17 : distinct: true,
18 4 : converter: (store) => store.state.organisations.selector,
19 1 : builder: (context, selector) {
20 1 : return DropdownButton<OrganisationModel>(
21 1 : value: selector.selected,
22 : icon: const Icon(Icons.arrow_drop_down),
23 : iconSize: 24,
24 : elevation: 16,
25 : style: const TextStyle(color: Colors.deepPurple),
26 1 : underline: Container(
27 : height: 2,
28 : color: Colors.deepPurpleAccent,
29 : ),
30 0 : onChanged: (OrganisationModel? selected) {
31 : if (selected != null) {
32 0 : context.dispatch<AppState>(
33 0 : SetSelectedOrganisationAction(selected));
34 0 : context.dispatch<AppState>(
35 0 : TapProjectsAction(organisationId: selected.id));
36 : }
37 : },
38 2 : items: selector.all.map<DropdownMenuItem<OrganisationModel>>(
39 0 : (OrganisationModel value) {
40 0 : return DropdownMenuItem<OrganisationModel>(
41 : value: value,
42 0 : child: Text(value.name),
43 : );
44 1 : }).toList(),
45 : );
46 : });
47 : }
48 : }
|