1 Star 1 Fork 0

蔡江洋/flutter-custom-refresh-indicator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
programmatically_controlled_indicator_screen.dart 2.76 KB
一键复制 编辑 原始数据 按行查看 历史
gonuit 提交于 3年前 . Add fetch more example
import 'dart:math';
import 'package:custom_refresh_indicator/custom_refresh_indicator.dart';
import 'package:example/indicators/warp_indicator.dart';
import 'package:example/widgets/example_app_bar.dart';
import 'package:example/widgets/example_list.dart';
import 'package:flutter/material.dart';
class ProgrammaticallyControlled extends StatefulWidget {
const ProgrammaticallyControlled({Key? key}) : super(key: key);
@override
State<ProgrammaticallyControlled> createState() =>
_ProgrammaticallyControlledState();
}
class _ProgrammaticallyControlledState
extends State<ProgrammaticallyControlled> {
final key = GlobalKey<CustomRefreshIndicatorState>();
final controller = IndicatorController(refreshEnabled: false);
bool _startedManually = false;
int _itemsCount = 4;
Future<void> onRefresh() async {
await Future.delayed(const Duration(seconds: 2));
if (!mounted) return;
setState(() {
_itemsCount = Random().nextInt(4) + 1;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: ExampleAppBar(
title: "Programmatically-controlled",
actions: [
AnimatedBuilder(
animation: controller,
builder: (context, _) {
return Row(
children: [
IconButton(
onPressed: controller.isIdle
? () {
key.currentState!.show(
draggingCurve: Curves.easeOutBack,
);
_startedManually = true;
}
: null,
icon: const Icon(Icons.play_arrow),
),
IconButton(
onPressed: controller.isIdle
? () => key.currentState!.refresh(
draggingCurve: Curves.easeOutBack,
)
: null,
icon: const Icon(Icons.refresh),
),
IconButton(
onPressed: controller.isLoading && _startedManually
? () {
key.currentState!.hide();
_startedManually = false;
}
: null,
icon: const Icon(Icons.stop),
),
],
);
},
),
],
),
body: WarpIndicator(
controller: controller,
indicatorKey: key,
onRefresh: onRefresh,
child: ExampleList(itemCount: _itemsCount),
),
);
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jiang-yang-cai/flutter-custom-refresh-indicator.git
git@gitee.com:jiang-yang-cai/flutter-custom-refresh-indicator.git
jiang-yang-cai
flutter-custom-refresh-indicator
flutter-custom-refresh-indicator
master

搜索帮助