Skip to content

Instantly share code, notes, and snippets.

@wemgl
Last active January 11, 2025 14:36
Show Gist options
  • Save wemgl/784f4435c7491cfba3b5f994545d521a to your computer and use it in GitHub Desktop.
Save wemgl/784f4435c7491cfba3b5f994545d521a to your computer and use it in GitHub Desktop.
stackoverflow_question_solution_74152502
import 'dart:math';
import 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: CustomScrollView(
slivers: <Widget>[
const SliverToBoxAdapter(
child: Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: EdgeInsets.all(16.0),
child: SizedBox(height: 16.0, child: Text("Some Title")),
),
),
),
SliverGrid.builder(
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 120,
),
itemBuilder: (context, index) {
return Container(
color: _randomColor(),
);
},
itemCount: 100,
),
],
),
),
),
);
}
Color _randomColor() {
final index = Random().nextInt(Colors.primaries.length);
return Colors.primaries[index];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment