From 303bd7fa127d248a7bbe393a526a6e40a3d0f99d Mon Sep 17 00:00:00 2001 From: mateusz-bak <32651935+mateusz-bak@users.noreply.github.com> Date: Sun, 7 Apr 2024 18:49:19 +0700 Subject: [PATCH] feat: Added frosted glass for AppBar in iOS --- lib/ui/books_screen/books_screen.dart | 39 ++++++++++++++++----- lib/ui/books_screen/widgets/books_grid.dart | 5 +++ lib/ui/books_screen/widgets/books_list.dart | 5 +++ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/lib/ui/books_screen/books_screen.dart b/lib/ui/books_screen/books_screen.dart index 949f5cae..a0a124ff 100644 --- a/lib/ui/books_screen/books_screen.dart +++ b/lib/ui/books_screen/books_screen.dart @@ -1,3 +1,6 @@ +import 'dart:io'; +import 'dart:ui'; + import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -32,6 +35,7 @@ class BooksScreen extends StatefulWidget { class _BooksScreenState extends State with AutomaticKeepAliveClientMixin, TickerProviderStateMixin { late List moreButtonOptions; + late double appBarHeight; Set selectedBookIds = {}; late TabController _tabController; @@ -858,6 +862,8 @@ class _BooksScreenState extends State @override void initState() { + appBarHeight = AppBar().preferredSize.height; + super.initState(); _tabController = TabController(length: 3, vsync: this); @@ -889,6 +895,7 @@ class _BooksScreenState extends State _resetMultiselectMode(); }, child: Scaffold( + extendBodyBehindAppBar: true, resizeToAvoidBottomInset: true, appBar: selectedBookIds.isNotEmpty ? _buildMultiSelectAppBar(context) @@ -961,10 +968,11 @@ class _BooksScreenState extends State ]), ), ), - SafeArea( - child: Builder(builder: (context) { - return Container( - color: Theme.of(context).scaffoldBackgroundColor, + Builder(builder: (context) { + return Container( + color: Theme.of(context).scaffoldBackgroundColor, + child: SafeArea( + top: false, child: TabBar( controller: _tabController, dividerColor: Colors.transparent, @@ -992,9 +1000,9 @@ class _BooksScreenState extends State ), ]), ), - ); - }), - ), + ), + ); + }), ], ); } else { @@ -1014,8 +1022,9 @@ class _BooksScreenState extends State ); } - AppBar _buildAppBar(BuildContext context) { - return AppBar( + PreferredSizeWidget _buildAppBar(BuildContext context) { + AppBar appBar = AppBar( + backgroundColor: Theme.of(context).colorScheme.surface.withOpacity(0.9), title: const Text( Constants.appName, style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), @@ -1053,6 +1062,18 @@ class _BooksScreenState extends State ), ], ); + + return Platform.isAndroid + ? appBar + : PreferredSize( + preferredSize: Size(double.infinity, appBarHeight), + child: ClipRRect( + child: BackdropFilter( + filter: ImageFilter.blur(sigmaX: 30, sigmaY: 30), + child: appBar, + ), + ), + ); } StreamBuilder> _buildToReadBooksTabView() { diff --git a/lib/ui/books_screen/widgets/books_grid.dart b/lib/ui/books_screen/widgets/books_grid.dart index fae2b42d..2d39b452 100644 --- a/lib/ui/books_screen/widgets/books_grid.dart +++ b/lib/ui/books_screen/widgets/books_grid.dart @@ -62,6 +62,11 @@ class _BooksGridState extends State return CustomScrollView( slivers: [ + SliverToBoxAdapter( + child: SizedBox( + height: MediaQuery.of(context).padding.top, + ), + ), SliverToBoxAdapter( child: Padding( padding: const EdgeInsets.fromLTRB(10, 0, 10, 10), diff --git a/lib/ui/books_screen/widgets/books_list.dart b/lib/ui/books_screen/widgets/books_list.dart index 2fd476ef..276c4fa1 100644 --- a/lib/ui/books_screen/widgets/books_list.dart +++ b/lib/ui/books_screen/widgets/books_list.dart @@ -62,6 +62,11 @@ class _BooksListState extends State return CustomScrollView( slivers: [ + SliverToBoxAdapter( + child: SizedBox( + height: MediaQuery.of(context).padding.top, + ), + ), SliverToBoxAdapter( child: widget.allBooksCount != null ? Padding(