- main.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class SliverPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => _SliverPage();
}
class _SliverPage extends State<SliverPage> {
Widget customCard(String text) {
return Card(
child: Container(
height: 120,
child: Center(
child: Text(
text,
style: TextStyle(fontSize: 40),
)),
));
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: [
SliverAppBar(
expandedHeight: 150.0,
flexibleSpace: FlexibleSpaceBar(
title: Text('Sliver Example'),
background: Image.asset('images/sunny.png'),
),
backgroundColor: Colors.deepOrangeAccent,
),
SliverList(
delegate: SliverChildListDelegate([
customCard('1'),
customCard('2'),
customCard('3'),
customCard('4'),
customCard('5'),
]),
),
SliverGrid(
delegate: SliverChildListDelegate([
customCard('1'),
customCard('2'),
customCard('3'),
customCard('4'),
customCard('5'),
]),
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2)),
],
),
);
}
}
Uploaded by Notion2Tistory v1.1.0