Problems trying to implement this layout - flutter

I'm trying to design the following layout using flutter for a website, but I can't figure out the right pattern for doing so.
I tried many possibilities with columns and rows; I tried also using a stack, but whatever I use, either 3-4 won't become scrollable, or 5 won't take the height that it's given. Is there a workaround for this layout to be implemented?

You can easily accomplish what you want using this library.
flutter_staggered_grid_view
If you want your layout to take up entire screen, key is to use percentages of screen height for mainAxisExtent of StaggeredGridTile.extent
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(
MaterialApp(
home: AppView(),
),
);
}
class AppView extends StatelessWidget {
const AppView({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
var list = List<int>.generate(100, (i) => i);
var height = MediaQuery.of(context).size.height;
return Scaffold(
body: StaggeredGrid.count(
crossAxisCount: 3,
axisDirection: AxisDirection.down,
mainAxisSpacing: height * 0.015,
crossAxisSpacing: height * 0.015,
children: [
StaggeredGridTile.extent(
crossAxisCellCount: 1,
mainAxisExtent: height * 0.08,
child: Container(
color: Colors.amber,
),
),
StaggeredGridTile.extent(
crossAxisCellCount: 1,
mainAxisExtent: height * 0.08,
child: Container(
color: Colors.amber,
),
),
StaggeredGridTile.extent(
crossAxisCellCount: 1,
mainAxisExtent: height * 0.08,
child: Container(
color: Colors.amber,
),
),
StaggeredGridTile.extent(
crossAxisCellCount: 2,
mainAxisExtent: height * 0.08,
child: Container(
color: Colors.red,
),
),
StaggeredGridTile.extent(
crossAxisCellCount: 1,
mainAxisExtent: height * 0.675,
child: Container(
color: Colors.blue,
),
),
StaggeredGridTile.extent(
crossAxisCellCount: 1,
mainAxisExtent: height * 0.81,
// mainAxisCellCount: 1.2,
child: Container(
color: Colors.pink,
child: ListView(
children: list.map((e) => Text(e.toString())).toList(),
),
),
),
StaggeredGridTile.extent(
crossAxisCellCount: 1,
mainAxisExtent: height * .58,
child: Container(
color: Colors.orange,
child: ListView(
children: list.map((e) => Text(e.toString())).toList(),
),
),
),
StaggeredGridTile.extent(
crossAxisCellCount: 2,
mainAxisExtent: height * .23,
child: Container(
color: Colors.teal,
),
),
],
),
);
}
}

Use this
Scaffold(
resizeToAvoidBottomInset: false,
body: Container(
height: (MediaQuery.of(context).size.height) / 2,
child: Stack(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 2,
child: Column(
children: [
Container(
margin: EdgeInsets.all(4),
width: double.infinity,
height: (MediaQuery.of(context).size.height) / 8,
child: SizedBox(
height: 1,
width: 1,
child: const ColoredBox(color: Colors.amber),
)),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 2,
child: Container(
margin: EdgeInsets.all(4),
height:
(MediaQuery.of(context).size.height) / 3,
child: SizedBox(
height: 1,
width: 1,
child:
const ColoredBox(color: Colors.amber),
)),
),
Expanded(
flex: 1,
child: Container(
margin: EdgeInsets.all(4),
height: (MediaQuery.of(context).size.height) /
7.5,
child: SizedBox(
height: 1,
width: 1,
child:
const ColoredBox(color: Colors.amber),
)),
),
],
),
],
),
),
Expanded(
flex: 1,
child: Container(
margin: EdgeInsets.all(4),
height: ((MediaQuery.of(context).size.height) / 4) + 12,
child: SizedBox(
height: 1,
width: 1,
child: const ColoredBox(color: Colors.amber),
)),
),
],
),
Align(
alignment: Alignment.bottomRight,
child: Container(
padding: EdgeInsets.only(bottom: 20),
margin: EdgeInsets.all(4),
width: (MediaQuery.of(context).size.height) / 3.8,
height: (MediaQuery.of(context).size.height) / 5,
child: SizedBox(
height: 1,
width: 1,
child: const ColoredBox(color: Colors.amber),
)),
)
],
),
),
),

There is a github project for design a responsive screen.
The github link Flutter-Responsive-Admin-Panel-or-Dashboard

Related

How to avoid overlap in widget inside GridView?

The widget inside the gridView overlap each other , the bottom portion of the widget is overlapped by another widget , How to avoid overlap in widget inside GridView?I want to avoid the overlap amoung the widget.
Here is my codes
It contain a gridview builder containing the widget, the widget is made by stack , position.fill
// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables
import 'package:flutter/material.dart';
import 'package:iconsax/iconsax.dart';
class WorkshopsCloseToYouPage extends StatelessWidget {
const WorkshopsCloseToYouPage({super.key});
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: GridView.builder(
itemCount: 6,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2, crossAxisSpacing: 4.0, mainAxisSpacing: 4.0),
itemBuilder: (BuildContext context, int index) {
return workshopCard();
},
),
),
);
}
Stack workshopCard() {
return Stack(
clipBehavior: Clip.none,
children: [
Container(
width: 200,
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
image: DecorationImage(
image: AssetImage('assets/workshop_image.png'),
fit: BoxFit.cover,
),
),
),
Positioned.fill(
bottom: -100,
child: Align(
alignment: Alignment.bottomCenter,
child: Card(
margin: const EdgeInsets.all(5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"Pottery Throwing Taster Class",
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(
height: 5,
),
Row(
children: [
SizedBox(
width: 100,
child: Column(
children: [
Row(
children: [
Icon(
Iconsax.location5,
size: 16,
color: Color(0xFF083AA9),
),
SizedBox(
width: 2,
),
Text(
"Honslow",
// style: TextStyle(fontSize: 8),
)
],
),
SizedBox(
height: 5,
),
Row(
children: [
Icon(
Iconsax.profile_2user,
size: 16,
color: Color(0xFF083AA9),
),
SizedBox(
width: 2,
),
Text("1 to 15")
],
),
SizedBox(
height: 5,
),
Row(
children: [
Icon(
Iconsax.tag_right,
size: 16,
color: Color(0xFF083AA9),
),
SizedBox(
width: 2,
),
Text("1 to 15")
],
),
SizedBox(
height: 5,
),
Row(
children: [
Icon(
Iconsax.star,
size: 16,
color: Color(0xFF083AA9),
),
SizedBox(
width: 2,
),
Text("5(37)")
],
),
],
),
),
ElevatedButton(
onPressed: () {},
style: TextButton.styleFrom(
minimumSize: const Size(70, 35),
maximumSize: const Size(70, 35),
backgroundColor: Color(0xFF0c3cac),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20))),
child: Row(
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
child: Text(
"Join",
style: TextStyle(
color: Colors.white,
fontSize: 12,
),
),
),
Icon(size: 5, Icons.arrow_forward_ios),
Icon(
color: Color.fromARGB(255, 231, 227, 227),
size: 5,
Icons.arrow_forward_ios),
Icon(
color: Color.fromARGB(255, 181, 180, 180),
size: 5,
Icons.arrow_forward_ios),
],
)),
],
),
],
),
)),
),
)
],
);
}
}
Output page showing the widget overlap

NeverScrollableScrollPhysics() is not working in flutter and need advise about tab padding/margin

#1. I was making a tab menus using tabcontroller, and I wanted to stop it's tab scrolling ability, and wanted to select tab using tab menu click.
I was trying with physics: NeverScrollableScrollPhysics(), but failed.
As a newbie, I don't understand what is the problem or what I am missing!
Here is A GIF file to illustrate my scenario --> here
#2. In this Scenario, the "Places", means the first tab is maintains a padding, how can I remove it and push it to the left, from where the body started?
Thanks in Advance :)
My Code -->
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'dart:math' as math;
void main() => runApp(StartPage());
class StartPage extends StatelessWidget {
static const String _title = 'TravelApp';
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: _title,
home: Scaffold(body: StartPage1()),
);
}
}
class StartPage1 extends StatelessWidget {
#override
Widget build(BuildContext context) {
dynamic screenHeight = MediaQuery.of(context).size.height;
dynamic screenwidth = MediaQuery.of(context).size.width;
return Scaffold(
body: Container(
height: screenHeight,
width: screenwidth,
padding: EdgeInsets.symmetric(
horizontal: screenwidth * 0.03,
vertical: screenHeight * 0.02,
),
child: Container(
// Places BAr
height: screenHeight * 0.20,
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: DefaultTabController(
length: 3,
child: Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(screenHeight * 0.076607387),
child: new Container(
child: SafeArea(
child: Column(
children: <Widget>[
Expanded(
child: Container(),
),
Container(
height: screenHeight * 0.05,
margin: EdgeInsets.fromLTRB(
0,
0,
0,
screenHeight * 0.02,
),
alignment: Alignment.centerLeft,
child: TabBar(
indicator: CircleTabIndicator(
color: Color(0xFF7675E0),
radius: 4,
),
isScrollable: true,
labelColor: Color(0xFF7675E0),
unselectedLabelColor: Colors.grey,
physics: NeverScrollableScrollPhysics(),
tabs: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: Text(
"Placess",
style: GoogleFonts.sniglet(),
),
),
Tab(
child: Text(
"Activities",
style: GoogleFonts.sniglet(),
),
),
Tab(
child: Text(
"Hotels",
style: GoogleFonts.sniglet(),
),
),
],
),
)
],
),
),
),
),
body: TabBarView(
children: <Widget>[
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: screenwidth * 0.18,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(
0,
0,
0,
9,
),
child: ClipOval(
child: Material(
child: InkWell(
splashColor: Color(0xFF7675E0),
child: SizedBox(
width: screenwidth * 0.136253041,
height: screenHeight * 0.076607387,
child: Image(
image:
AssetImage('assets/1002.png'),
),
),
onTap: () {},
),
),
),
),
Text(
"Mountain",
style: GoogleFonts.sniglet(
color: Colors.black45,
),
),
],
),
),
Container(
width: screenwidth * 0.18,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(
0,
0,
0,
9,
),
child: ClipOval(
child: Material(
child: InkWell(
splashColor: Color(0xFF7675E0),
child: SizedBox(
width: screenwidth * 0.136253041,
height: screenHeight * 0.076607387,
child: Image(
image:
AssetImage('assets/1017.png'),
),
),
onTap: () {},
),
),
),
),
Text(
"Beach",
style: GoogleFonts.sniglet(
color: Colors.black45,
),
),
],
),
),
Container(
width: screenwidth * 0.18,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(
0,
0,
0,
9,
),
child: ClipOval(
child: Material(
child: InkWell(
splashColor: Color(0xFF7675E0),
child: SizedBox(
width: screenwidth * 0.136253041,
height: screenHeight * 0.076607387,
child: Image(
image:
AssetImage('assets/1013.png'),
),
),
onTap: () {},
),
),
),
),
Text(
"Location",
style: GoogleFonts.sniglet(
color: Colors.black45,
),
),
],
),
),
Container(
width: screenwidth * 0.18,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(
0,
0,
0,
screenHeight * 0.012311902,
),
child: ClipOval(
child: Material(
child: InkWell(
splashColor: Color(0xFF7675E0),
child: SizedBox(
width: screenwidth * 0.136253041,
height: screenHeight * 0.076607387,
child: Image(
image:
AssetImage('assets/1002.png'),
),
),
onTap: () {},
),
),
),
),
Text(
"More",
style: GoogleFonts.sniglet(
color: Colors.black45,
),
),
],
),
),
],
),
),
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: screenwidth * 0.18,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(
0,
0,
0,
9,
),
child: ClipOval(
child: Material(
child: InkWell(
splashColor: Color(0xFF7675E0),
child: SizedBox(
width: screenwidth * 0.136253041,
height: screenHeight * 0.076607387,
child: Image(
image:
AssetImage('assets/1004.png'),
),
),
onTap: () {},
),
),
),
),
Text(
"Mountain",
style: GoogleFonts.sniglet(
color: Colors.black45,
),
),
],
),
),
Container(
width: screenwidth * 0.18,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(
0,
0,
0,
9,
),
child: ClipOval(
child: Material(
child: InkWell(
splashColor: Color(0xFF7675E0),
child: SizedBox(
width: screenwidth * 0.136253041,
height: screenHeight * 0.076607387,
child: Image(
image:
AssetImage('assets/1013.png'),
),
),
onTap: () {},
),
),
),
),
Text(
"Beach",
style: GoogleFonts.sniglet(
color: Colors.black45,
),
),
],
),
),
Container(
width: screenwidth * 0.18,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(
0,
0,
0,
9,
),
child: ClipOval(
child: Material(
child: InkWell(
splashColor: Color(0xFF7675E0),
child: SizedBox(
width: screenwidth * 0.136253041,
height: screenHeight * 0.076607387,
child: Image(
image:
AssetImage('assets/1017.png'),
),
),
onTap: () {},
),
),
),
),
Text(
"Location",
style: GoogleFonts.sniglet(
color: Colors.black45,
),
),
],
),
),
Container(
width: screenwidth * 0.18,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(
0,
0,
0,
9,
),
child: ClipOval(
child: Material(
child: InkWell(
splashColor: Color(0xFF7675E0),
child: SizedBox(
width: screenwidth * 0.136253041,
height: screenHeight * 0.076607387,
child: Image(
image:
AssetImage('assets/1004.png'),
),
),
onTap: () {},
),
),
),
),
Text(
"More",
style: GoogleFonts.sniglet(
color: Colors.black45,
),
),
],
),
),
],
),
),
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: screenwidth * 0.18,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(
0,
0,
0,
9,
),
child: ClipOval(
child: Material(
child: InkWell(
splashColor: Color(0xFF7675E0),
child: SizedBox(
width: screenwidth * 0.136253041,
height: screenHeight * 0.076607387,
child: Image(
image:
AssetImage('assets/1002.png'),
),
),
onTap: () {},
),
),
),
),
Text(
"Mountain",
style: GoogleFonts.sniglet(
color: Colors.black45,
),
),
],
),
),
Container(
width: screenwidth * 0.18,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(
0,
0,
0,
9,
),
child: ClipOval(
child: Material(
child: InkWell(
splashColor: Color(0xFF7675E0),
child: SizedBox(
width: screenwidth * 0.136253041,
height: screenHeight * 0.076607387,
child: Image(
image:
AssetImage('assets/1013.png'),
),
),
onTap: () {},
),
),
),
),
Text(
"Beach",
style: GoogleFonts.sniglet(
color: Colors.black45,
),
),
],
),
),
Container(
width: screenwidth * 0.18,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(
0,
0,
0,
9,
),
child: ClipOval(
child: Material(
child: InkWell(
splashColor: Color(0xFF7675E0),
child: SizedBox(
width: screenwidth * 0.136253041,
height: screenHeight * 0.076607387,
child: Image(
image:
AssetImage('assets/1017.png'),
),
),
onTap: () {},
),
),
),
),
Text(
"Location",
style: GoogleFonts.sniglet(
color: Colors.black45,
),
),
],
),
),
Container(
width: screenwidth * 0.18,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(
0,
0,
0,
9,
),
child: ClipOval(
child: Material(
child: InkWell(
splashColor: Color(0xFF7675E0),
child: SizedBox(
width: screenwidth * 0.136253041,
height: screenHeight * 0.076607387,
child: Image(
image:
AssetImage('assets/1004.png'),
),
),
onTap: () {},
),
),
),
),
Text(
"More",
style: GoogleFonts.sniglet(
color: Colors.black45,
),
),
],
),
),
],
),
),
],
),
),
),
),
),
),
);
}
}
For the tabbar scrolling issue: you will need to set the NeverScrollableScrollPhysics() in TabBarView's physics property, and not in the TabBar's physics property.

Bottom Overflow Problem in Flutter Despite of Screen fixing(?!)

I was trying to make a responsive app that measure the screen height and than apply it's container's height according it. I split the app's page in (40%, 30% , 30%) portion, but the app showing the message "Bottom pixel overflow by 10.0 pixel".
And When I rotate the Scene, The middle portion container also show the same problem.
As A newbie, I Don't understand what is my wrong-doing or wrong-knowing?
Is the padding cause the problem?
And is there any simple or standard system to design a app responsive to various window ?
Thanks in Advance.
Here is my Code
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
/// This is the main application widget.
class MyApp extends StatelessWidget {
static const String _title = 'TravelApp';
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
//title: _title,
home: Scaffold(
//appBar: AppBar(
//centerTitle: true,
//title: const Text(_title),
//),
body: MyStatelessWidget(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
dynamic screenHeight = MediaQuery.of(context).size.height;
dynamic screenwidth = MediaQuery.of(context).size.width;
return Scaffold(
body: Container(
height: screenHeight,
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomRight,
colors: [Color(0xFDEAEC), Colors.grey]),
),
// Portion Started In The Column
child: Column(
children: <Widget>[
Container(
alignment: Alignment.center,
height: screenHeight * 0.40, //40% of Screen height
child: Image(
image: AssetImage('../assets/firstpag.jpg'),
),
),
Container(
alignment: Alignment.center,
height: screenHeight * 0.30, //30% of Screen height
color: Colors.green,
padding: EdgeInsets.fromLTRB(0, 30, 0, 0),
child: Column(
children: <Widget>[
Container(
alignment: Alignment.center,
child: Text(
"Let's Get Started",
style: TextStyle(fontSize: 25),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
padding: EdgeInsets.fromLTRB(10, 15, 10, 0),
child: Text(
"Lorem Ipsum is simply dummy text of the printing.Lorem Ipsum is simply dummy text of the printing",
style: TextStyle(
fontSize: 12,
),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
width: screenwidth * 0.20,
padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
alignment: Alignment.center,
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.blue,
height: 4,
width: 10,
)
],
)),
],
),
),
Container(
alignment: Alignment.center,
height: screenHeight * 0.30, //30% of Screen height
color: Colors.red,
padding: EdgeInsets.fromLTRB(0, 30, 0, 0),
child: Column(
children: <Widget>[
Container(
alignment: Alignment.center,
child: Text(
"Let's Get Started",
style: TextStyle(fontSize: 25),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
padding: EdgeInsets.fromLTRB(10, 15, 10, 0),
child: Text(
"Lorem Ipsum is simply dummy text of the printing.Lorem Ipsum is simply dummy text of the printing",
style: TextStyle(
fontSize: 18,
),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
width: screenwidth * 0.20,
padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
alignment: Alignment.center,
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.blue,
height: 4,
width: 10,
)
],
)),
],
),
)
],
),
));
}
}
The issue with the code above is that it is using a padding: EdgeInsets.all(5) which also means we're using 5px from the bottom and from the top as padding.
Therefore, the layout overflows by 10px.
A possible solution would be to either remove the padding or change it to horizontal-only, depending on the desired outcome:
padding: EdgeInsets.symmetric(horizontal: 5),
Full snippet code:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
/// This is the main application widget.
class MyApp extends StatelessWidget {
static const String _title = 'TravelApp';
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
//title: _title,
home: Scaffold(
//appBar: AppBar(
//centerTitle: true,
//title: const Text(_title),
//),
body: MyStatelessWidget(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
dynamic screenHeight = MediaQuery.of(context).size.height;
dynamic screenwidth = MediaQuery.of(context).size.width;
return Scaffold(
body: Container(
height: screenHeight,
padding: EdgeInsets.symmetric(horizontal: 5), // modified line
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomRight,
colors: [Color(0xFDEAEC), Colors.grey]),
),
// Portion Started In The Column
child: Column(
children: <Widget>[
Container(
alignment: Alignment.center,
height: screenHeight * 0.40, //40% of Screen height
child: Image(
image: AssetImage('../assets/firstpag.jpg'),
),
),
Container(
alignment: Alignment.center,
height: screenHeight * 0.30, //30% of Screen height
color: Colors.green,
padding: EdgeInsets.fromLTRB(0, 30, 0, 0),
child: Column(
children: <Widget>[
Container(
alignment: Alignment.center,
child: Text(
"Let's Get Started",
style: TextStyle(fontSize: 25),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
padding: EdgeInsets.fromLTRB(10, 15, 10, 0),
child: Text(
"Lorem Ipsum is simply dummy text of the printing.Lorem Ipsum is simply dummy text of the printing",
style: TextStyle(
fontSize: 12,
),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
width: screenwidth * 0.20,
padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
alignment: Alignment.center,
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.blue,
height: 4,
width: 10,
)
],
)),
],
),
),
Container(
alignment: Alignment.center,
height: screenHeight * 0.30, //30% of Screen height
color: Colors.red,
padding: EdgeInsets.fromLTRB(0, 30, 0, 0),
child: Column(
children: <Widget>[
Container(
alignment: Alignment.center,
child: Text(
"Let's Get Started",
style: TextStyle(fontSize: 25),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
padding: EdgeInsets.fromLTRB(10, 15, 10, 0),
child: Text(
"Lorem Ipsum is simply dummy text of the printing.Lorem Ipsum is simply dummy text of the printing",
style: TextStyle(
fontSize: 18,
),
textAlign: TextAlign.center,
),
),
Container(
alignment: Alignment.center,
width: screenwidth * 0.20,
padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
alignment: Alignment.center,
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.grey,
height: 4,
width: 5,
),
Container(
color: Colors.blue,
height: 4,
width: 10,
)
],
)),
],
),
)
],
),
));
}
}

`Stack` do not display content which are not within the area of its first Widget

I am trying to make a scrollable UI in flutter. I added a ListView and then inside it a Stack.
Below is my code
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
var scaffoldKey = GlobalKey<ScaffoldState>();
class TestPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
drawer: Drawer(
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Drawer Header'),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListTile(
title: Text('Item 1'),
onTap: () {
// Update the state of the app
// ...
// Then close the drawer
Navigator.pop(context);
},
),
ListTile(
title: Text('Item 2'),
onTap: () {
// Update the state of the app
// ...
// Then close the drawer
Navigator.pop(context);
},
),
],
),
),
body: Container(
height: double.infinity,
child: ListView(
shrinkWrap: true,
children: <Widget>[TestPageUI()],
),
),
key: scaffoldKey,
);
}
}
class TestPageUI extends StatefulWidget {
#override
State<StatefulWidget> createState() {
// TODO: implement createState
return TestPageState();
}
}
class TestPageState extends State<TestPageUI> {
#override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * .30,
width: double.infinity,
child: ClipPath(
clipper: ClippingClass(),
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * .30,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage("assets/images/morning_image.png"))),
),
),
),
SafeArea(
child: Row(
children: <Widget>[
IconButton(
icon: Icon(
Icons.menu,
color: Colors.white,
),
onPressed: () {
print("clicked");
scaffoldKey.currentState.openDrawer();
},
),
Spacer(
flex: 2,
),
IconButton(
icon: Icon(
Icons.notifications,
color: Colors.white,
),
onPressed: () {},
),
],
),
),
Positioned(
top: MediaQuery.of(context).size.height * .2,
left: 0.0,
right: 0.0,
child: Align(
alignment: Alignment.center,
child: Container(
child: Text(
"Good Morning, Fred",
style: Theme.of(context)
.textTheme
.headline
.apply(color: Colors.white),
),
),
),
),
Positioned(
top: MediaQuery.of(context).size.height * .3,
left: 0.0,
right: 0.0,
child: Container(
margin: EdgeInsets.only(left: 10, right: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width * .22,
height: 100,
child: Column(
children: <Widget>[
Image.asset(
"assets/icons/car_service.png",
width: 48,
height: 48,
),
Container(
margin: EdgeInsets.all(5),
child: Text(
"ONE",
style: Theme.of(context)
.textTheme
.caption
.apply(color: Colors.black),
textAlign: TextAlign.center,
),
)
],
),
),
Spacer(
flex: 1,
),
Container(
width: MediaQuery.of(context).size.width * .22,
height: 100,
child: Column(
children: <Widget>[
Image.asset(
"assets/icons/car_service.png",
width: 48,
height: 48,
),
Container(
margin: EdgeInsets.all(5),
child: Text(
"FOUR",
style: Theme.of(context)
.textTheme
.caption
.apply(color: Colors.black),
textAlign: TextAlign.center,
),
)
],
),
),
],
),
),
),
Positioned(
top: MediaQuery.of(context).size.height * .54,
left: 0.0,
right: 0.0,
child: Container(
height: MediaQuery.of(context).size.height,
child: ListView.builder(
itemCount: 100,
itemBuilder: (BuildContext context, int index) {
return Container(
margin: EdgeInsets.only(bottom: 10, left: 10, right: 10),
child: _createAdvertisement(),
);
},
),
),
)
],
);
}
Widget _createAdvertisement() {
return Card(
elevation: 4.0,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)),
clipBehavior: Clip.antiAlias,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
FadeInImage.assetNetwork(
alignment: Alignment.topCenter,
placeholder: "https://picsum.photos/200",
image: "https://picsum.photos/200",
fit: BoxFit.fill,
width: double.infinity,
height: MediaQuery.of(context).size.height * .9 / 4,
),
],
),
);
}
#override
void initState() {
// TODO: implement initState
super.initState();
}
}
class ClippingClass extends CustomClipper<Path> {
#override
Path getClip(Size size) {
var path = Path();
path.lineTo(0.0, size.height);
path.quadraticBezierTo(
size.width / 4, size.height - 30, size.width / 2, size.height - 30);
path.quadraticBezierTo(size.width - (size.width / 4), size.height - 30,
size.width, size.height);
path.lineTo(size.width, 0.0);
path.close();
return path;
}
#override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
There is an issue, below is the output
You can see that after the top background image, there is no content. The container holding the top background image is 30% of the height. whatever not within its area, will not get displayed. However if you increase its height, the rest of the content will get displayed as well as the background image size will increase.
What is wrong in here? How to display the content below the 30% height without an issue?
Also please note that I have another ListView at the end of the code. I do not want this ListView to scroll by its own, because the top ListView does the job of scrolling the full page.
Use overflow:Overflow.visible inside Stack()
like this-
Stack(overflow: Overflow.visible,
child:.....)

Off-screen flutter_swiper slide layout, Stack / Positioned widget

I am trying to achieve this layout and content using Flutter:
https://i.imgur.com/oqiZqHb.png
If I try to offset by -20 using a Positioned widget to have the sticky scroller feature of the flutter_swiper package hide on part of the screen and have the side headers on top of that to cover it I get:
I/flutter ( 6060): Another exception was thrown: A RenderFlex overflowed by Infinity pixels on the bottom.
Removing the Positioned Widget gets the part of the layout working, I might need an additional card in this example but I am struggling to get the slider to offset and have the correct swipable item proportions 141x118 on the Stack with 12 padding right and the third one slightly showing on the right but the widget starting point clips the first one as well.
https://i.imgur.com/AfjqIag.jpg
This is my code for the horizontal slider widget:
import 'package:flutter/cupertino.dart';
import '../../../theme/styles.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'dart:math';
class HorizontalIndicator extends StatefulWidget {
const HorizontalIndicator({
Key key,
}) : super(key: key);
#override
_HorizontalIndicatorState createState() => _HorizontalIndicatorState();
}
class _HorizontalIndicatorState extends State<HorizontalIndicator> {
#override
Widget build(BuildContext context) {
var rnd = new Random();
var next = rnd.nextInt(10) * 1;
double screenWidth = MediaQuery.of(context).size.width;
return Container(
height: 120,
padding: EdgeInsets.only(top: 0),
width: screenWidth,
child: Stack(
overflow: Overflow.visible,
fit: StackFit.expand,
children: <Widget>[
Container(
child: new Swiper(
itemBuilder: (BuildContext context, int index) {
return Container(
margin: EdgeInsets.symmetric(vertical: 6),
decoration: new BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(26)),
boxShadow: [
BoxShadow(
color: ThemeColor.shadowColor,
blurRadius:
3.0,
spreadRadius:
0,
)
],
),
child: Padding(
padding: const EdgeInsets.only(right: 12),
child: ClipRRect(
borderRadius: BorderRadius.circular(26),
child: Image.network(
"https://picsum.photos/150/120?" +
"$index" +
"$next",
fit: BoxFit.cover,
),
),
),
);
},
itemCount: 10,
viewportFraction: 0.43,
scale: 1,
itemWidth: 150,
itemHeight: 120,
layout: SwiperLayout.DEFAULT)),
]),
);
}
}
This is how I am positioning it:
...
Stack(
alignment: AlignmentDirectional.topStart,
fit: StackFit.loose,
overflow: Overflow.visible,
children: [
ListView(children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 85, left: 50),
child: Column(
children: <Widget>[
HorizontalIndicator(),
HorizontalIndicator(),
HorizontalIndicator(),
HorizontalIndicator(),
],
),
),
]),
//ProgressBarLarge2(),
],
),
...
I finally got this layout to work.
Here is how I positioned the items:
Stack(
alignment: AlignmentDirectional.topStart,
fit: StackFit.loose,
children: [
ListView(physics: ClampingScrollPhysics(), children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 80, left: 0),
child: Column(
children: <Widget>[
HorizontalIndicator(),
HorizontalIndicator(),
HorizontalIndicator(),
],
),
),
]),
ProgressBarLarge(
context, ThemeColor.primaryColor, 0.5, 48, 11, "Done", "Pending"),
],
),
This is how the horizontal widget was structured (sorry for the long code!).
I just used Stack and Positioned.fill widget with a -100 right value and tweaked the viewportFraction values:
Container(
height: 124,
padding: EdgeInsets.only(top: 0),
child: Stack(alignment: Alignment.centerLeft, children: <Widget>[
Positioned.fill(
left: 47,
right: -100,
child: Container(
child: new Swiper(
itemBuilder: (BuildContext context, move) {
return Container(
padding: EdgeInsets.symmetric(vertical: 0),
decoration: new BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(26)),
boxShadow: [
BoxShadow(
color: ThemeColor.shadowColor.withOpacity(0),
offset: Offset(0, 2),
blurRadius:
87.0, // has the effect of softening the shadow
spreadRadius:
0, // has the effect of extending the shadow
)
],
),
child: Padding(
padding: const EdgeInsets.all(0),
child: Container(
margin: EdgeInsets.all(5),
child: MaterialButton(
elevation: 0,
highlightElevation: 2,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(26.0)),
padding: EdgeInsets.fromLTRB(0, 0.0, 0, 0.0),
color: Colors.grey.shade800,
onPressed: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => SeatsPage()),
);
},
child: Container(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
left: 24,
top: 12,
right: 24),
child: FittedBox(
fit: BoxFit.scaleDown,
child: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: <Widget>[
Padding(
padding:
const EdgeInsets
.only(
top: 0,
right: 0),
child: Opacity(
opacity: 0.90,
child: Text(
"84",
style: ThemeText
.cardHeaderNumber,
textAlign:
TextAlign.left,
),
),
),
// Icon(
// Icons.more_vert,
// color: Colors.grey.withAlpha(0), // More
// ),
],
),
),
),
Padding(
padding:
const EdgeInsets.fromLTRB(
24, 2, 16, 2),
child: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: <Widget>[
Opacity(
opacity: 0.50,
child: Text(
"Available",
style: ThemeText
.cardText,
),
),
Icon(
Icons
.fiber_smart_record,
color: ThemeColor
.primaryColor,
),
],
))
],
),
),
],
),
),
),
),
));
},
itemCount: 4,
viewportFraction: viewportFraction,
scale: 1,
itemWidth: 140,
itemHeight: 120,
layout: SwiperLayout.DEFAULT)),
),
]),
),