Skip to content

Instantly share code, notes, and snippets.

@SharbelOkzan
Created July 22, 2022 19:09
Show Gist options
  • Select an option

  • Save SharbelOkzan/83f3cc061baabb4136ce6e59411a83fa to your computer and use it in GitHub Desktop.

Select an option

Save SharbelOkzan/83f3cc061baabb4136ce6e59411a83fa to your computer and use it in GitHub Desktop.
Right to Left Horizontal ListView
import 'package:flutter/material.dart';
import 'package:flutter/gestures.dart';
main() {
runApp(
MaterialApp(
// ignore this line if running on mobile
scrollBehavior: MyCustomScrollBehavior(),
debugShowCheckedModeBanner: false,
home: RtLListView(),
),
);
}
class RtLListView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Right to Left Horizontal ListView builder'),
),
body: Directionality(
textDirection: TextDirection.rtl,
child: ListView.builder(
itemBuilder: (_, i) =>
Padding(padding: EdgeInsets.all(20), child: Text('$i')),
scrollDirection: Axis.horizontal,
itemCount: 50,
),
),
);
}
}
class MyCustomScrollBehavior extends MaterialScrollBehavior {
// Override behavior methods and getters like dragDevices
@override
Set<PointerDeviceKind> get dragDevices => {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment