1
- import 'dart:developer' ;
2
-
3
1
import 'package:ensemble/framework/action.dart' ;
4
2
import 'package:ensemble/framework/error_handling.dart' ;
5
3
import 'package:ensemble/framework/event.dart' ;
6
- import 'package:ensemble/framework/extensions.dart' ;
7
4
import 'package:ensemble/framework/studio/studio_debugger.dart' ;
8
5
import 'package:ensemble/framework/view/footer.dart' ;
9
- import 'package:ensemble/framework/view/page_group.dart' ;
10
6
import 'package:ensemble/framework/widget/has_children.dart' ;
11
7
import 'package:ensemble/framework/widget/view_util.dart' ;
12
8
import 'package:ensemble/framework/widget/widget.dart' ;
@@ -15,24 +11,18 @@ import 'package:ensemble/layout/templated.dart';
15
11
import 'package:ensemble/model/pull_to_refresh.dart' ;
16
12
import 'package:ensemble/page_model.dart' ;
17
13
import 'package:ensemble/screen_controller.dart' ;
18
- import 'package:ensemble/util/layout_utils.dart' ;
19
14
import 'package:ensemble/util/utils.dart' ;
20
- import 'package:ensemble/framework/theme/theme_manager.dart' ;
21
- import 'package:ensemble/widget/carousel.dart' ;
22
15
import 'package:ensemble/widget/helpers/pull_to_refresh_container.dart' ;
23
- import 'package:ensemble/widget/helpers/widgets.dart' ;
24
16
import 'package:ensemble_ts_interpreter/invokables/invokable.dart' ;
25
17
import 'package:flutter/cupertino.dart' ;
26
18
import 'package:flutter/foundation.dart' ;
27
19
import 'package:flutter/material.dart' as flutter;
28
- import 'package:ensemble/util/platform.dart' ;
29
20
import 'package:flutter/material.dart' ;
30
-
31
- import '../../widget/helpers/controllers.dart' ;
32
21
import 'box_utils.dart' ;
33
22
34
23
class Column extends BoxLayout {
35
24
static const type = 'Column' ;
25
+
36
26
Column ({Key ? key}) : super (key: key);
37
27
38
28
@override
@@ -44,6 +34,8 @@ class Column extends BoxLayout {
44
34
Map <String , Function > setters () {
45
35
Map <String , Function > entries = super .setters ();
46
36
entries.addAll ({
37
+ 'pullToRefresh' : (input) =>
38
+ _controller.pullToRefresh = PullToRefresh .fromMap (input, this ),
47
39
'onPullToRefresh' : (funcDefinition) => _controller.onPullToRefresh =
48
40
EnsembleAction .fromYaml (funcDefinition, initiator: this ),
49
41
'pullToRefreshOptions' : (input) => _controller.pullToRefreshOptions =
@@ -55,6 +47,7 @@ class Column extends BoxLayout {
55
47
56
48
class Row extends BoxLayout {
57
49
static const type = 'Row' ;
50
+
58
51
Row ({Key ? key}) : super (key: key);
59
52
60
53
@override
@@ -65,6 +58,7 @@ class Row extends BoxLayout {
65
58
66
59
class Flex extends BoxLayout {
67
60
static const type = 'Flex' ;
61
+
68
62
Flex ({Key ? key}) : super (key: key);
69
63
70
64
@override
@@ -98,6 +92,7 @@ abstract class BoxLayout extends StatefulWidget
98
92
BoxLayout ({Key ? key}) : super (key: key);
99
93
100
94
final BoxLayoutController _controller = BoxLayoutController ();
95
+
101
96
@override
102
97
BoxLayoutController get controller => _controller;
103
98
@@ -262,7 +257,8 @@ class BoxLayoutState extends WidgetState<BoxLayout>
262
257
controller: widget._controller,
263
258
ignoresMargin: widget is Column );
264
259
265
- if (widget._controller.scrollable) {
260
+ var pullToRefresh = _getPullToRefresh ();
261
+ if (widget._controller.scrollable || pullToRefresh != null ) {
266
262
FooterScope ? footerScope = FooterScope .of (context);
267
263
rtn = ScrollableColumn (
268
264
child: SingleChildScrollView (
@@ -273,33 +269,40 @@ class BoxLayoutState extends WidgetState<BoxLayout>
273
269
: null ,
274
270
scrollDirection:
275
271
widget.isVertical () ? Axis .vertical : Axis .horizontal,
276
- physics: widget._controller.onPullToRefresh != null
272
+ physics: pullToRefresh != null
277
273
? const AlwaysScrollableScrollPhysics ()
278
274
: null ,
279
275
child: rtn),
280
276
);
281
277
282
- if (widget is Column && widget._controller.onPullToRefresh != null ) {
283
- rtn = PullToRefreshContainer (
284
- options: widget._controller.pullToRefreshOptions,
285
- onRefresh: _pullToRefresh,
286
- contentWidget: rtn);
278
+ if (widget is Column && pullToRefresh != null ) {
279
+ rtn =
280
+ PullToRefreshContainer (options: pullToRefresh, contentWidget: rtn);
287
281
}
288
282
}
289
283
290
- // for Column we add margin at the end, just in case it is inside a Scrollable or PulltoRefresh
284
+ // for Column we add margin at the end, just in case it is inside a Scrollable or PullToRefresh
291
285
if (widget is Column && widget._controller.margin != null ) {
292
286
rtn = Padding (padding: widget._controller.margin! , child: rtn);
293
287
}
294
288
295
289
return rtn;
296
290
}
297
291
298
- Future <void > _pullToRefresh () async {
299
- if (widget._controller.onPullToRefresh != null ) {
300
- await ScreenController ()
301
- .executeAction (context, widget._controller.onPullToRefresh! );
302
- }
292
+ // backward compatible
293
+ PullToRefresh ? _getPullToRefresh () {
294
+ return widget._controller.pullToRefresh ??
295
+ (widget._controller.onPullToRefresh != null
296
+ ? PullToRefresh (
297
+ widget._controller.onPullToRefresh! ,
298
+ indicatorType:
299
+ widget._controller.pullToRefreshOptions? .indicatorType,
300
+ indicatorMinDuration: widget
301
+ ._controller.pullToRefreshOptions? .indicatorMinDuration,
302
+ indicatorPadding:
303
+ widget._controller.pullToRefreshOptions? .indicatorPadding,
304
+ )
305
+ : null );
303
306
}
304
307
305
308
void _onItemTap (int index) {
0 commit comments