1
1
import 'package:async_redux/async_redux.dart' ;
2
2
import 'package:flutter/material.dart' ;
3
3
import 'package:stelaris/api/model/sound/sound_file_source.dart' ;
4
+ import 'package:stelaris/api/state/actions/sound/sound_actions.dart' ;
5
+ import 'package:stelaris/api/state/actions/sound/sound_file_actions.dart' ;
4
6
import 'package:stelaris/api/state/app_state.dart' ;
5
7
import 'package:stelaris/api/state/factory/sound/selected_sound_state.dart' ;
6
8
import 'package:stelaris/feature/base/chips/action_chips.dart' ;
@@ -17,57 +19,77 @@ class SoundFileEntryPage extends StatefulWidget {
17
19
}
18
20
19
21
class _SoundFileEntriesState extends State <SoundFileEntryPage > {
22
+ final ScrollController _scrollController = ScrollController ();
23
+ SelectedSoundView ? _vm;
24
+
25
+ @override
26
+ void initState () {
27
+ super .initState ();
28
+ _scrollController.addListener (_onScroll);
29
+ }
30
+
31
+ @override
32
+ void dispose () {
33
+ _scrollController.removeListener (_onScroll);
34
+ _scrollController.dispose ();
35
+ super .dispose ();
36
+ }
37
+
20
38
@override
21
39
Widget build (BuildContext context) {
22
40
return StoreConnector <AppState , SelectedSoundView >(
23
- vm: () => SelectedSoundState (),
24
- builder: (context, vm) {
25
- return Column (
26
- mainAxisAlignment: MainAxisAlignment .start,
27
- crossAxisAlignment: CrossAxisAlignment .start,
28
- mainAxisSize: MainAxisSize .min,
29
- children: [
30
- verticalSpacing25,
31
- _getActionWidget (context),
32
- const SizedBox (height: 16 ,),
33
- vm.hasNoFiles
34
- ? const Flexible (flex: 1 , child: const EmptyDataWidget ())
35
- : Expanded (
36
- child: ListView .builder (
37
- padding: const EdgeInsets .all (8 ),
38
- itemCount: vm.fileCount, // Example: 10 items
39
- itemBuilder: (context, index) {
40
- return ConstrainedBox (
41
- constraints: const BoxConstraints (
42
- minWidth: 220 ,
43
- maxWidth: 400 ,
44
- ),
45
- child: SoundFileCard (eventModel: vm[index]),
46
- );
47
- },
48
- ),
49
- ),
50
- ],
51
- );
52
- }
41
+ vm: () => SelectedSoundState (),
42
+ onInit: (store) => InitSoundFileAction (),
43
+ onDidChange: (context, store, viewModel) {
44
+ _vm = viewModel;
45
+ },
46
+ builder: (context, vm) {
47
+ return Column (
48
+ mainAxisAlignment: MainAxisAlignment .start,
49
+ crossAxisAlignment: CrossAxisAlignment .start,
50
+ mainAxisSize: MainAxisSize .min,
51
+ children: [
52
+ verticalSpacing25,
53
+ _getActionWidget (context),
54
+ const SizedBox (height: 16 ),
55
+ vm.hasNoFiles
56
+ ? const Flexible (flex: 1 , child: EmptyDataWidget ())
57
+ : Expanded (
58
+ child: ListView .builder (
59
+ controller: _scrollController,
60
+ padding: const EdgeInsets .all (8 ),
61
+ itemCount: vm.fileCount, // Example: 10 items
62
+ itemBuilder: (context, index) {
63
+ return ConstrainedBox (
64
+ constraints: const BoxConstraints (
65
+ minWidth: 220 ,
66
+ maxWidth: 400 ,
67
+ ),
68
+ child: SoundFileCard (eventModel: vm[index]),
69
+ );
70
+ },
71
+ ),
72
+ ),
73
+ ],
74
+ );
75
+ },
53
76
);
54
77
}
55
78
56
79
Widget _getActionWidget (BuildContext context) {
57
80
return ActionChips (
58
81
addCallback: () => _openAddDialog (),
59
- saveCallback: () {} ,
82
+ saveCallback: () => context. dispatch ( SoundDatabaseUpdate ()) ,
60
83
);
61
84
}
62
85
63
86
void _openAddDialog () {
64
87
showDialog (
65
88
context: context,
66
- builder: (context) =>
67
- SoundFileModal (
68
- create: true ,
69
- onSave:
70
- ({
89
+ builder: (context) => SoundFileModal (
90
+ create: true ,
91
+ onSave:
92
+ ({
71
93
required volume,
72
94
required pitch,
73
95
required weight,
@@ -76,30 +98,32 @@ class _SoundFileEntriesState extends State<SoundFileEntryPage> {
76
98
required preload,
77
99
required type,
78
100
}) {
101
+ SoundFileSource fileSource = SoundFileSource (
102
+ name: 'Test' ,
103
+ volume: volume,
104
+ pitch: pitch,
105
+ attenuationDistance: attenuationDistance,
106
+ preload: preload,
107
+ type: type,
108
+ weight: weight,
109
+ );
110
+ context.dispatch (SoundFileSourceAddAction (fileSource));
79
111
// Handle save logic here
80
112
},
81
- ),
113
+ ),
82
114
);
83
115
}
84
116
85
- void _create ({
86
- required double volume,
87
- required double pitch,
88
- required int weight,
89
- required bool stream,
90
- required int attenuationDistance,
91
- required bool preload,
92
- required String type,
93
- }) {
94
- SoundFileSource fileSource = SoundFileSource (name: 'Test' ,
95
- volume: volume,
96
- pitch: pitch,
97
- attenuationDistance: attenuationDistance,
98
- preload: preload,
99
- type: type,
100
- weight: weight
101
- );
117
+ void _onScroll () {
118
+ if (_vm == null ) return ;
119
+
120
+ final SelectedSoundView view = _vm! ;
102
121
103
- //context.dispatch(SelectedS)
122
+ if (_scrollController.position.pixels >=
123
+ _scrollController.position.maxScrollExtent - 200 &&
124
+ view.hasNextPage &&
125
+ ! view.isLoadingFiles) {
126
+ view.onLoadMoreSoundFiles ();
127
+ }
104
128
}
105
129
}
0 commit comments