aoi-hosizora / flutter_ahlib Goto Github PK
View Code? Open in Web Editor NEWA personal flutter library, contains some useful widgets and utils.
License: MIT License
A personal flutter library, contains some useful widgets and utils.
License: MIT License
Here should be add(xxx)
rather than insert(0, xxx)
.
flutter_ahlib/lib/src/widget/text_group.dart
Line 229 in c6bd720
Add these options (or others) for TextGroup
.
flutter_ahlib/lib/src/widget/text_group.dart
Lines 268 to 269 in c6bd720
Here should use assert
rather than math.max
:
flutter_ahlib/lib/src/widget/sliver_appbar_delegate.dart
Lines 36 to 37 in c6bd720
Add some settings for PlaceholderSetting
, such as showRetryButton
, showLoadingText
, buttonTextStyle
, etc.
/// An [Icon] with a line from left top to bottom right, which is rendered by [CustomPaint].
class BannedIcon extends StatelessWidget {
const BannedIcon({
Key key,
@required this.icon,
this.banned = true,
@required this.color,
@required this.backgroundColor,
this.offset = 3.0,
this.lineWidth = 3.0,
this.blinkLineWidth = 2.0,
this.size = Size.zero,
}) : assert(icon != null),
assert(banned != null),
assert(offset != null),
assert(color != null),
assert(backgroundColor != null),
assert(lineWidth != null),
assert(blinkLineWidth != null),
assert(size != null),
super(key: key);
/// Content icon, the shape of line depends on this widget's size.
final Widget icon;
/// Paint the line or not.
final bool banned;
/// Color of line, need to be the same as icon's color.
final Color color;
/// Color of background, used to paint the blink line.
final Color backgroundColor;
/// Line position offset from the icon size, default is 3.0.
final double offset;
/// Line width, default is 3.0.
final double lineWidth;
/// Blink link width, default is 2.0, recommend to set a value that close to [lineWidth].
final double blinkLineWidth;
/// Icon size, default is [Size.zero] which depends on the child or parent.
final Size size;
@override
Widget build(BuildContext context) {
return Center(
child: CustomPaint(
foregroundPainter: !banned
? null
: FunctionPainter(
onPaint: (canvas, size) {
// line
canvas.drawLine(
Offset(offset, offset),
Offset(size.width - offset, size.height - offset),
Paint()
..color = color
..strokeWidth = lineWidth,
);
// blink line
canvas.drawLine(
Offset(offset, offset - blinkLineWidth),
Offset(size.width - offset + blinkLineWidth, size.height - offset),
Paint()
..color = backgroundColor
..strokeWidth = blinkLineWidth,
);
},
),
child: icon,
size: size,
willChange: banned ? true : false,
),
);
}
}
Need to adjust structures, including packages and codes.
enum _AppendIndicatorMode {
drag, // start to show
armed, // drag far enough
append, // run the append callback
done_before, // before append callback is done
done, // append callback is done
canceled, // canceled by no arming
}
static const _kScaleSlowDuration = Duration(milliseconds: 400);
static const _kScaleFastDuration = Duration(milliseconds: 100);
static const _kProgressFadeDuration = Duration(milliseconds: 100);
static const _kProgressIncrDuration = Duration(milliseconds: 150);
static const _kProgressFinalDuration = Duration(milliseconds: 150);
AnimationController _progressController;
Animation<double> _progressAnimation;
void initState() {
super.initState();
_sizeController = AnimationController(vsync: this);
_sizeFactor = _sizeController.drive(Tween(begin: 0.0, end: 1.0));
_progressController = AnimationController(vsync: this);
_progressAnimation = _progressController.drive(Tween(begin: 0.0, end: 1.0));
}
void _start() {
_sizeController.value = 0.0;
_progressController.value = 0.0;
_dragOffset = 0;
}
/// Show animation with "-> fade -> increasing -> shrink" or "-> shrink".
void _dismiss(_AppendIndicatorMode newMode) async {
if (newMode == _AppendIndicatorMode.canceled) {
// -> cancel
_mode = _AppendIndicatorMode.canceled;
if (mounted) setState(() {});
} else if (newMode == _AppendIndicatorMode.done) {
// -> done_before
_mode = _AppendIndicatorMode.done_before;
if (mounted) setState(() {});
await Future.delayed(_kProgressFadeDuration); // fade
await _progressController.animateTo(1.0, duration: _kProgressIncrDuration); // increasing
await Future.delayed(_kProgressFinalDuration);
// -> done
_mode = _AppendIndicatorMode.done;
if (mounted) setState(() {});
}
await _sizeController.animateTo(0.0, duration: _kScaleSlowDuration, curve: Curves.easeOutCubic); // shrink
// -> null
_mode = null;
if (mounted) setState(() {});
}
SizeTransition(
sizeFactor: _sizeFactor,
axis: Axis.horizontal,
child: AnimatedCrossFade(
duration: _kProgressFadeDuration,
crossFadeState: _mode == _AppendIndicatorMode.done_before || _mode == _AppendIndicatorMode.done ? CrossFadeState.showSecond : CrossFadeState.showFirst,
firstChild: LinearProgressIndicator(
value: _mode == _AppendIndicatorMode.append || _mode == _AppendIndicatorMode.done_before || _mode == _AppendIndicatorMode.done ? null : 0,
minHeight: widget.minHeight,
backgroundColor: widget.backgroundColor,
valueColor: widget.valueColor,
),
secondChild: AnimatedBuilder(
animation: _progressAnimation,
builder: (_, __) => LinearProgressIndicator(
value: _progressAnimation.value,
minHeight: widget.minHeight,
backgroundColor: widget.backgroundColor,
valueColor: widget.valueColor,
),
),
),
),
The http.head
header should contain the headers
parameter.
int totalSize;
http.head(url, headers: {
'Accept': '*/*',
'Accept-Encoding': '',
}).then((data) {
totalSize = int.tryParse(data.headers['content-length']);
});
RefreshIndicator
and AppendIndicator
should be out of PlaceholderText
, insure for WidgetsBinding.instance.addPostFrameCallback((_) => _indicatorKey?.currentState?.show())
.
Refactor the whole library, rewrite the comments, release to v1.2.
Widget progress: (9)
List related progress: (4)
Image related progress: (3)
Util related progress: (7)
Need to add a threshold for AppendIndicator
to check if it needs to append when the list is short.
And fix the scroll invoked when the onAppend
invoked but it has been scrolled up.
ScrollMoreController
should be split to an extension
for scroll helper functions and ListController
for refresh and append functions.
Consider to upgrade in the next version.
Use optional parameters to scrollXXX
methods.
flutter_ahlib/lib/src/util/flutter_extensions.dart
Lines 20 to 22 in c6bd720
Add PageController
extension and add scrollWithAnimate
method.
PageController _controller;
_controller.animateToPage(index, duration: kTabScrollDuration, curve: Curves.easeOutQuad);
Rename some method names.
flutter_ahlib/lib/src/util/action_controller.dart
Lines 26 to 28 in c6bd720
Use default value AlwaysScrollableScrollPhysics()
for physics
.
Add textScaleFactor
field for RichText
in GroupText
.
And try to change to default textTheme
for RichText
.
See https://github.com/Aoi-hosizora/manhuagui_flutter/blob/master/lib/page/view/multilink_text.dart#L36.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.