Skip to content

Commit

Permalink
update demo
Browse files Browse the repository at this point in the history
  • Loading branch information
zmtzawqlp committed Dec 8, 2021
1 parent 1f3965a commit 8c3bf14
Show file tree
Hide file tree
Showing 52 changed files with 334 additions and 1,579 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 5.0.0

* Migrate to 2.5
* Merge code from https://github.com/flutter/flutter/pull/87801
* Fix exception that findRenderObject throw exception even mounted is true

## 4.0.0

* Breaking change:
Expand Down
2 changes: 1 addition & 1 deletion example/ff_annotation_route_commands
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-s --no-null-safety
-s
87 changes: 48 additions & 39 deletions example/lib/common/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ import 'package:loading_more_list/loading_more_list.dart';

class SecondaryTabView extends StatefulWidget {
const SecondaryTabView(this.tabKey, this.tc);

final String tabKey;
final TabController tc;

@override
_SecondaryTabViewState createState() => _SecondaryTabViewState();
}

class _SecondaryTabViewState extends State<SecondaryTabView>
with AutomaticKeepAliveClientMixin {
@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context) {
super.build(context);
Expand Down Expand Up @@ -72,7 +69,9 @@ class _SecondaryTabViewState extends State<SecondaryTabView>

class TabViewItem extends StatefulWidget {
const TabViewItem(this.tabKey);

final Key tabKey;

@override
_TabViewItemState createState() => _TabViewItemState();
}
Expand Down Expand Up @@ -111,6 +110,7 @@ class _TabViewItemState extends State<TabViewItem>
class CommonSliverPersistentHeaderDelegate
extends SliverPersistentHeaderDelegate {
CommonSliverPersistentHeaderDelegate(this.child, this.height);

final Widget child;
final double height;

Expand Down Expand Up @@ -142,46 +142,55 @@ Future<bool> onRefresh() {
List<Widget> buildSliverHeader() {
final List<Widget> widgets = <Widget>[];

widgets.add(SliverAppBar(
widgets.add(
SliverAppBar(
pinned: true,
expandedHeight: 200.0,
//title: Text(old ? 'old demo' : 'new demo'),
flexibleSpace: FlexibleSpaceBar(
//centerTitle: true,
collapseMode: CollapseMode.pin,
background: Image.asset(
'assets/467141054.jpg',
fit: BoxFit.fill,
))));

widgets.add(SliverGrid(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
crossAxisSpacing: 0.0,
mainAxisSpacing: 0.0,
//centerTitle: true,
collapseMode: CollapseMode.pin,
background: Image.asset('assets/467141054.jpg', fit: BoxFit.fill),
),
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
alignment: Alignment.center,
height: 60.0,
child: Text('Gird$index'),
decoration: BoxDecoration(
border: Border.all(color: Colors.orange, width: 1.0)),
);
},
childCount: 7,
);

widgets.add(
SliverGrid(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
crossAxisSpacing: 0.0,
mainAxisSpacing: 0.0,
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
alignment: Alignment.center,
height: 60.0,
child: Text('Gird$index'),
decoration: BoxDecoration(
border: Border.all(color: Colors.orange, width: 1.0)),
);
},
childCount: 7,
),
),
));

widgets.add(SliverList(
delegate: SliverChildBuilderDelegate((BuildContext c, int i) {
return Container(
alignment: Alignment.center,
height: 60.0,
child: Text('SliverList$i'),
);
}, childCount: 3)));
);

widgets.add(
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext c, int i) {
return Container(
alignment: Alignment.center,
height: 60.0,
child: Text('SliverList$i'),
);
},
childCount: 3,
),
),
);

// widgets.add(SliverPersistentHeader(
// pinned: true,
Expand Down
71 changes: 38 additions & 33 deletions example/lib/common/push_to_refresh_header.dart
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
import 'dart:math';
import 'dart:ui' as ui show Image;

import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh_notification/pull_to_refresh_notification.dart';

import 'package:intl/intl.dart';
import 'package:pull_to_refresh_notification/pull_to_refresh_notification.dart';

double get maxDragOffset => 100;
double hideHeight = maxDragOffset / 2.3;
double refreshHeight = maxDragOffset / 1.5;

class PullToRefreshHeader extends StatelessWidget {
const PullToRefreshHeader(this.info, this.lastRefreshTime, {this.color});
final PullToRefreshScrollNotificationInfo info;
final DateTime lastRefreshTime;
final Color color;
const PullToRefreshHeader(
this.info,
this.lastRefreshTime, {
this.color,
});

final PullToRefreshScrollNotificationInfo? info;
final DateTime? lastRefreshTime;
final Color? color;

@override
Widget build(BuildContext context) {
if (info == null) {
final PullToRefreshScrollNotificationInfo? _info = info;
if (_info == null) {
return Container();
}
String text = '';
if (info.mode == RefreshIndicatorMode.armed) {
if (_info.mode == RefreshIndicatorMode.armed) {
text = 'Release to refresh';
} else if (info.mode == RefreshIndicatorMode.refresh ||
info.mode == RefreshIndicatorMode.snap) {
} else if (_info.mode == RefreshIndicatorMode.refresh ||
_info.mode == RefreshIndicatorMode.snap) {
text = 'Loading...';
} else if (info.mode == RefreshIndicatorMode.done) {
} else if (_info.mode == RefreshIndicatorMode.done) {
text = 'Refresh completed.';
} else if (info.mode == RefreshIndicatorMode.drag) {
} else if (_info.mode == RefreshIndicatorMode.drag) {
text = 'Pull to refresh';
} else if (info.mode == RefreshIndicatorMode.canceled) {
} else if (_info.mode == RefreshIndicatorMode.canceled) {
text = 'Cancel refresh';
}

Expand All @@ -45,8 +52,8 @@ class PullToRefreshHeader extends StatelessWidget {
return Container(
height: dragOffset,
color: color ?? Colors.transparent,
//padding: EdgeInsets.only(top: dragOffset / 3),
//padding: EdgeInsets.only(bottom: 5.0),
// padding: EdgeInsets.only(top: dragOffset / 3),
// padding: EdgeInsets.only(bottom: 5.0),
child: Stack(
children: <Widget>[
Positioned(
Expand All @@ -66,20 +73,15 @@ class PullToRefreshHeader extends StatelessWidget {
),
Column(
children: <Widget>[
Text(
text,
style: ts,
),
Text(text, style: ts),
Text(
'Last updated:' +
DateFormat('yyyy-MM-dd hh:mm').format(time),
style: ts.copyWith(fontSize: 14),
)
],
),
Expanded(
child: Container(),
),
const Spacer(),
],
),
)
Expand All @@ -91,7 +93,9 @@ class PullToRefreshHeader extends StatelessWidget {

class RefreshImage extends StatelessWidget {
const RefreshImage(this.top);

final double top;

@override
Widget build(BuildContext context) {
const double imageSize = 30;
Expand All @@ -103,19 +107,20 @@ class RefreshImage extends StatelessWidget {
final double imageHeight = image.height.toDouble();
final double imageWidth = image.width.toDouble();
final Size size = rect.size;
final double y = (1 - min(top / (refreshHeight - hideHeight), 1)) *
imageHeight as double;
final double y =
(1 - min(top / (refreshHeight - hideHeight), 1)) * imageHeight;

canvas.drawImageRect(
image,
Rect.fromLTWH(0.0, y, imageWidth, imageHeight - y),
Rect.fromLTWH(rect.left, rect.top + y / imageHeight * size.height,
size.width, (imageHeight - y) / imageHeight * size.height),
Paint()
..colorFilter =
const ColorFilter.mode(Color(0xFFea5504), BlendMode.srcIn)
..isAntiAlias = false
..filterQuality = FilterQuality.low);
image,
Rect.fromLTWH(0.0, y, imageWidth, imageHeight - y),
Rect.fromLTWH(rect.left, rect.top + y / imageHeight * size.height,
size.width, (imageHeight - y) / imageHeight * size.height),
Paint()
..colorFilter =
const ColorFilter.mode(Color(0xFFea5504), BlendMode.srcIn)
..isAntiAlias = false
..filterQuality = FilterQuality.low,
);

//canvas.restore();
},
Expand Down
Loading

0 comments on commit 8c3bf14

Please sign in to comment.