Skip to content

Commit 8a4ea56

Browse files
committed
Work on pagination
1 parent b30b773 commit 8a4ea56

File tree

1 file changed

+79
-55
lines changed

1 file changed

+79
-55
lines changed
Lines changed: 79 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'package:async_redux/async_redux.dart';
22
import 'package:flutter/material.dart';
33
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';
46
import 'package:stelaris/api/state/app_state.dart';
57
import 'package:stelaris/api/state/factory/sound/selected_sound_state.dart';
68
import 'package:stelaris/feature/base/chips/action_chips.dart';
@@ -17,57 +19,77 @@ class SoundFileEntryPage extends StatefulWidget {
1719
}
1820

1921
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+
2038
@override
2139
Widget build(BuildContext context) {
2240
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+
},
5376
);
5477
}
5578

5679
Widget _getActionWidget(BuildContext context) {
5780
return ActionChips(
5881
addCallback: () => _openAddDialog(),
59-
saveCallback: () {},
82+
saveCallback: () => context.dispatch(SoundDatabaseUpdate()),
6083
);
6184
}
6285

6386
void _openAddDialog() {
6487
showDialog(
6588
context: context,
66-
builder: (context) =>
67-
SoundFileModal(
68-
create: true,
69-
onSave:
70-
({
89+
builder: (context) => SoundFileModal(
90+
create: true,
91+
onSave:
92+
({
7193
required volume,
7294
required pitch,
7395
required weight,
@@ -76,30 +98,32 @@ class _SoundFileEntriesState extends State<SoundFileEntryPage> {
7698
required preload,
7799
required type,
78100
}) {
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));
79111
// Handle save logic here
80112
},
81-
),
113+
),
82114
);
83115
}
84116

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!;
102121

103-
//context.dispatch(SelectedS)
122+
if (_scrollController.position.pixels >=
123+
_scrollController.position.maxScrollExtent - 200 &&
124+
view.hasNextPage &&
125+
!view.isLoadingFiles) {
126+
view.onLoadMoreSoundFiles();
127+
}
104128
}
105129
}

0 commit comments

Comments
 (0)