Skip to content

Instantly share code, notes, and snippets.

@alexsunday
Created April 4, 2023 12:08
Show Gist options
  • Save alexsunday/13738cafd5a3608e1ce0afb76a449e39 to your computer and use it in GitHub Desktop.
Save alexsunday/13738cafd5a3608e1ce0afb76a449e39 to your computer and use it in GitHub Desktop.
flutter scroll horizontal
import 'package:flutter/material.dart';
class TestSingleScroll extends StatelessWidget {
const TestSingleScroll({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
const n = 10;
final List<Widget> children = [];
for (int i = 0; i != n; i++) {
children.add(Container(
width: 100,
height: 100,
decoration: BoxDecoration(
border: Border.all(color: Colors.green, width: 1),
),
child: Center(
child: Text("$i"),
)));
}
return Container(
height: 200,
width: 600,
color: const Color.fromARGB(255, 227, 223, 223),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Row(
children: children,
),
),
);
}
}
void main() {
runApp(const MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: TestSingleScroll(),
),
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment