Skip to content

support flutter 3.0, code cleanup, fix example demo code error #590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/lib/ui/example/useStage/twolevel_refresh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class _TwoLevelExampleState extends State<TwoLevelExample> {
},
items: [
BottomNavigationBarItem(
icon: Icon(Icons.add), title: Text("二级刷新例子1")),
icon: Icon(Icons.add), label: "二级刷新例子1"),
BottomNavigationBarItem(
icon: Icon(Icons.border_clear), title: Text("二级刷新例子2"))
icon: Icon(Icons.border_clear), label: "二级刷新例子2")
],
)
: null,
Expand Down
47 changes: 18 additions & 29 deletions example/lib/ui/test/TestPage.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:flutter/material.dart';

import 'Test1.dart';
import 'Test2.dart';
import 'Test3.dart';
import 'Test4.dart';
import 'package:flutter/material.dart';

class TestPage extends StatefulWidget {
TestPage({Key key, this.title}) : super(key: key);
Expand All @@ -22,8 +23,7 @@ class TestPage extends StatefulWidget {
_TestPageState createState() => new _TestPageState();
}

class _TestPageState extends State<TestPage>
with SingleTickerProviderStateMixin {
class _TestPageState extends State<TestPage> with SingleTickerProviderStateMixin {
int tabIndex = 0;
PageController _pageController;
List<Widget> views;
Expand Down Expand Up @@ -69,30 +69,24 @@ class _TestPageState extends State<TestPage>
BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home,
color: tabIndex == 0 ? Colors.blue : Colors.grey),
title: Text('Example1',
style: TextStyle(
color: tabIndex == 0 ? Colors.blue : Colors.grey))),
icon: Icon(Icons.home, color: tabIndex == 0 ? Colors.blue : Colors.grey),
label: 'Example1',
),
BottomNavigationBarItem(
icon: Icon(Icons.cloud,
color: tabIndex == 1 ? Colors.blue : Colors.grey),
title: Text('Example2',
style: TextStyle(
color: tabIndex == 1 ? Colors.blue : Colors.grey))),
icon: Icon(Icons.cloud, color: tabIndex == 1 ? Colors.blue : Colors.grey),
label: 'Example2',
),
BottomNavigationBarItem(
icon: Icon(Icons.call,
color: tabIndex == 2 ? Colors.blue : Colors.grey),
title: Text('Example3',
style: TextStyle(
color: tabIndex == 2 ? Colors.blue : Colors.grey))),
icon: Icon(Icons.call, color: tabIndex == 2 ? Colors.blue : Colors.grey),
label: 'Example3',
),
BottomNavigationBarItem(
icon: Icon(Icons.transform,
color: tabIndex == 3 ? Colors.blue : Colors.grey),
title: Text('Example4',
style: TextStyle(
color: tabIndex == 3 ? Colors.blue : Colors.grey))),
icon: Icon(Icons.transform, color: tabIndex == 3 ? Colors.blue : Colors.grey),
label: 'Example4',
),
],
selectedItemColor: Colors.blue,
unselectedItemColor: Colors.grey,
onTap: (index) {
_pageController.jumpToPage(index);
},
Expand All @@ -108,12 +102,7 @@ class _TestPageState extends State<TestPage>
void initState() {
// TODO: implement initState
_pageController = PageController();
views = [
Test1(key: example1Key),
Test2(),
Test3(key: example3Key),
Test4()
];
views = [Test1(key: example1Key), Test2(), Test3(key: example3Key), Test4()];
super.initState();
}
}
3 changes: 0 additions & 3 deletions lib/src/indicator/classic_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

import 'package:flutter/material.dart'
hide RefreshIndicator, RefreshIndicatorState;
import 'package:flutter/widgets.dart';
import '../../pull_to_refresh.dart';
import '../internals/indicator_wrap.dart';
import '../smart_refresher.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';

Expand Down
2 changes: 0 additions & 2 deletions lib/src/indicator/material_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
* Time: 2019/5/19 下午9:23
*/

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'
hide RefreshIndicator, RefreshIndicatorState;
import 'package:flutter/widgets.dart';
import '../internals/indicator_wrap.dart';
import '../smart_refresher.dart';

Expand Down
2 changes: 0 additions & 2 deletions lib/src/indicator/twolevel_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'classic_indicator.dart';
import '../smart_refresher.dart';

Expand Down
3 changes: 0 additions & 3 deletions lib/src/indicator/waterdrop_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
import 'dart:async';
import 'package:flutter/material.dart'
hide RefreshIndicatorState, RefreshIndicator;
import 'package:flutter/widgets.dart';
import 'package:flutter/foundation.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import '../internals/indicator_wrap.dart';
import 'package:flutter/cupertino.dart';
import '../smart_refresher.dart';

/// QQ ios refresh header effect
class WaterDropHeader extends RefreshIndicator {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/internals/indicator_wrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ abstract class RefreshIndicatorState<T extends RefreshIndicator>
the _onOffsetChange didn't callback,it will keep failed or success state.
2. As FrontStyle,when user dragging in 0~100 in refreshing state,it should be reset after the state change
*/
WidgetsBinding.instance!.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) {
return;
}
Expand Down Expand Up @@ -287,7 +287,7 @@ abstract class RefreshIndicatorState<T extends RefreshIndicator>
} else if (mode == RefreshStatus.twoLevelOpening) {
floating = true;
refresherState!.setCanDrag(false);
WidgetsBinding.instance!.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
activity!.resetActivity();
_position!
Expand Down Expand Up @@ -390,7 +390,7 @@ abstract class LoadIndicatorState<T extends LoadIndicator> extends State<T>

// this line for patch bug temporary:indicator disappears fastly when load more complete
if (mounted) Scrollable.of(context)!.position.correctBy(0.00001);
WidgetsBinding.instance!.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted && _position?.outOfRange == true) {
activity!.delegate.goBallistic(0);
}
Expand Down
1 change: 0 additions & 1 deletion lib/src/internals/refresh_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

/// Implementation of localized strings for the [ClassicHeader],[ClassicFooter],[TwoLevelHeader]
///
Expand Down
18 changes: 7 additions & 11 deletions lib/src/smart_refresher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import 'package:flutter/widgets.dart';
import 'package:flutter/foundation.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:pull_to_refresh/src/internals/slivers.dart';
import 'internals/indicator_wrap.dart';
import 'internals/refresh_physics.dart';
import 'indicator/classic_indicator.dart';
import 'indicator/material_indicator.dart';

// ignore_for_file: INVALID_USE_OF_PROTECTED_MEMBER
// ignore_for_file: INVALID_USE_OF_VISIBLE_FOR_TESTING_MEMBER
Expand Down Expand Up @@ -424,7 +420,7 @@ class SmartRefresherState extends State<SmartRefresher> {
dragStartBehavior: dragStartBehavior ?? DragStartBehavior.start,
reverse: reverse ?? false,
);
} else if (childView is Scrollable) {
} else {
body = Scrollable(
physics: _getScrollPhysics(
conf, childView.physics ?? AlwaysScrollableScrollPhysics()),
Expand Down Expand Up @@ -510,7 +506,7 @@ class SmartRefresherState extends State<SmartRefresher> {
void initState() {
// TODO: implement initState
if (widget.controller.initialRefresh) {
WidgetsBinding.instance!.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((_) {
// if mounted,it avoid one situation: when init done,then dispose the widget before build.
// this situation mostly TabBarView
if (mounted) widget.controller.requestRefresh();
Expand Down Expand Up @@ -654,7 +650,7 @@ class RefreshController {
{bool needMove: true,
bool needCallback: true,
Duration duration: const Duration(milliseconds: 500),
Curve curve: Curves.linear}) {
Curve curve: Curves.linear}) async {
assert(position != null,
'Try not to call requestRefresh() before build,please call after the ui was rendered');
if (isRefresh) return Future.value();
Expand Down Expand Up @@ -762,7 +758,7 @@ class RefreshController {
{Duration duration: const Duration(milliseconds: 500),
Curve curve: Curves.linear}) {
headerMode?.value = RefreshStatus.twoLevelClosing;
WidgetsBinding.instance!.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((_) {
position!
.animateTo(0.0, duration: duration, curve: curve)
.whenComplete(() {
Expand All @@ -785,22 +781,22 @@ class RefreshController {
/// after data returned,set the footer state to idle
void loadComplete() {
// change state after ui update,else it will have a bug:twice loading
WidgetsBinding.instance!.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((_) {
footerMode?.value = LoadStatus.idle;
});
}

/// If catchError happen,you may call loadFailed indicate fetch data from network failed
void loadFailed() {
// change state after ui update,else it will have a bug:twice loading
WidgetsBinding.instance!.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((_) {
footerMode?.value = LoadStatus.failed;
});
}

/// load more success without error,but no data returned
void loadNoData() {
WidgetsBinding.instance!.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((_) {
footerMode?.value = LoadStatus.noMore;
});
}
Expand Down