55 lines
1.5 KiB
Dart
55 lines
1.5 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter_remix/flutter_remix.dart';
|
||
import 'package:go_router/go_router.dart';
|
||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||
|
||
/// 圆形返回钮(对齐 demo `.back`:38×38 圆 + 1px 描边 + chevron)。
|
||
/// 左对齐到 12px(demo `.dhead` padding-left),用作各页 AppBar 的 leading。
|
||
class CircleBackButton extends StatelessWidget {
|
||
const CircleBackButton({
|
||
super.key,
|
||
this.onTap,
|
||
this.fallbackLocation = '/assets',
|
||
});
|
||
|
||
final VoidCallback? onTap;
|
||
final String fallbackLocation;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final cs = ShadTheme.of(context).colorScheme;
|
||
return Align(
|
||
alignment: Alignment.centerLeft,
|
||
child: Padding(
|
||
padding: const EdgeInsets.only(left: 12),
|
||
child: GestureDetector(
|
||
behavior: HitTestBehavior.opaque,
|
||
onTap:
|
||
onTap ??
|
||
() {
|
||
if (context.canPop()) {
|
||
context.pop();
|
||
} else {
|
||
context.go(fallbackLocation);
|
||
}
|
||
},
|
||
child: Container(
|
||
width: 38,
|
||
height: 38,
|
||
alignment: Alignment.center,
|
||
decoration: BoxDecoration(
|
||
shape: BoxShape.circle,
|
||
border: Border.all(color: cs.border, width: 1),
|
||
),
|
||
child: Icon(
|
||
FlutterRemix.arrow_left_s_line,
|
||
size: 22,
|
||
color: cs.foreground,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|