I have a dummy list of items I want to show a floating action button in swip up direction and hide it in down direction. how can I implement this functionality ?
class _MyHomePageState extends State<MyHomePage> {
bool upDirection = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Container(
child: Row(
children: <Widget>[
Expanded(
child: ListView.builder(
itemCount: 100,
itemBuilder: (context,index){
return ListTile(
title: Text(index.toString()),
);
},
),
)
],
),
),
),
floatingActionButton:upDirection==true?FloatingActionButton(onPressed: (){},):Container() ,
);
}
}
To scroll a Flutter ListView widget horizontally, set scrollDirection property of the ListView widget to Axis. horizontal. This arranges the items side by side horzontally. Following is the basic syntax to arrange the items horizontally in a ListView and scroll them horizontally.
You might want to create a list that scrolls horizontally rather than vertically. The ListView widget supports horizontal lists. Use the standard ListView constructor, passing in a horizontal scrollDirection , which overrides the default vertical direction.
All you need is a NotificationListener.onNotification
callback:
NotificationListener<UserScrollNotification>(
onNotification: (notification) {
final ScrollDirection direction = notification.direction;
return true;
},
child: ListView.builder(
itemCount: 100,
itemBuilder: (_, i) => ListTile(title: Text('$i')),
),
)
bool _visible = true;
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: AnimatedOpacity(
duration: Duration(milliseconds: 400),
opacity: _visible ? 1 : 0,
child: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {},
),
),
body: NotificationListener<UserScrollNotification>(
onNotification: (notification) {
final ScrollDirection direction = notification.direction;
setState(() {
if (direction == ScrollDirection.reverse) {
_visible = false;
} else if (direction == ScrollDirection.forward) {
_visible = true;
}
});
return true;
},
child: ListView.builder(
itemCount: 100,
itemBuilder: (_, i) => ListTile(title: Text('$i')),
),
),
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With