Flutter

Flutter SliverAppBar

2020-03-06  本文已影响0人  三只仓鼠
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: SafeArea(
          child: Scaffold(
        body: Home(),
      )),
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      slivers: <Widget>[
        SliverAppBar(
          expandedHeight: 210,
          floating: false,////滑动时是否悬浮
          pinned: true,//固定标题栏
          flexibleSpace: FlexibleSpaceBar(
            title: Text("Demo Title"),
            centerTitle: true,
            background: Image.network(
              "http://pic26.nipic.com/20130122/5056611_171645641000_2.jpg",
              fit: BoxFit.cover,
            ),
          ),
        ),
        SliverFillRemaining(
          child: Container(),
        )
      ],
    );
  }
}

上一篇下一篇

猜你喜欢

热点阅读