Skip to content

Commit 2a12c23

Browse files
authored
Merge pull request #3 from ngomile/main
Rely on source sorting listings and other changes
2 parents e58bcb3 + 72bfbf3 commit 2a12c23

File tree

5 files changed

+67
-46
lines changed

5 files changed

+67
-46
lines changed

lib/custom_widgets/job_list_retriever.dart

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@ import 'package:flutter/material.dart';
44
import 'package:katswiri/custom_widgets/custom_widgets.dart';
55
import 'package:katswiri/models/models.dart';
66
import 'package:katswiri/sources/sources.dart';
7-
import 'package:katswiri/utils/utils.dart';
87

98
class JobListRetriever extends StatefulWidget {
109
const JobListRetriever({
1110
super.key,
1211
required this.source,
1312
this.filter,
1413
this.primary,
15-
this.sortJobs = true,
1614
});
1715

1816
final Source source;
1917
final Map<String, String>? filter;
2018
final bool? primary;
21-
final bool sortJobs;
2219

2320
@override
2421
State<JobListRetriever> createState() => _JobListRetrieverState();
@@ -33,7 +30,7 @@ class _JobListRetrieverState extends State<JobListRetriever>
3330
bool _loading = true;
3431
bool _hasError = false;
3532
String _errMsg = '';
36-
bool _showButton = false;
33+
bool _showScrollTop = false;
3734

3835
late final StreamController<List<Job>> _streamController =
3936
StreamController.broadcast();
@@ -79,15 +76,14 @@ class _JobListRetrieverState extends State<JobListRetriever>
7976
stream: _streamController.stream,
8077
builder: _builder,
8178
),
82-
if (_showButton)
83-
Positioned(
84-
bottom: 16,
85-
right: 16,
86-
child: FloatingActionButton(
87-
onPressed: _scrollToTop,
88-
child: const Icon(Icons.arrow_upward),
89-
),
79+
Positioned(
80+
right: 16.0,
81+
bottom: 16.0,
82+
child: _ScrollToTop(
83+
onPressed: _scrollToTop,
84+
showScrollTop: _showScrollTop,
9085
),
86+
),
9187
],
9288
);
9389
}
@@ -134,7 +130,6 @@ class _JobListRetrieverState extends State<JobListRetriever>
134130
controller: _scrollController,
135131
padding: const EdgeInsets.only(top: 4.0),
136132
primary: widget.primary,
137-
shrinkWrap: true,
138133
itemBuilder: (context, index) => widgetList[index],
139134
itemCount: widgetList.length,
140135
);
@@ -176,26 +171,20 @@ class _JobListRetrieverState extends State<JobListRetriever>
176171
}
177172

178173
void _onShowToTop() {
179-
if (_scrollController.offset >= 100 && !_showButton) {
174+
if (_scrollController.offset >= 100 && !_showScrollTop) {
180175
setState(() {
181-
_showButton = true;
176+
_showScrollTop = true;
182177
});
183-
} else if (_scrollController.offset < 100 && _showButton) {
178+
} else if (_scrollController.offset < 100 && _showScrollTop) {
184179
setState(() {
185-
_showButton = false;
180+
_showScrollTop = false;
186181
});
187182
}
188183
}
189184

190185
void _onData(List<Job> jobs) {
191186
_jobs.addAll(jobs);
192187

193-
if (widget.sortJobs) {
194-
_jobs.sort(
195-
(a, b) => postedDate(b.posted).compareTo(postedDate(a.posted)),
196-
);
197-
}
198-
199188
setState(() {
200189
_page++;
201190
_loading = false;
@@ -239,3 +228,34 @@ class _JobListRetrieverState extends State<JobListRetriever>
239228
);
240229
}
241230
}
231+
232+
class _ScrollToTop extends StatefulWidget {
233+
const _ScrollToTop({
234+
required this.onPressed,
235+
required this.showScrollTop,
236+
});
237+
238+
final void Function() onPressed;
239+
final bool showScrollTop;
240+
241+
@override
242+
State<_ScrollToTop> createState() => __ScrollToTopState();
243+
}
244+
245+
class __ScrollToTopState extends State<_ScrollToTop> {
246+
@override
247+
Widget build(BuildContext context) {
248+
return AnimatedOpacity(
249+
opacity: widget.showScrollTop ? 1.0 : 0.0,
250+
duration: const Duration(milliseconds: 800),
251+
curve: Curves.elasticIn,
252+
child: Visibility(
253+
visible: widget.showScrollTop,
254+
child: FloatingActionButton(
255+
onPressed: widget.onPressed,
256+
child: const Icon(Icons.arrow_upward),
257+
),
258+
),
259+
);
260+
}
261+
}

lib/custom_widgets/tabbed_sources.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class _TabbedSourcesState extends State<TabbedSources>
6161
tabController: _tabController,
6262
sources: _sources,
6363
filter: widget.filter,
64-
sortJobs: widget.sortJobs,
6564
),
6665
),
6766
],
@@ -122,14 +121,12 @@ class TabBarViewSection extends StatefulWidget {
122121
required this.tabController,
123122
required this.sources,
124123
this.filter,
125-
this.sortJobs = true,
126124
super.key,
127125
});
128126

129127
final TabController tabController;
130128
final List<Source> sources;
131129
final Map<String, String>? filter;
132-
final bool sortJobs;
133130

134131
@override
135132
State<TabBarViewSection> createState() => _TabBarViewSectionState();
@@ -145,7 +142,6 @@ class _TabBarViewSectionState extends State<TabBarViewSection> {
145142
(source) => JobListRetriever(
146143
source: source,
147144
filter: widget.filter,
148-
sortJobs: widget.sortJobs,
149145
),
150146
)
151147
.toList(),

lib/screens/about_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class _AppDetailSection extends StatelessWidget {
6565
),
6666
),
6767
TextSpan(
68-
text: 'Version 1.0.1\n',
68+
text: 'Version 1.0.2\n',
6969
style: TextStyle(
7070
color: Theme.of(context).colorScheme.secondary,
7171
),

lib/screens/webview_screen.dart

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,28 @@ class _WebViewScreenState extends State<WebViewScreen> {
3737
..setJavaScriptMode(JavaScriptMode.unrestricted)
3838
..loadRequest(Uri.parse(_url))
3939
..setNavigationDelegate(
40-
NavigationDelegate(onProgress: (progress) {
41-
setState(() {
42-
_progressValue = progress / 100;
43-
});
44-
}, onPageStarted: (_) {
45-
setState(() {
46-
_progressValue = 0.0;
47-
});
48-
}, onPageFinished: (_) {
49-
setState(() {
50-
_progressValue = 1.0;
51-
});
52-
}, onUrlChange: (UrlChange urlChange) {
53-
setState(() {
54-
_url = urlChange.url ?? '';
55-
});
56-
}),
40+
NavigationDelegate(
41+
onProgress: (progress) {
42+
setState(() {
43+
_progressValue = progress / 100;
44+
});
45+
},
46+
onPageStarted: (_) {
47+
setState(() {
48+
_progressValue = 0.0;
49+
});
50+
},
51+
onPageFinished: (_) {
52+
setState(() {
53+
_progressValue = 1.0;
54+
});
55+
},
56+
onUrlChange: (UrlChange urlChange) {
57+
setState(() {
58+
_url = urlChange.url ?? '';
59+
});
60+
},
61+
),
5762
);
5863

5964
super.initState();

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
1717
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
1818
# In Windows, build-name is used as the major, minor, and patch parts
1919
# of the product and file versions while build-number is used as the build suffix.
20-
version: 1.0.1+2
20+
version: 1.0.2+3
2121

2222
environment:
2323
sdk: ">=3.0.2"

0 commit comments

Comments
 (0)