fix(flutter): 精修首页 feed 交互与底色
This commit is contained in:
1 parent
435fbbbbb1
commit
321c62664c
17 files changed
+427
-448
No files matched your search
@@ -58,6 +58,45 @@ class _TopIconButton extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// 刷新入口:点击重新加载 feed,长按仍可打开更多(清屏等)。
|
||||
class _RefreshButton extends StatelessWidget {
|
||||
const _RefreshButton({
|
||||
required this.tooltip,
|
||||
required this.dimension,
|
||||
required this.glyphSize,
|
||||
required this.onTap,
|
||||
required this.onLongPress,
|
||||
});
|
||||
|
||||
final String tooltip;
|
||||
final double dimension;
|
||||
final double glyphSize;
|
||||
final VoidCallback onTap;
|
||||
final VoidCallback onLongPress;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Tooltip(
|
||||
message: tooltip,
|
||||
child: GestureDetector(
|
||||
key: const Key('home-feed-refresh'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: onTap,
|
||||
onLongPress: onLongPress,
|
||||
child: SizedBox.square(
|
||||
dimension: dimension,
|
||||
child: Icon(
|
||||
Icons.refresh_rounded,
|
||||
size: glyphSize,
|
||||
color: Colors.white,
|
||||
shadows: const [Shadow(blurRadius: 6, color: Colors.black)],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FeedTabItem extends StatelessWidget {
|
||||
const _FeedTabItem({
|
||||
required this.tab,
|
||||
@@ -111,217 +150,100 @@ class _FeedTabItem extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _FeedRailItem extends StatelessWidget {
|
||||
const _FeedRailItem({
|
||||
super.key,
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.iconSize,
|
||||
required this.onTap,
|
||||
this.count,
|
||||
this.countKey,
|
||||
this.selected = false,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final double iconSize;
|
||||
final VoidCallback onTap;
|
||||
final int? count;
|
||||
final Key? countKey;
|
||||
final bool selected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
child: Semantics(
|
||||
button: true,
|
||||
label: label,
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: onTap,
|
||||
child: SizedBox(
|
||||
width: 48,
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
size: iconSize,
|
||||
color: selected ? AppColors.blue : Colors.white,
|
||||
shadows: const [Shadow(blurRadius: 6, color: Colors.black)],
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
count == null ? label : formatInteractionCount(count!),
|
||||
key: countKey,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 10,
|
||||
shadows: [Shadow(blurRadius: 6, color: Colors.black)],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FeedPill extends StatelessWidget {
|
||||
const _FeedPill({
|
||||
/// 整集条底部的进度线:20px 手势区内可点按/拖动 seek。
|
||||
class _FeedProgressBar extends StatefulWidget {
|
||||
const _FeedProgressBar({
|
||||
required this.controller,
|
||||
required this.height,
|
||||
required this.background,
|
||||
required this.child,
|
||||
required this.hitHeight,
|
||||
this.onScrubStart,
|
||||
this.onSeek,
|
||||
});
|
||||
|
||||
final double height;
|
||||
final Color background;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: height,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: background,
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: Center(child: child),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DanmakuPill extends StatelessWidget {
|
||||
const _DanmakuPill({
|
||||
required this.l10n,
|
||||
required this.height,
|
||||
required this.background,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final AppLocalizations l10n;
|
||||
final double height;
|
||||
final Color background;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
key: const Key('home-feed-danmaku'),
|
||||
onTap: onTap,
|
||||
child: _FeedPill(
|
||||
height: height,
|
||||
background: background,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text(
|
||||
'弹',
|
||||
style: TextStyle(color: Colors.white, fontSize: 12),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Flexible(
|
||||
child: Text(
|
||||
l10n.danmaku,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FullscreenPill extends StatelessWidget {
|
||||
const _FullscreenPill({
|
||||
required this.l10n,
|
||||
required this.height,
|
||||
required this.background,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final AppLocalizations l10n;
|
||||
final double height;
|
||||
final Color background;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
key: const Key('home-feed-fullscreen'),
|
||||
onTap: onTap,
|
||||
child: _FeedPill(
|
||||
height: height,
|
||||
background: background,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.fullscreen_rounded, color: Colors.white, size: 14),
|
||||
const SizedBox(width: 4),
|
||||
Flexible(
|
||||
child: Text(
|
||||
l10n.watchFullscreen,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FeedProgressTrack extends StatelessWidget {
|
||||
const _FeedProgressTrack({required this.controller, required this.height});
|
||||
|
||||
final ValueListenable<VideoPlayerValue>? controller;
|
||||
final double height;
|
||||
final double hitHeight;
|
||||
final VoidCallback? onScrubStart;
|
||||
final ValueChanged<Duration>? onSeek;
|
||||
|
||||
@override
|
||||
State<_FeedProgressBar> createState() => _FeedProgressBarState();
|
||||
}
|
||||
|
||||
class _FeedProgressBarState extends State<_FeedProgressBar> {
|
||||
double? _preview;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final source = controller;
|
||||
if (source == null) return _track(0);
|
||||
return ValueListenableBuilder<VideoPlayerValue>(
|
||||
valueListenable: source,
|
||||
builder: (context, value, _) {
|
||||
final total = value.duration.inMilliseconds;
|
||||
final fraction = total <= 0
|
||||
? 0.0
|
||||
: (value.position.inMilliseconds / total).clamp(0.0, 1.0);
|
||||
return _track(fraction.toDouble());
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final width = constraints.maxWidth;
|
||||
final source = widget.controller;
|
||||
final track = source == null
|
||||
? _track(0, width)
|
||||
: ValueListenableBuilder<VideoPlayerValue>(
|
||||
valueListenable: source,
|
||||
builder: (context, value, _) {
|
||||
final total = value.duration.inMilliseconds;
|
||||
final played = total <= 0
|
||||
? 0.0
|
||||
: (value.position.inMilliseconds / total)
|
||||
.clamp(0.0, 1.0)
|
||||
.toDouble();
|
||||
return _track(_preview ?? played, width);
|
||||
},
|
||||
);
|
||||
return GestureDetector(
|
||||
key: const Key('home-feed-progress'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTapDown: (details) {
|
||||
widget.onScrubStart?.call();
|
||||
_commit(details.localPosition.dx / width);
|
||||
},
|
||||
onHorizontalDragStart: (details) {
|
||||
widget.onScrubStart?.call();
|
||||
_update(details.localPosition.dx / width);
|
||||
},
|
||||
onHorizontalDragUpdate: (details) =>
|
||||
_update(details.localPosition.dx / width),
|
||||
onHorizontalDragEnd: (_) => _commit(_preview),
|
||||
onHorizontalDragCancel: () => setState(() => _preview = null),
|
||||
child: SizedBox(
|
||||
height: widget.hitHeight,
|
||||
child: Align(alignment: Alignment.bottomCenter, child: track),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _track(double fraction) {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) => SizedBox(
|
||||
height: height,
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(
|
||||
width: constraints.maxWidth,
|
||||
height: height,
|
||||
color: Colors.white24,
|
||||
),
|
||||
Container(
|
||||
width: constraints.maxWidth * fraction,
|
||||
height: height,
|
||||
color: AppColors.blue,
|
||||
),
|
||||
],
|
||||
),
|
||||
void _update(double fraction) {
|
||||
setState(() => _preview = fraction.clamp(0.0, 1.0).toDouble());
|
||||
}
|
||||
|
||||
void _commit(double? fraction) {
|
||||
if (fraction == null) return;
|
||||
final total = widget.controller?.value.duration.inMilliseconds ?? 0;
|
||||
if (total > 0) {
|
||||
widget.onSeek?.call(
|
||||
Duration(milliseconds: (total * fraction.clamp(0.0, 1.0)).round()),
|
||||
);
|
||||
}
|
||||
setState(() => _preview = null);
|
||||
}
|
||||
|
||||
Widget _track(double fraction, double width) {
|
||||
return SizedBox(
|
||||
height: widget.height,
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(width: width, height: widget.height, color: Colors.white24),
|
||||
Container(
|
||||
width: width * fraction,
|
||||
height: widget.height,
|
||||
color: AppColors.blue,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user