-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontroller_vm.dart
More file actions
102 lines (89 loc) · 2.37 KB
/
controller_vm.dart
File metadata and controls
102 lines (89 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import 'package:devfest/core/router/navigator.dart';
import 'package:devfest/views/controller_page/controller_page_item.dart';
import 'package:devfest/views/controller_page/tabs/home/home_page.dart';
import 'package:devfest/views/controller_page/tabs/profile/profile_page.dart';
import 'package:devfest/views/maps_page/maps_page.dart';
import 'package:devfest/views/speakers_page/speakers_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import '../../../views/controller_page/tabs/agenda/agenda_page.dart';
class ControllerVM extends ChangeNotifier {
final Reader read;
ControllerVM(this.read);
int _currentTab = 0;
int get currentTab => _currentTab;
set currentTab(int val) {
_currentTab = val;
notifyListeners();
}
Widget? _currentPage;
Widget? get currentPage => _currentPage;
set currentPage(Widget? val) {
_currentPage = val;
notifyListeners();
}
Widget get defaultPage => IndexedStack(
index: currentTab,
children: [...pages.map((e) => e.page)],
);
final pages = <ControllerPageItem>[
const ControllerPageItem(
page: HomePage(
key: PageStorageKey<String>('home'),
),
image: 'home',
name: 'Home',
),
const ControllerPageItem(
page: AgendaPage(
key: PageStorageKey<String>('agenda'),
),
image: 'agenda',
name: 'Agenda',
),
const ControllerPageItem(
page: MapsPage(
key: PageStorageKey<String>('map'),
),
image: 'map',
name: 'Map',
),
const ControllerPageItem(
page: SpeakersPage(
key: PageStorageKey<String>('speakers'),
),
image: 'speakers',
name: 'Speakers',
),
const ControllerPageItem(
page: ProfilePage(
key: PageStorageKey<String>('You'),
),
image: 'you',
name: 'You',
),
];
/// Handle bottom navigation bar index change
void onPageChanged(int index) {
if (currentTab == index) {
return;
}
currentTab = index;
}
void returnToDefaultPage() => AppNavigator.pop();
void goToTalkCategories() {
AppNavigator.pushNamed(Routes.allTalkPage);
}
void goToAgenda() {
currentTab = 1;
notifyListeners();
}
void goToMap() {
currentTab = 2;
notifyListeners();
}
void goToSpeakers() {
currentTab = 3;
notifyListeners();
}
}