Skip to content

Commit 17e4465

Browse files
committed
## [0.1.56] - 21st November, 2018
* Introducing few commonly used widgets: Fetching, NoData, Paginator, PullToRefresh (cherry picked from commit 1dfb720)
1 parent c22a8d4 commit 17e4465

File tree

10 files changed

+307
-11
lines changed

10 files changed

+307
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.1.56] - 21st November, 2018
2+
3+
* Introducing few commonly used widgets: Fetching, NoData, Paginator, PullToRefresh
4+
15
## [0.1.55] - 14th November, 2018
26

37
* AdharaStatefulWidget~isFirstLoadComplete was returning wrong status, issue fixed.

example/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@ class _AppState extends AdharaState<App> {
113113
//import 'appconfig.dart'; //TODO uncomment
114114
//import 'package:adhara/adhara.dart'; //TODO uncomment
115115

116-
void main() => AdharaApp.initWithConfig(AppConfig());
116+
void main() => AdharaApp.init(AppConfig());

lib/styles/colors.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AdharaColors {
2+
3+
4+
5+
}

lib/styles/text_styles.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'package:flutter/material.dart';
2+
3+
class AdharaStyles {
4+
5+
static const textMuted = const TextStyle(
6+
color: Colors.black12,
7+
fontWeight: FontWeight.w400,
8+
fontFamily: "SFProText",
9+
fontStyle: FontStyle.normal,
10+
fontSize: 18.0
11+
);
12+
13+
}

lib/widgets/fetching.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import 'package:flutter/material.dart';
2+
3+
import '../resources/r.dart';
4+
import '../styles/text_styles.dart';
5+
import 'no_data.dart';
6+
7+
8+
class Fetching extends NoData{
9+
10+
final String text;
11+
final Widget bottom;
12+
final TextStyle textStyle;
13+
final String assetPath;
14+
15+
Fetching({
16+
Key key,
17+
this.bottom,
18+
this.text: "Loading...",
19+
this.textStyle: AdharaStyles.textMuted,
20+
this.assetPath
21+
}): super(key: key);
22+
23+
@override
24+
Widget buildWithResources(BuildContext context, Resources r){
25+
String _assetPath = assetPath ?? r.config.fromFile['fetchingImage'] ?? "assets/animations/fetching.gif";
26+
return Center(
27+
child: Column(
28+
crossAxisAlignment: CrossAxisAlignment.center,
29+
mainAxisAlignment: MainAxisAlignment.center,
30+
children: [
31+
Container(
32+
width: 120.0,
33+
child: Center(
34+
child: Image.asset(_assetPath)
35+
),
36+
),
37+
bottom ?? text!=null?Text(text, style: textStyle, textAlign: TextAlign.center,):Container(),
38+
]
39+
)
40+
);
41+
}
42+
43+
}

lib/widgets/no_data.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'package:flutter/material.dart';
2+
3+
import '../resources/r.dart';
4+
import '../styles/text_styles.dart';
5+
import 'stateless_widget.dart';
6+
7+
8+
class NoData extends AdharaStatelessWidget{
9+
10+
final String displayText;
11+
final TextStyle textStyle;
12+
13+
NoData({
14+
Key key,
15+
this.displayText: "No Data Availalbe",
16+
this.textStyle: AdharaStyles.textMuted
17+
}) : super(key: key);
18+
19+
@override
20+
Widget buildWithResources(BuildContext context, Resources r){
21+
return Center(
22+
child: Text(displayText, style: textStyle)
23+
);
24+
}
25+
26+
}

lib/widgets/paginator.dart

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
import 'dart:async';
2+
3+
import 'package:flutter/material.dart';
4+
5+
import 'pull_to_refresh.dart';
6+
import 'stateful_widget.dart';
7+
8+
enum PaginatorTypes{
9+
CUSTOM_SCROLL_VIEW, LIST_VIEW
10+
}
11+
12+
typedef Future<bool> OnPageChange(int);
13+
14+
class Paginator extends AdharaStatefulWidget{
15+
16+
final List<Widget> children;
17+
final OnPageChange onPageChange;
18+
final Function onPageLoaded;
19+
final PaginatorTypes listType;
20+
final IndexedWidgetBuilder itemBuilder;
21+
final bool reverse;
22+
final int itemCount;
23+
final bool endNavigationOnLastPage;
24+
final Widget loadingWidget;
25+
26+
Paginator({
27+
Key key,
28+
@required this.onPageChange,
29+
@required this.onPageLoaded,
30+
this.children,
31+
this.itemBuilder,
32+
this.listType: PaginatorTypes.CUSTOM_SCROLL_VIEW,
33+
this.itemCount,
34+
this.reverse: false,
35+
this.endNavigationOnLastPage: false,
36+
this.loadingWidget
37+
}):
38+
assert(children!=null || itemBuilder!=null),
39+
super(key: key);
40+
41+
@override
42+
_PaginatorState createState() => new _PaginatorState();
43+
44+
}
45+
46+
class _PaginatorState extends AdharaState<Paginator>{
47+
48+
String get tag => "Paginator";
49+
ScrollController _scrollController;
50+
bool isLoading = false;
51+
int page = 0;
52+
53+
@override
54+
initState(){
55+
super.initState();
56+
_scrollController = ScrollController();
57+
_scrollController.addListener(onScroll);
58+
}
59+
60+
@override
61+
void dispose() {
62+
_scrollController.removeListener(onScroll);
63+
_scrollController.dispose();
64+
super.dispose();
65+
}
66+
67+
get didHitBottom{
68+
return _scrollController.position.pixels == _scrollController.position.maxScrollExtent;
69+
}
70+
71+
bool hasMore = true;
72+
onScroll() async {
73+
if(!isLoading && didHitBottom){
74+
isLoading = true;
75+
setState((){});
76+
if(widget.endNavigationOnLastPage && !hasMore){
77+
return;
78+
}
79+
// _scrollController.position.setPixels(_scrollController.position.pixels+10.0); //Throwing exception - Need to check back
80+
hasMore = await widget.onPageChange(page+1);
81+
if(hasMore) page++;
82+
await widget.onPageLoaded(page);
83+
isLoading = false;
84+
setState((){});
85+
}
86+
}
87+
88+
bool get isListView{
89+
return widget.listType == PaginatorTypes.LIST_VIEW;
90+
}
91+
92+
Widget get indicator{
93+
if(isLoading){
94+
return widget.loadingWidget ?? Container(
95+
child: Row(
96+
crossAxisAlignment: CrossAxisAlignment.center,
97+
mainAxisAlignment: MainAxisAlignment.center,
98+
mainAxisSize: MainAxisSize.max,
99+
children: <Widget>[
100+
Container(
101+
width: 20.0,
102+
height: 20.0,
103+
padding: EdgeInsets.all(5.0),
104+
child: CircularProgressIndicator(strokeWidth: 2.0),
105+
),
106+
Text('${r.getString("loading")}')
107+
],
108+
),
109+
height: 30.0,
110+
);
111+
}
112+
return Container(
113+
height: 0.1,
114+
);
115+
}
116+
117+
get children{
118+
List<Widget> _children = List<Widget>.from(widget.children);
119+
//adding the loading text...
120+
if(isListView) _children.add(indicator);
121+
else _children.add(SliverList(delegate: SliverChildListDelegate([indicator])));
122+
//return all elements including loading text
123+
return _children;
124+
}
125+
126+
Widget get paginator{
127+
if(widget.itemBuilder!=null){
128+
return ListView.builder(
129+
reverse: widget.reverse,
130+
itemBuilder: widget.itemBuilder,
131+
itemCount: widget.itemCount,
132+
controller: _scrollController,
133+
);
134+
}
135+
if(isListView){
136+
return ListView(
137+
controller: _scrollController,
138+
children: children,
139+
);
140+
}
141+
return CustomScrollView(
142+
controller: _scrollController,
143+
slivers: children,
144+
);
145+
}
146+
147+
@override
148+
Widget build(BuildContext context){
149+
return PullToRefresh(
150+
processing: () async {
151+
page = 0;
152+
await widget.onPageChange(page);
153+
},
154+
postRefresh: () async {
155+
await widget.onPageLoaded(page);
156+
},
157+
child: paginator
158+
);
159+
}
160+
161+
}

lib/widgets/pull_to_refresh.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import 'dart:async';
2+
3+
import 'package:flutter/material.dart';
4+
5+
import 'stateful_widget.dart';
6+
7+
8+
class PullToRefresh extends AdharaStatefulWidget{
9+
10+
final Widget child;
11+
final Function postRefresh;
12+
final Function processing;
13+
14+
PullToRefresh({
15+
Key key,
16+
this.postRefresh,
17+
@required this.processing,
18+
@required this.child
19+
}): super(key: key);
20+
21+
@override
22+
_PullToRefreshState createState() => new _PullToRefreshState();
23+
24+
}
25+
26+
class _PullToRefreshState extends AdharaState<PullToRefresh>{
27+
28+
String get tag => "PullToRefresh";
29+
30+
31+
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey = new GlobalKey<RefreshIndicatorState>();
32+
33+
Future<Null> _handleRefresh() async {
34+
// AppDataInterface dataInterface = r.dataInterface;
35+
if(widget.processing!=null) {
36+
await widget.processing();
37+
}
38+
// await dataInterface.sync();
39+
if(widget.postRefresh!=null){
40+
widget.postRefresh();
41+
}
42+
}
43+
44+
@override
45+
Widget build(BuildContext context){
46+
return RefreshIndicator(
47+
key: _refreshIndicatorKey,
48+
onRefresh: _handleRefresh,
49+
child: widget.child,
50+
);
51+
}
52+
53+
}

pubspec.lock

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,6 @@ packages:
8181
description: flutter
8282
source: sdk
8383
version: "0.0.99"
84-
socket_io:
85-
dependency: "direct main"
86-
description:
87-
path: "."
88-
ref: HEAD
89-
resolved-ref: db2f26b8cd457f82830aa5598966fcaa5444da2f
90-
url: "https://github.com/AlexeySemigradsky/socket_io.git"
91-
source: git
92-
version: "0.1.0"
9384
source_span:
9485
dependency: transitive
9586
description:

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: adhara
22
description: Base framework for Flutter Apps with intense networking and data interactivity
3-
version: 0.1.55
3+
version: 0.1.56
44
author: Rohit R. Abbadi <[email protected]>
55
homepage: https://infitio.com
66

0 commit comments

Comments
 (0)