Skip to content

Instantly share code, notes, and snippets.

@ademar111190
Last active August 1, 2022 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ademar111190/9efeaab35d76d686fa43942791f027b8 to your computer and use it in GitHub Desktop.
Save ademar111190/9efeaab35d76d686fa43942791f027b8 to your computer and use it in GitHub Desktop.
Preview your widgets
import 'gits…/fill_view_port_column_scroll_view.dart';
import 'package:flutter/material.dart';
class Preview extends StatelessWidget {
final List<Widget> children;
const Preview(
this.children, {
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Stack(
children: [
LayoutBuilder(
builder: (context, constraints) {
final cols = constraints.maxWidth ~/ 8;
final rows = constraints.maxHeight ~/ 8;
return GridView.builder(
itemCount: cols * rows + cols,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: cols,
childAspectRatio: 1.0,
crossAxisSpacing: 0.0,
mainAxisSpacing: 0.0,
),
itemBuilder: (context, index) {
final oddRow = (index ~/ cols).isOdd;
final oddCol = (index % cols).isOdd;
return Container(
color: oddRow == oddCol ? Colors.grey.withAlpha(128) : Colors.blueGrey.withAlpha(128),
);
},
);
},
),
FillViewPortColumnScrollView(
children: children,
),
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment