가을기 Workspace

[플러터] 30일차 - 스크롤시 역동적인 앱바 본문

개발/개인앱

[플러터] 30일차 - 스크롤시 역동적인 앱바

가을기_ 2021. 8. 19. 23:20

 

 

  • 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)),
        ],
      ),
    );
  }
}
Comments