37 lines
923 B
Dart
37 lines
923 B
Dart
![]() |
/// 返回顶部
|
||
|
library;
|
||
|
|
||
|
import 'package:flutter/material.dart';
|
||
|
|
||
|
class Backtop extends StatelessWidget {
|
||
|
const Backtop({
|
||
|
super.key,
|
||
|
required this.controller,
|
||
|
required this.offset,
|
||
|
this.distance = 1000.0,
|
||
|
});
|
||
|
|
||
|
final ScrollController controller;
|
||
|
/// 滚动位置
|
||
|
final double offset;
|
||
|
/// 距离顶部多远显示
|
||
|
final double distance;
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context){
|
||
|
return AnimatedOpacity(
|
||
|
opacity: offset > distance ? 1.0 : 0.0,
|
||
|
duration: Duration(milliseconds: 200),
|
||
|
child: IconButton(
|
||
|
onPressed: (){
|
||
|
controller.animateTo(0, duration: Duration(milliseconds: 300), curve: Curves.easeInOut);
|
||
|
},
|
||
|
icon: Icon(Icons.arrow_upward_rounded, size: 20.0,),
|
||
|
style: ButtonStyle(
|
||
|
backgroundColor: WidgetStateProperty.all(Colors.grey[100]),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|