Skip to content

Instantly share code, notes, and snippets.

@gspencergoog
Created November 17, 2022 18:15
Show Gist options
  • Select an option

  • Save gspencergoog/e38050ab0d8758b979796a088cefc629 to your computer and use it in GitHub Desktop.

Select an option

Save gspencergoog/e38050ab0d8758b979796a088cefc629 to your computer and use it in GitHub Desktop.
2D Scrolling Test
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center,
color: Colors.green,
child: TextButton(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return const Dialog(child: MyDialog());
},
);
},
child: const Text('Open Dialog')));
}
}
class MyDialog extends StatelessWidget {
const MyDialog({super.key});
static const Size minSize = Size(200, 200);
static const Size maxSize = Size(400, 400);
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final Size constrainedSize = constraints.constrain(maxSize);
return SingleChildScrollView(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: SizedBox(
width: constrainedSize.width < minSize.width ? minSize.width : constrainedSize.width,
height: constrainedSize.height < minSize.height ? minSize.height : constrainedSize.height,
child: const Placeholder(color: Colors.red),
),
),
);
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment