Browse Source

更新下拉刷新

tags/0.0.1
Weller 4 years ago
parent
commit
b6364e7919
3 changed files with 44 additions and 16 deletions
  1. +2
    -2
      .dart_tool/package_config.json
  2. +22
    -10
      lib/pages/main_page/main_page.dart
  3. +20
    -4
      lib/widgets/refresh/refresh_header/refresh_header.dart

+ 2
- 2
.dart_tool/package_config.json View File

@@ -141,7 +141,7 @@
}, },
{ {
"name": "flutter_alibc", "name": "flutter_alibc",
"rootUri": "file:///Users/fnuser/.pub-cache/hosted/pub.flutter-io.cn/flutter_alibc-0.0.15",
"rootUri": "file:///Users/fnuser/.pub-cache/git/zhiying_flutter_alibc-6e02aaf22b9798f4b01554a9153d2c66591da8c1/",
"packageUri": "lib/", "packageUri": "lib/",
"languageVersion": "2.1" "languageVersion": "2.1"
}, },
@@ -620,7 +620,7 @@
"languageVersion": "2.1" "languageVersion": "2.1"
} }
], ],
"generated": "2020-10-14T08:31:49.974712Z",
"generated": "2020-10-14T08:58:23.460236Z",
"generator": "pub", "generator": "pub",
"generatorVersion": "2.8.2" "generatorVersion": "2.8.2"
} }

+ 22
- 10
lib/pages/main_page/main_page.dart View File

@@ -1,3 +1,5 @@
import 'dart:ui';

import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@@ -18,8 +20,7 @@ import 'package:zhiying_comm/zhiying_comm.dart';
class MainPage extends StatefulWidget { class MainPage extends StatefulWidget {
final Map<String, dynamic> data; final Map<String, dynamic> data;


MainPage(
this.data, {
MainPage(this.data, {
Key key, Key key,
}) : super(key: key); }) : super(key: key);


@@ -58,7 +59,7 @@ class _MainPageContainerState extends State<_MainPageContainer>
ScrollController _controller = ScrollController(); ScrollController _controller = ScrollController();
MainPageBloc _bloc; MainPageBloc _bloc;
RefreshController _refreshController = RefreshController _refreshController =
RefreshController(initialRefresh: false);
RefreshController(initialRefresh: false);


Widget _floatWidget; Widget _floatWidget;


@@ -69,8 +70,12 @@ class _MainPageContainerState extends State<_MainPageContainer>
} }


void _onRefresh() async { void _onRefresh() async {
await Duration(microseconds: 3);
_refreshController.refreshCompleted();
// await Future.delayed(Duration(milliseconds: 3000));
// _refreshController.refreshCompleted();

if (widget.data.containsKey('skip_identifier')) {
_bloc.loadData(widget.data['skip_identifier']);
}
} }


@override @override
@@ -117,15 +122,20 @@ class _MainPageContainerState extends State<_MainPageContainer>


@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
double top = MediaQueryData
.fromWindow(window)
.padding
.top;
return StreamBuilder<List<Map<String, dynamic>>>( return StreamBuilder<List<Map<String, dynamic>>>(
stream: _bloc.outData, stream: _bloc.outData,
builder: (BuildContext context, AsyncSnapshot snapshot) { builder: (BuildContext context, AsyncSnapshot snapshot) {
List widgets = _createContent(context, snapshot.data ?? []); List widgets = _createContent(context, snapshot.data ?? []);
_refreshController.refreshCompleted();
return Scaffold( return Scaffold(
backgroundColor: Color(0xfff9f9f9), backgroundColor: Color(0xfff9f9f9),
floatingActionButton: _floatWidget, floatingActionButton: _floatWidget,
floatingActionButtonLocation: floatingActionButtonLocation:
FloatingActionButtonLocation.centerDocked,
FloatingActionButtonLocation.centerDocked,
body: MediaQuery.removePadding( body: MediaQuery.removePadding(
removeTop: true, removeTop: true,
context: context, context: context,
@@ -140,7 +150,9 @@ class _MainPageContainerState extends State<_MainPageContainer>
SmartRefresher( SmartRefresher(
enablePullDown: true, enablePullDown: true,
enablePullUp: false, enablePullUp: false,
header: RefreshHeader(),
header: RefreshHeader(
offsetY: top,
),
controller: _refreshController, controller: _refreshController,
onLoading: _onLoading, onLoading: _onLoading,
onRefresh: _onRefresh, onRefresh: _onRefresh,
@@ -157,12 +169,12 @@ class _MainPageContainerState extends State<_MainPageContainer>
}); });
} }


List<Widget> _createContent(
BuildContext context, List<Map<String, dynamic>> datas) {
List<Widget> _createContent(BuildContext context,
List<Map<String, dynamic>> datas) {
List<Widget> list = List(); List<Widget> list = List();
for (int i = 0; i < datas.length; i++) { for (int i = 0; i < datas.length; i++) {
WidgetModel item = WidgetModel item =
WidgetModel.fromJson(Map<String, dynamic>.from(datas[i]));
WidgetModel.fromJson(Map<String, dynamic>.from(datas[i]));


print('item.modName ${item.modName}'); print('item.modName ${item.modName}');
if (item.modName == 'index_taobao_auth_tip') { if (item.modName == 'index_taobao_auth_tip') {


+ 20
- 4
lib/widgets/refresh/refresh_header/refresh_header.dart View File

@@ -1,17 +1,33 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:loading_indicator/loading_indicator.dart'; import 'package:loading_indicator/loading_indicator.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';


class RefreshHeader extends StatelessWidget { class RefreshHeader extends StatelessWidget {
final double offsetY;
final double _height = 44;

const RefreshHeader({Key key, this.offsetY = 0}) : super(key: key);

@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// double top = MediaQueryData.fromWindow(window).padding.top;
return CustomHeader( return CustomHeader(
height: _height + offsetY,
builder: (BuildContext context, RefreshStatus mode) { builder: (BuildContext context, RefreshStatus mode) {
return Container( return Container(
height: 120,
margin: EdgeInsets.only(top: offsetY),
// color: Colors.blue,
width: double.infinity, width: double.infinity,
child: Center(child: LoadingIndicator(
indicatorType: Indicator.lineScale, color: Colors.white,),),
child: Center(
child: Container(
width: 36,
height: 36,
child: LoadingIndicator(
indicatorType: Indicator.ballSpinFadeLoader,
color: Colors.white,
),
),
),
// color: Colors.blue, // color: Colors.blue,
); );
}, },


Loading…
Cancel
Save