朋友們,我想讓浮動動作按鈕在浮動動作按鈕中向上和向下滾動頁面時滑動,為此我應該使用哪個部件?
Mycode
FloatingActionButton.extended(
onPressed: () {
print("hello world"/span>)。
},
標簽。const Text('Update'/span>,style: TextStyle(color: Colors.white),)。
圖示。const Icon(Icons.update_outlined,color: Colors.white,)。
backgroundColor: Colors.blue,
// ForegroundColor: Text(Colors.white),
),
uj5u.com熱心網友回復:
讓我們試試,這里我們使用NotificationListener。在NotificationListener的幫助下,我們獲取螢屏資訊,當開始向上或向下滾動時,我們改變FloatingActionButtonLocation。
import 'package:flutter/material.dart'。
void main() {
runApp(MaterialApp(debugShowCheckedModeBanner: false, home: MyHomePage())。
}
class MyHomePage extends StatefulWidget{
const MyHomePage({
Key key,
}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState()。
}
class _MyHomePageState extends State< MyHomePage> {
ScrollController _scrollController = ScrollController()。
FloatingActionButtonLocation _floatingActionButtonLocation =
FloatingActionButtonLocation.endFloat。
@override
Widget build(BuildContext context) {
return SafeArea(
孩子。Scaffold(
floatingActionButton: FloatingActionButton(
child: Text("test"),
),
floatingActionButtonLocation: _floatingActionButtonLocation,
身體。容器(
孩子。NotificationListener(
onNotification: (ScrollNotification scrollInfo) {
setState(() {
if (scrollInfo.metrics.pelsels > 0.0) { //這里你改變了條件。
_floatingActionButtonLocation =
FloatingActionButtonLocation.endTop。
} else {
_floatingActionButtonLocation =
FloatingActionButtonLocation.endFloat。
}
});
return true;
},
孩子。ListView(
children: [
Text("data")。
Text("data")。
Text("data"),
Text("data"),
Text("data"),
Text("data")。
SizedBox(
高度。500,
),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data"),
Text("data")。
],
),
),
),
),
);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/329161.html
標籤:
上一篇:如何改變底部導航指示器的寬度
下一篇:如何使紐扣在一起的翩翩起舞
