From 7e0c0d50e6d0605a61685b45261c8ba0ec04a066 Mon Sep 17 00:00:00 2001 From: zhang <494089941@qq.com> Date: Fri, 15 Jan 2021 16:13:15 +0800 Subject: [PATCH] update app bar --- lib/pages/home/home_page.dart | 63 ++++++++------------ lib/pages/home/widget/animate_app_bar.dart | 69 ++++++++++++++++++++++ lib/pages/personal/personal_page.dart | 2 + 3 files changed, 94 insertions(+), 40 deletions(-) create mode 100644 lib/pages/home/widget/animate_app_bar.dart diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index 9551a3df..ad85ab4b 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -4,6 +4,7 @@ import 'package:akuCommunity/base/base_style.dart'; import 'package:akuCommunity/const/resource.dart'; import 'package:akuCommunity/pages/activities_page/activities_page.dart'; import 'package:akuCommunity/pages/convenient_phone/convenient_phone_page.dart'; +import 'package:akuCommunity/pages/home/widget/animate_app_bar.dart'; import 'package:akuCommunity/pages/industry_committee/industry_committee_page.dart'; import 'package:akuCommunity/pages/life_pay/life_pay_page.dart'; import 'package:akuCommunity/pages/message_center_page/message_center_page.dart'; @@ -48,6 +49,9 @@ class _HomePageState extends State @override bool get wantKeepAlive => true; + ScrollController _scrollController; + Color _bgColor; + List _shopList = []; List data; @@ -102,6 +106,8 @@ class _HomePageState extends State akuShop(value); }); // akuShop(page); + _scrollController = ScrollController(); + } Future akuShop(String response) async { @@ -142,6 +148,8 @@ class _HomePageState extends State ); } + + @override Widget build(BuildContext context) { super.build(context); @@ -149,47 +157,21 @@ class _HomePageState extends State designSize: Size(750, 1334), allowFontScaling: true); return Scaffold( extendBodyBehindAppBar: true, - appBar: AppBar( - title: 'TEST'.text.make(), - backgroundColor: Colors.transparent, - elevation: 0, - centerTitle: true, - leading: Container( - margin: EdgeInsets.only(left: 32.w), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - '深圳', - style: TextStyle( - fontWeight: FontWeight.w600, - fontSize: 24.sp, - color: Color(0xff333333), - ), - ), - Text( - '阴 27℃', - style: TextStyle( - fontSize: 20.sp, - color: Color(0xff333333), - ), - ) - ]), + appBar: AnimateAppBar( + scrollController: _scrollController, + actions:[ + _buildColButton( + icon: AntDesign.scan1, + title: '扫一扫', + onTap: () => Get.to(ScanPage()), ), - actions: [ - _buildColButton( - icon: AntDesign.scan1, - title: '扫一扫', - onTap: () => Get.to(ScanPage()), - ), - _buildColButton( - icon: AntDesign.bells, - title: '消息', - onTap: () => Get.to(MessageCenterPage()), - ), - 16.wb, - ], + _buildColButton( + icon: AntDesign.bells, + title: '消息', + onTap: () => Get.to(MessageCenterPage()), + ), + 16.wb, + ], ), body: RefreshConfiguration( child: SmartRefresher( @@ -200,6 +182,7 @@ class _HomePageState extends State enablePullUp: true, enablePullDown: false, child: CustomScrollView( + controller: _scrollController, slivers: [ SliverToBoxAdapter( child: Column( diff --git a/lib/pages/home/widget/animate_app_bar.dart b/lib/pages/home/widget/animate_app_bar.dart new file mode 100644 index 00000000..8258c76e --- /dev/null +++ b/lib/pages/home/widget/animate_app_bar.dart @@ -0,0 +1,69 @@ +import 'package:flutter/material.dart'; +import 'package:velocity_x/velocity_x.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; + +class AnimateAppBar extends StatefulWidget with PreferredSizeWidget { + final ScrollController scrollController; + final List actions; + AnimateAppBar({Key key, this.scrollController, this.actions}) + : super(key: key); + + @override + _AnimateAppBarState createState() => _AnimateAppBarState(); + + @override + // TODO: implement preferredSize + Size get preferredSize => Size.fromHeight(56); +} + +class _AnimateAppBarState extends State { + Color _bgColor = Colors.transparent; + @override + void initState() { + super.initState(); + widget.scrollController.addListener(() { + setState(() { + _bgColor = widget.scrollController.offset > 30 + ? Color(0xFFFFBD00) + : widget.scrollController.offset < 0 + ? Colors.transparent + : Color(0xFFFFBD00) + .withOpacity((widget.scrollController.offset / 30)); + }); + }); + } + + @override + Widget build(BuildContext context) { + return AppBar( + title: 'TEST'.text.make(), + backgroundColor: _bgColor, + elevation: 0, + centerTitle: true, + leading: Container( + margin: EdgeInsets.only(left: 32.w), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + '深圳', + style: TextStyle( + fontWeight: FontWeight.w600, + fontSize: 24.sp, + color: Color(0xff333333), + ), + ), + Text( + '阴 27℃', + style: TextStyle( + fontSize: 20.sp, + color: Color(0xff333333), + ), + ) + ]), + ), + actions: widget.actions, + ); + } +} diff --git a/lib/pages/personal/personal_page.dart b/lib/pages/personal/personal_page.dart index e563ca57..941b27ef 100644 --- a/lib/pages/personal/personal_page.dart +++ b/lib/pages/personal/personal_page.dart @@ -94,6 +94,8 @@ class _PersonalIndexState extends State SliverAppBar _sliverAppBar(double height) { final userProvider = Provider.of(context); return SliverAppBar( + pinned: true, + toolbarHeight: 0, elevation: 0, stretch: true, floating: true,