网络文章-v3 -下拉与加载更多
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:easy_refresh/easy_refresh.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_first_station/net_article/api/article_api.dart';
|
import 'package:flutter_first_station/net_article/api/article_api.dart';
|
||||||
@@ -46,13 +49,39 @@ class _ArticleContentState extends State<ArticleContent> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return ListView.builder(
|
return EasyRefresh(
|
||||||
itemExtent: 80,
|
header: const ClassicHeader(
|
||||||
itemCount: _articles.length,
|
dragText: "下拉加载",
|
||||||
itemBuilder: _buildItemByIndex,
|
armedText: "释放刷新",
|
||||||
|
readyText: "开始加载",
|
||||||
|
processingText: "正在加载",
|
||||||
|
processedText: "刷新成功",
|
||||||
|
),
|
||||||
|
footer:const ClassicFooter(
|
||||||
|
processingText: "正在加载"
|
||||||
|
),
|
||||||
|
onRefresh: _onRefresh,
|
||||||
|
onLoad: _onLoad,
|
||||||
|
child: ListView.builder(
|
||||||
|
itemExtent: 80,
|
||||||
|
itemCount: _articles.length,
|
||||||
|
itemBuilder: _buildItemByIndex,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onRefresh() async{
|
||||||
|
_articles = await api.loadArticles(0);
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onLoad() async{
|
||||||
|
int nextPage = _articles.length%20;
|
||||||
|
List<Article> newArticles = await api.loadArticles(nextPage);
|
||||||
|
_articles = _articles + newArticles;
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildItemByIndex(BuildContext context, int index) {
|
Widget _buildItemByIndex(BuildContext context, int index) {
|
||||||
return ArticleItem(
|
return ArticleItem(
|
||||||
article: _articles[index],
|
article: _articles[index],
|
||||||
@@ -67,6 +96,10 @@ class _ArticleContentState extends State<ArticleContent> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ArticleItem extends StatelessWidget {
|
class ArticleItem extends StatelessWidget {
|
||||||
|
|||||||
24
pubspec.lock
24
pubspec.lock
@@ -121,6 +121,14 @@ packages:
|
|||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "5.1.2"
|
version: "5.1.2"
|
||||||
|
easy_refresh:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: easy_refresh
|
||||||
|
sha256: "6f4d222355a8294a72d600bcd7551e0559b6d96a98e8977c69796e0fb2f9e5ef"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "3.3.1+2"
|
||||||
fake_async:
|
fake_async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -264,6 +272,22 @@ packages:
|
|||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.2"
|
version: "1.8.2"
|
||||||
|
path_drawing:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path_drawing
|
||||||
|
sha256: bbb1934c0cbb03091af082a6389ca2080345291ef07a5fa6d6e078ba8682f977
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.1"
|
||||||
|
path_parsing:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path_parsing
|
||||||
|
sha256: e3e67b1629e6f7e8100b367d3db6ba6af4b1f0bb80f64db18ef1fbabd2fa9ccf
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.1"
|
||||||
path_provider:
|
path_provider:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ dependencies:
|
|||||||
sqflite: ^2.2.8+2
|
sqflite: ^2.2.8+2
|
||||||
dio: ^5.1.2
|
dio: ^5.1.2
|
||||||
webview_flutter: ^4.2.0
|
webview_flutter: ^4.2.0
|
||||||
|
easy_refresh: ^3.3.1+2
|
||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.2
|
||||||
|
|||||||
Reference in New Issue
Block a user