Screen of the strange top padding of my app
I have made two classes : the first has a first AppBar and calls the second one that has also a sticky AppBar and display a list of scrollable Items. However, I have a strange top padding in the second AppBar. I have tried a lot of stuff but nothing seems to work.
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
extendBodyBehindAppBar: true,
bottomNavigationBar: BottomNavBar(0, _currentAccount),
appBar: PreferredSize(
preferredSize:
Size.fromHeight(MediaQuery.of(context).size.height / 7),
child: Column(
children: [
Container(
width: MediaQuery.of(context).size.width,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: <Color>[
Color(0xFF894c56),
Color(0xFFa80d0d)
])),
child: Padding(
padding: const EdgeInsets.only(bottom: 30),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.only(top: 50, left: 5),
child: Text(
'Votre évenement ',
style: TextStyle(
fontSize: 15, color: Colors.grey),
)),
Padding(
padding: const EdgeInsets.only(top: 5, left: 5),
child: Text(
event,
style: const TextStyle(
color: Colors.white, fontSize: 17),
),
)
])),
)
],
),
),
body: ListPrestat('Traiteur', _currentAccount)
// ListPrestat('Traiteur', _currentAccount)
));
}
This is the code of my first class that calls the ListPrestat class here under :
#override
Widget build(BuildContext context) {
return SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height ,
// -(MediaQuery.of(context).size.height / 6 + 56),
child: CustomScrollView(
slivers: [
SliverAppBar(
toolbarHeight: 50,
expandedHeight: 0,
backgroundColor: const Color(0xFFDCDCDC),
pinned: true,
leading: IconButton(
icon: const Icon(
Icons.arrow_back,
color: Color(0xFFDC3535),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => MainScreen(_currentAccount)),
);
},
),
centerTitle: true,
shadowColor: Colors.black,
elevation: 10,
bottom: const PreferredSize(
preferredSize: Size.fromHeight(0),
child: TagList(ListCat: 'brouette')),
title: Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.all(MediaQuery.of(context).size.width / 4),
child: Text(
_currentCat,
style: const TextStyle(
color: Colors.black,
fontSize: 16.0,
fontWeight: FontWeight.w700,
),
)),
),
SliverFixedExtentList(
itemExtent: 110.0,
delegate: SliverChildListDelegate(
[
for (int index = 0; index < 5; index++)
CustomListItem2(
thumbnail: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: AspectRatio(
child: Image.network(
growableList[index],
width: 100.0,
height: 100.0,
fit: BoxFit.fill,
),
aspectRatio: 1 / 1,
)),
title: 'Chez Luigi',
subtitle: 'Les meilleurs pizza hors d\'italie.',
ListCat: 'Food Truck',
),
],
),
)
],
),
);
}
Do you have any idea what can have caused this padding and how to resolve this problem ?
wrap your secound class with scaffold
Scaffold(
body: SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height ,),
...................
)
Related
I want to design this ui bellow in flutter the problem is the categories list as you can see it changes on scroll the items design change from vertical to horizontal, here my code down bellow, I m wondering how can I do that on flutter
Click here to see the design I m talking about, you can notice that under the search bar the list design changes, I want to do that
class FavouritesScreen extends StatelessWidget {
const FavouritesScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: CustomScrollView(
physics: BouncingScrollPhysics(),
slivers: [
SliverAppBar(
expandedHeight: 104,
floating: true,
pinned: true,
snap: false,
titleSpacing: 0,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
title: Padding(
padding: const EdgeInsets.only(left: 16.0, right: 16.0, top: 4),
child: Text(
"My List",
style: TextStyle(color: Gray500, fontSize: 26),
),
),
bottom: AppBar(
elevation: 0,
titleSpacing: 0,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
title: Padding(
padding:
const EdgeInsets.only(left: 16.0, right: 16.0, top: 4),
child: Container(
height: 48,
child: Row(
children: [
Expanded(
child: Container(
height: 48,
width: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Gray100,
),
child: Row(
children: [
SizedBox(
width: 10,
),
Icon(
Icons.search,
color: Gray300,
),
SizedBox(
width: 10,
),
Text(
"Search",
style: TextStyle(
color: Gray300,
),
),
],
),
),
),
SizedBox(
width: 16,
),
Container(
height: 48,
width: 48,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.black),
child: Icon(Icons.date_range),
)
],
),
),
),
),
),
SliverToBoxAdapter(
child: Column(
children: [
//the list of the menu
],
),
)
],
),
),
);
}
}
I want to create a list in Flutter with a small preview of the content before the user sees all information on a new screen.
Therefor I build a simple list with Sliver-Cards:
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Cards'),
backgroundColor: Colors.blue,
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
child: CustomScrollView(
shrinkWrap: false,
slivers: <Widget>[
_buildHeader(),
_buildCard('1', Colors.white, Colors.red, Colors.transparent),
_buildCard('2', Colors.white, Colors.blue, Colors.red),
_buildCard('3', Colors.white, Colors.green, Colors.blue),
…
],
),
),
);
}
Widget _buildHeader() => SliverStickyHeader(
header: Container(
height: 50,
color: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 16),
alignment: Alignment.topLeft,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Center(
child: Text(
"Card-Header",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.black),
),
),
],
),
),
sliver: SliverToBoxAdapter(
child: Container(
height: 20,
),
),
);
Widget _buildCard(
String logo, Color logoColor, Color cardColor, Color prevColor) =>
SliverStickyHeader(
header: GestureDetector(
child: Stack(
children: <Widget>[
Container(
height: 16,
color: prevColor,
),
Container(
height: 60,
decoration: BoxDecoration(
color: cardColor,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16))),
padding: const EdgeInsets.symmetric(horizontal: 16),
alignment: Alignment.bottomLeft,
child: Text(
logo,
style:
TextStyle(color: logoColor, fontWeight: FontWeight.bold),
),
),
],
),
),
sliver: SliverToBoxAdapter(
child: Container(
height: 20,
color: cardColor,
),
),
);
Here’s a Screenshot:
The only thing missing is the method to show a small preview of the content, which I want to stick to the top of the list. For example, anything like in this GitHub post: https://github.com/loopeer/CardStackView/blob/master/screenshot/screenshot1.gif
Is it possible to create a method like this in flutter?
I'm using the GridView.count widget which works alright. But when I'm scrolling down you can see the tiles going behind my other stuff above my GridView part. You can see it through the little Spaces. I want them to disappear when they go above their starting point.
Also please give me any advice on other parts of my code (3 weeks into Flutter).
enter image description here
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(backgroundColor: Colors.blueGrey[700],
appBar: AppBar(
backgroundColor: Colors.green[200],
foregroundColor: Colors.black,
centerTitle: true,
title: const Text("Stromberg Soundboard"),
),
body: ListView(
children: [
Container(
margin: EdgeInsets.all(3),
height: 250,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: const DecorationImage(
image: AssetImage('assets/bernd.jpeg'), fit: BoxFit.cover),
),
),
const SeasonsAndJokes(),
],
),
),
);
}
}
#override
Widget build(BuildContext context) {
return Column(
children: [
Container(
height: 30,
width: double.infinity,
margin: const EdgeInsets.only(left: 5, right: 5, bottom: 5),
color: Colors.green[100],
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
padding: const EdgeInsets.all(0),
alignment: Alignment.topLeft,
iconSize: 32,
disabledColor: Colors.white,
onPressed: lastSeason,
icon: const Icon(Icons.arrow_left_sharp),
),
Text(
seasonsText[indexische],
style: const TextStyle(fontWeight: FontWeight.bold),
textScaleFactor: 1.3,
),
IconButton(
padding: const EdgeInsets.all(0),
alignment: Alignment.topRight,
iconSize: 32,
onPressed: nextSeason,
icon: const Icon(Icons.arrow_right_sharp),
)
],
),
),
SizedBox(
height: 380,
child: GridView.count(
padding: const EdgeInsets.only(right: 5, left: 5),
crossAxisSpacing: 5,
mainAxisSpacing: 5,
crossAxisCount: 2,
childAspectRatio: 3,
children: [
for (int i = 0; i < titelSeasonOne.length; i++)
ListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: const BorderSide(color: Colors.white38),
),
trailing: const Icon(
Icons.volume_up_sharp,
color: Colors.blueGrey,
),
tileColor: Colors.green[200],
textColor: Colors.black87,
title: Text(
titelSeasonOne[i],
textScaleFactor: 1,
),
onTap: () {
final player = AudioCache();
player.play(audioSeasonOne[i]);
},
),
],
),
)
],
);
}
}
I want these animation between to be smooth, I tried using AnimatedSize, AnimatedOpacity and AnimatedPositioned but there were few errors. And I don't know how to use these with SliverAppBar. In other examples I saw people using LayoutBuilder but they didn't share the full code so I couldn't test it. I will share my code snippet but it has a really odd transition between the two states.
I want CircleAvatar to become smaller and change position
I want Icon(Icons.arrow_back) and Text('Previous Page') to disappear.
I also want my name and job to disappear.
I want that three Containers to become smaller and change position.
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: 'Dialog Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: CustomScrollView(
slivers: [
SliverAppBar(
elevation: 0,
pinned: true,
expandedHeight: 190,
collapsedHeight: kToolbarHeight + 8,
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.none,
centerTitle: true,
titlePadding: EdgeInsetsDirectional.only(
start: 20.0,
end: 20.0,
top: 12.0,
bottom: 12.0,
),
title: SafeArea(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CircleAvatar(
radius: 16,
),
Row(
children: [
Container(
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
padding: EdgeInsets.all(8.0),
child: Icon(Icons.person),
),
SizedBox(
width: 8,
),
Container(
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
padding: EdgeInsets.all(8.0),
child: Icon(Icons.menu),
),
SizedBox(
width: 8,
),
Container(
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
padding: EdgeInsets.all(8.0),
child: Icon(Icons.message),
),
],
),
],
),
],
),
),
background: SafeArea(
child: Column(
children: [
Container(
alignment: Alignment.topLeft,
child: Row(
children: [
IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {},
),
Text(
'PREVIOUS PAGE',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(
left: 20,
top: 12,
bottom: 24,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(
radius: 20,
),
SizedBox(
width: 12,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Sertan Hakkı İmamoğlu',
style: TextStyle(
fontSize: 18,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
Text(
'Student',
style: TextStyle(
fontSize: 14,
color: Colors.grey,
),
),
SizedBox(
height: 12,
),
Row(
children: [
Container(
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
padding: EdgeInsets.symmetric(
horizontal: 34,
vertical: 12,
),
child: Icon(Icons.menu),
),
SizedBox(
width: 4,
),
Container(
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
padding: EdgeInsets.symmetric(
horizontal: 34,
vertical: 12,
),
child: Icon(Icons.person),
),
SizedBox(
width: 4,
),
Container(
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
padding: EdgeInsets.symmetric(
horizontal: 34,
vertical: 12,
),
child: Icon(Icons.message),
),
],
)
],
)
],
),
),
],
),
),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
color: index.isOdd ? Colors.white : Colors.black12,
height: 100.0,
child: Center(
child: Text('$index', textScaleFactor: 5),
),
);
},
childCount: 20,
),
),
],
),
),
);
}
}
Here's my take on your issue, as suggested by pskink I've used a SliverPersistentHeader and tried to make it responsive so when the size is reducing it has a bit of an animation.
Sample Code
class CustomPageHeader extends SliverPersistentHeaderDelegate {
CustomPageHeader({
required double collapsedHeight,
required double expandedHeight,
}) : minExtent = collapsedHeight, maxExtent = expandedHeight;
#override
final double minExtent;
#override
final double maxExtent;
Widget _buildBtn(IconData icon, double scale) {
double horizontal = 34.0 * scale;
horizontal = horizontal < 8 ? 8.0 : horizontal;
double vertical = 12.0 * scale;
vertical = vertical < 8 ? 8.0 : vertical;
return Container(
decoration: const BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
padding: EdgeInsets.symmetric(horizontal: horizontal, vertical: vertical),
child: Icon(icon),
);
}
#override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
final theme = Theme.of(context);
final backgroundColor =
theme.appBarTheme.backgroundColor ?? theme.colorScheme.primary;
final scale = 1 - shrinkOffset / maxExtent;
final isReduced = shrinkOffset >= maxExtent * 0.12;
final wrappedBtns = Wrap(
spacing: 8,
children: [
_buildBtn(Icons.menu, scale),
_buildBtn(Icons.person, scale),
_buildBtn(Icons.message, scale),
],
);
double avatarRadius = 20.0 * scale;
avatarRadius = avatarRadius > 16 ? avatarRadius : 16.0;
return Container(
padding: const EdgeInsets.only(
left: 20,
top: 12,
bottom: 12,
),
color: backgroundColor,
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(radius: avatarRadius),
!isReduced
? const SizedBox(width: 12)
: Expanded(child: Container()),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (!isReduced)
Text(
'Sertan Hakkı İmamoğlu',
style: TextStyle(
fontSize: 18 * scale,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
if (!isReduced)
Text(
'Student',
style: TextStyle(
fontSize: 14 * scale,
color: Colors.grey,
),
),
],
),
if (isReduced) wrappedBtns,
],
),
Flexible(
child: Container(
constraints: const BoxConstraints(maxHeight: 12),
),
),
if (!isReduced) wrappedBtns,
],
),
);
}
#override
bool shouldRebuild(_) => true;
}
Use it in your sliver list like this:
SliverPersistentHeader(
pinned: true,
delegate: CustomPageHeader(
collapsedHeight: kToolbarHeight + 8,
expandedHeight: 190,
),
),
Try the full test code on DartPad
The code is perfectible but should help you enough so you can improve it and continue by yourself.
Please, would you look at the attached screenshot and tell me where that band of off-white is coming from?? (red arrow.)
I want the rounded container to display text right down to the bottom of the screen--any text-overflow will simply be scrolled by the SingleChildScrollView widget, but the container just gets thinner and thinner while that block of grey just stays there??
Been working in Flutter since March of 2018, and Flutter's layout widgets are still a mystery!
Here is the code:
#override
Widget build(BuildContext context) {
return Scaffold(
// primary: false,
appBar: AppBar(
title: I10n.t('Playhouse'),
centerTitle: true,
automaticallyImplyLeading: false,
elevation: 0,
excludeHeaderSemantics: true,
),
endDrawer: const ScrapBookDrawer(),
body: SafeArea(
child: Column(
children: [
/// Submodule Name | Short Description
Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 10, top: 4),
child: Text(
'${widget.subTask['subName']} |',
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
),
const Expanded(
child: Padding(
padding: EdgeInsets.only(top: 4),
child: Text(
'Submodule description',
),
),
),
],
),
Stack(
alignment: AlignmentDirectional.topCenter,
children: <Widget>[
/// Large Picture
Container(
height: 500, // double.infinity,
child: Crop(
interactive: false,
backgroundColor: Colors.white,
dimColor: Colors.white,
controller: CropController(),
child: Image.memory(
base64.decode(
con.submodule['image'],
),
),
),
),
Positioned(
left: 0,
right: 0,
top: 300,
/// Rounded Container
child: Container(
height: 500,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(60),
topRight: Radius.circular(60),
),
color: Colors.white,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
/// Task Name and Number
Padding(
padding: const EdgeInsets.only(top: 30, bottom: 20),
child: Text(
widget.subTask['name'],
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
),
/// Short Description or Title
Padding(
padding: const EdgeInsets.only(bottom: 20),
child: Text(widget.subTask['short_description']),
),
/// Long Description
Flexible(
flex: 300,
child: SingleChildScrollView(
child: Text(widget.subTask['long_description']),
),
),
],
),
),
)
],
),
],
),
),
);
}
I got rid of the white area by increasing height of the first Container in the Stack. Seems like it is just a default background that's not covered with anything.