Skip to content

Instantly share code, notes, and snippets.

@pjbelo
Last active December 13, 2023 14:59
Show Gist options
  • Save pjbelo/4ec341a672ccb96470bb6fc09b20305d to your computer and use it in GitHub Desktop.
Save pjbelo/4ec341a672ccb96470bb6fc09b20305d to your computer and use it in GitHub Desktop.
Flutter - Horizontal AND Vertical scroll demo
// Flutter - Horizontal AND Vertical scroll demo
// drag with mouse to scroll the 1200x1200 container inside the 300x300 container
// Live demo at https://dartpad.dev/?id=4ec341a672ccb96470bb6fc09b20305d
import 'package:flutter/material.dart';
import 'dart:ui';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: ScrollConfiguration(
behavior: ScrollConfiguration.of(context).copyWith(dragDevices: {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
}),
child: Center(
child: MyWidget(),
),
),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
width: 300,
height: 300,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: SingleChildScrollView(
child: LargeContainer(),
),
),
);
}
}
class LargeContainer extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
width: 1200,
height: 1200,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [
Colors.yellow,
Colors.red,
Colors.indigo,
Colors.teal,
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment