Why scroll direction horizontal is not working? - flutter

import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
class Screen extends StatefulWidget {
#override
_UserProfileScreenState createState() => _UserProfileScreenState();
}
class _UserProfileScreenState extends State<Screen> {
Widget randomjobs() {
final dbRef = FirebaseDatabase.instance
.reference()
.child("Add Job Details")
.limitToFirst(3);
return FutureBuilder(
future: dbRef.once(),
builder: (context, AsyncSnapshot<DataSnapshot> snapshot) {
if (snapshot.hasData) {
List<Map<dynamic, dynamic>> list = [];
if (snapshot.data.value == null) {
return Text("no Data");
}
for (String key in snapshot.data.value.keys) {
list.add(snapshot.data.value[key]);
}
return ListView.builder(
itemCount: snapshot.data.value.length,
itemBuilder: (BuildContext context, int index) {
return Container(
margin: EdgeInsets.only(top: 20.0),
height: 220.0,
child: PageView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 8, right: 8),
padding: EdgeInsets.only(
top: 20.0, left: 20.0, right: 20.0),
width: 240.0,
height: 240.0,
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(20.0)),
gradient: LinearGradient(
begin: Alignment.bottomRight,
end: Alignment.topLeft,
stops: [0.2, 0.6],
colors: [
Color(0xff7500bf),
Color(0xff5b1ad1),
],
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Text(list[index]["Job Title"],
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w500,
color: Color(0xfffefeff))),
),
Container(
margin: EdgeInsets.only(top: 10.0),
child: Opacity(
opacity: 0.6,
child: Text(list[index]["Job Title"],
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.w600,
color: Color(0xffffffff))),
),
),
Container(
margin: EdgeInsets.only(top: 10.0),
child: Opacity(
opacity: 0.49,
child: Text(list[index]["Job Title"],
style: TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w600,
color: Color(0xffffffff))),
),
),
Container(
margin: EdgeInsets.only(top: 60.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
GestureDetector(
onTap: () {},
child: Container(
padding: EdgeInsets.only(
top: 12.0,
left: 15.0,
right: 15.0,
bottom: 12.0),
decoration: BoxDecoration(
color: new Color.fromRGBO(
255, 255, 255, 0.5),
borderRadius: BorderRadius.all(
Radius.circular(12.0))),
child: Opacity(
opacity: 0.7,
child: Text('APPLY',
style: TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w600,
color: Color(0xfffefeff))),
),
),
)
],
),
)
],
),
)
],
));
});
}
return CircularProgressIndicator();
},
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Job')),
body: randomjobs(),
);
}
}
This is the total page code. it prints in the vertical direction whereas i need it in horizontal.Even though I am using scroll direction horizontal I am not able to make it happen.Can you help. scrollDirection: Axis.horizontal I have used this in my code but the result is still I am not able to get horizontal scroll below my app bar.
Thank you

Is this what your trying?
body: ListView.builder(
shrinkWrap: true,
//add item count depending on your list
//itemCount: list.length,
itemCount: 4,
//added scrolldirection
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index) {
//Removed your pageview
return Container(
height: 240.0,
margin: EdgeInsets.only(left: 8, right: 8, top: 20),
padding: EdgeInsets.only(top: 20.0, left: 20.0, right: 20.0),
// rest of your code

Related

Why I'm not able to get the updated variable even using setstate inside the stateful widget. As I want to update my Container on new TabBar option

Basically I want to change content on selecting the TabBar options. Here's my code. Also I'm new to flutter. I've also created a _incrementCounter() and getter setter methods. By using _incrementCounter() I'm returning an integer in order to update the PAgeView of my screen which is implemented inside a List called tabsCat. But on calling the _incrementCounter() method on line 264 it does not give the updated value please guide.
import 'dart:ui';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:fluttertravelapp/models/beach_model.dart';
import 'package:fluttertravelapp/models/new_category_model.dart';
import 'package:fluttertravelapp/models/popular_model.dart';
import 'package:fluttertravelapp/models/recommended_model.dart';
import 'package:fluttertravelapp/screens/selected_category_screen.dart';
import 'package:fluttertravelapp/screens/selected_place_screen.dart';
import 'package:fluttertravelapp/widgets/bottom_navigation_bar.dart';
import 'package:fluttertravelapp/widgets/custom_tab_indicator.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
class HomeScreen extends StatefulWidget {
#override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
int count = 0;
// Creating the getter method
// to get input from Field/Property
int get getCount {
return count;
}
// Creating the setter method
// to set the input in Field/Property
set setCount(int newCount) {
count = newCount;
}
int _incrementCounter() {
int index = 0;
setState(() {
index = getCount;
print(index);
});
return index;
}
/// Page Controller
final _pageController = PageController(viewportFraction: 0.877);
#override
Widget build(BuildContext context) {
int tabIndex = 0;
List tabsCat = [
PageView(
physics: BouncingScrollPhysics(),
controller: _pageController,
scrollDirection: Axis.horizontal,
children: List.generate(
recommendations.length,
(int index) => GestureDetector(
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => SelectedCategoryScreen(
newCategoryModel: newCategories[index])));
},
child: Container(
margin: EdgeInsets.only(right: 28.8),
width: 333.6,
height: 218.4,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(9.6),
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(newCategories[index].image),
),
),
child: Stack(
children: <Widget>[
Positioned(
bottom: 19.2,
left: 19.2,
child: ClipRRect(
borderRadius: BorderRadius.circular(4.8),
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaY: 19.2, sigmaX: 19.2),
child: Container(
height: 36,
padding: EdgeInsets.only(
left: 16.72, right: 14.4),
alignment: Alignment.centerLeft,
child: Row(
children: <Widget>[
SvgPicture.asset(
'assets/svg/icon_location.svg'),
SizedBox(
width: 9.52,
),
Text(
recommendations[index].name,
style: GoogleFonts.lato(
fontWeight: FontWeight.w700,
color: Colors.white,
fontSize: 16.8),
)
],
),
),
),
),
)
],
),
),
),
),
),
PageView(
physics: BouncingScrollPhysics(),
controller: _pageController,
scrollDirection: Axis.horizontal,
children: List.generate(
recommendations.length,
(int index) => GestureDetector(
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => SelectedCategoryScreen(
newCategoryModel: newCategories[index])));
},
child: Container(
margin: EdgeInsets.only(right: 28.8),
width: 333.6,
height: 218.4,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(9.6),
image: DecorationImage(
fit: BoxFit.cover,
image: CachedNetworkImageProvider(recommendations[index].image),
),
),
child: Stack(
children: <Widget>[
Positioned(
bottom: 19.2,
left: 19.2,
child: ClipRRect(
borderRadius: BorderRadius.circular(4.8),
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaY: 19.2, sigmaX: 19.2),
child: Container(
height: 36,
padding: EdgeInsets.only(
left: 16.72, right: 14.4),
alignment: Alignment.centerLeft,
child: Row(
children: <Widget>[
SvgPicture.asset(
'assets/svg/icon_location.svg'),
SizedBox(
width: 9.52,
),
Text(
recommendations[index].name,
style: GoogleFonts.lato(
fontWeight: FontWeight.w700,
color: Colors.white,
fontSize: 16.8),
)
],
),
),
),
),
)
],
),
),
),
),
),
];
return Scaffold(
//bottomNavigationBar: BottomNavigationBarTravel(),
body: SafeArea(
child: Container(
child: ListView(
physics: BouncingScrollPhysics(),
children: <Widget>[
/// Custom Navigation Drawer and Search Button
Container(
height: 57.6,
margin: EdgeInsets.only(top: 28.8, left: 28.8, right: 28.8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
],
),
),
/// Text Widget for Title
Padding(
padding: EdgeInsets.only(top: 0, left: 28.8),
child: Text(
'Explore\nPakistan',
style: GoogleFonts.playfairDisplay(
fontSize: 45.6, fontWeight: FontWeight.w700),
),
),
/// Custom Tab bar with Custom Indicator
Column(
children:
[DefaultTabController(
length: 4,
child: TabBar(
labelPadding: EdgeInsets.only(left: 14.4, right: 14.4),
indicatorPadding:
EdgeInsets.only(left: 14.4, right: 14.4),
isScrollable: true,
labelColor: Color(0xFF000000),
unselectedLabelColor: Color(0xFF8a8a8a),
labelStyle: GoogleFonts.lato(
fontSize: 14, fontWeight: FontWeight.w700),
unselectedLabelStyle: GoogleFonts.lato(
fontSize: 14, fontWeight: FontWeight.w700),
indicator: RoundedRectangleTabIndicator(
color: Color(0xFF000000), weight: 2.4, width: 14.4),
onTap: (index){
setCount = index;
//print(getCount);
},
tabs: [
Tab(
child: Container(
child: Text('Recommended'),
),
),
Tab(
child: Container(
child: Text('Popular'),
),
),
Tab(
child: Container(
child: Text('New Destination'),
),
),
Tab(
child: Container(
child: Text('Hidden Gems'),
),
)
]),
),
/// ListView widget with PageView
/// Recommendations Section
Container(
height: 218.4,
margin: EdgeInsets.only(top: 16),
child: tabsCat[_incrementCounter()],
),
]),
/// Dots Indicator
/// Using SmoothPageIndicator Library
Padding(
padding: EdgeInsets.only(left: 28.8, top: 28.8),
child: SmoothPageIndicator(
controller: _pageController,
count: recommendations.length,
effect: ExpandingDotsEffect(
activeDotColor: Color(0xFF8a8a8a),
dotColor: Color(0xFFababab),
dotHeight: 4.8,
dotWidth: 6,
spacing: 4.8),
),
),
/// Text Widget for Popular Categories
Padding(
padding: EdgeInsets.only(top: 48, left: 28.8, right: 28.8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width*0.4,
child: FittedBox(
child: Text(
'Popular Categories',
style: GoogleFonts.playfairDisplay(
fontWeight: FontWeight.w700,
color: Color(0xFF000000),
),
),
),
),
Container(width: MediaQuery.of(context).size.width*0.1,
child: FittedBox(
child: Text(
'Show All ',
style: GoogleFonts.lato(
fontWeight: FontWeight.w500,
color: Color(0xFF8a8a8a),
),
),
),
)
],
),
),
/// ListView for Popular Categories Section
Container(
margin: EdgeInsets.only(top: 33.6),
height: 45.6,
child: ListView.builder(
itemCount: populars.length,
scrollDirection: Axis.horizontal,
physics: BouncingScrollPhysics(),
padding: EdgeInsets.only(left: 28.8, right: 9.6),
itemBuilder: (context, index) {
return Container(
margin: EdgeInsets.only(right: 19.2),
height: 45.6,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(9.6),
color: Color(populars[index].color),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
width: 19.2,
),
Image.asset(
populars[index].image,
height: 16.8,
),
SizedBox(
width: 19.2,
)
],
),
);
},
),
),
/// ListView for Beach Section
Container(
margin: EdgeInsets.only(top: 28.8, bottom: 16.8),
height: 124.8,
child: ListView.builder(
itemCount: beaches.length,
padding: EdgeInsets.only(left: 28.8, right: 12),
scrollDirection: Axis.horizontal,
physics: BouncingScrollPhysics(),
itemBuilder: (context, index) {
return Container(
height: 124.8,
width: 188.4,
margin: EdgeInsets.only(right: 16.8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(9.6),
image: DecorationImage(
fit: BoxFit.cover,
image:
CachedNetworkImageProvider(beaches[index].image),
),
),
);
},
),
)
],
),
),
),
);
}
}
Solve the error by calling the _incrementcounter method onto OnTap section. Here's my code changes:
Edited incrementcounter method and declare new method setNewCount,
void setNewCount(int newCount) {
count = newCount;
}
void _incrementCounter() {
setState(() {
count = getCount;
});
}
2nd change :
onTap: (index){
setNewCount(index);
_incrementCounter();
},
3rd change:
Container(
height: 218.4,
margin: EdgeInsets.only(top: 16),
child: tabsCat[count],
),
Try
onTap: (index){
setCount(index);
//print(getCount);
},
instead of
onTap: (index){
setCount = index;
//print(getCount);
},

Flutter - RangeError (index)

I am getting "RangeError (index): Invalid value: Not in inclusive range 0..4: 5" error in my flutter app.
Error
This is my code and I hope somebody is able to help me fixing the error:
import 'package:fluttertravelapp/models/beach_model.dart';
import 'package:fluttertravelapp/models/popular_model.dart';
import 'package:fluttertravelapp/screens/selected_place_screen.dart';
import 'package:fluttertravelapp/widgets/bottom_navigation_bar.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:fluttertravelapp/models/recommended_model.dart';
import 'package:fluttertravelapp/widgets/custom_tab_indicator.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:cached_network_image/cached_network_image.dart';
class HomeScreen extends StatefulWidget {
#override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
// Page Controller
final _pageController = PageController(viewportFraction: 0.877);
#override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomNavigationBarTravel(),
body: SafeArea(
child: Container(
child: ListView(
physics: BouncingScrollPhysics(),
// Custom Navigation Drawer and Search Button
children: [
Container(
height: 57.6,
margin: EdgeInsets.only(top: 28.8, left: 28.8, right: 28.8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: 57.6,
width: 57.6,
padding: EdgeInsets.all(18),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(9.6),
color: Color(0x080a0928),
),
child: SvgPicture.asset('assets/svg/icon_drawer.svg'),
),
Container(
height: 57.6,
width: 57.6,
padding: EdgeInsets.all(18),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(9.6),
color: Color(0x080a0928),
),
child: SvgPicture.asset('assets/svg/icon_search.svg'),
),
],
),
),
// Text Widget for Title
Padding(
padding: EdgeInsets.only(top: 48, left: 28.8),
child: Text('Explore\nthe Nature', style: GoogleFonts.playfairDisplay(
fontSize: 45.6,
fontWeight: FontWeight.w700,
),),
),
//Custom Tab bar with Custom Indicator
Container(
height: 30,
margin: EdgeInsets.only(left: 14.4, top: 28.8),
child: DefaultTabController(
length: 4,
child: TabBar(labelPadding: EdgeInsets.only(left: 14.4, right: 14.4),
indicatorPadding: EdgeInsets.only(left: 14.4, right: 14.4),
isScrollable: true,
labelColor: Color(0xFF000000),
unselectedLabelColor: Color(0xFF8a8a8a),
labelStyle: GoogleFonts.lato(
fontSize: 14,
fontWeight: FontWeight.w700,
),
unselectedLabelStyle: GoogleFonts.lato(
fontSize: 14,
fontWeight: FontWeight.w700,
),
indicator: RoundedRectangleTabIndicator(
color: Color(0xFF000000), weight: 2.4, width: 14.4
),
tabs: [
Tab(
child: Container(
child: Text('Recommended'),
),
),
Tab(
child: Container(
child: Text('Popular'),
),
),
Tab(
child: Container(
child: Text('New Destination'),
),
),
Tab(
child: Container(
child: Text('Hidden Gems'),
),
),
],),),
),
//ListView Widget with PageView
//Recommendations section
Container(
height: 218.4,
margin: EdgeInsets.only(top: 16,),
child: PageView(
physics: BouncingScrollPhysics(),
controller: _pageController,
scrollDirection: Axis.horizontal,
children: List.generate(
recommendations.length,
(int index) => GestureDetector(
onTap: (){
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => SelectedPlaceScreen(
recommendedModel: recommendations[index])));
},
child: Container(
margin: EdgeInsets.only(right: 28.8),
width: 333.6,
height: 218.4,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(9.6),
image: DecorationImage(
fit: BoxFit.cover,
image: CachedNetworkImageProvider(recommendations[index].image),
),
),
child: Stack(
children: [
Positioned(
bottom: 19.2,
left: 19.2,
child: ClipRRect(
borderRadius: BorderRadius.circular(4.8),
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaY: 19.2, sigmaX: 19.2),
child: Container(
height: 36,
padding: EdgeInsets.only(
left: 16.72, right: 14.4),
alignment: Alignment.centerLeft,
child: Row(
children: [
SvgPicture.asset('assets/svg/icon_location.svg'),
SizedBox(width: 9.52,),
Text(recommendations[index].name,
style: GoogleFonts.lato(
fontWeight: FontWeight.w700,
color: Colors.white,
fontSize: 16.8,),
),
],
),
),
),
),
)
],
),
),
)),
),
),
//Dots Indicator
//Using SmoothPageIndicator Library
Padding(padding: EdgeInsets.only(left: 28.8, top: 28.8),
child: SmoothPageIndicator(
controller: _pageController,
count: recommendations.length,
effect: ExpandingDotsEffect(
activeDotColor: Color(0xFF8a8a8a),
dotColor: Color(0xFFabababab),
dotHeight: 4.8,
dotWidth: 6,
spacing: 4.8,
),
),
),
//Text Widget for Popular Categories
Padding(
padding: EdgeInsets.only(top: 48, left: 28.8, right: 28.8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'Popular Categories',
style: GoogleFonts.playfairDisplay(
fontSize: 28,
fontWeight: FontWeight.w700,
color: Color(0xFF000000),
),
),
Text(
'Show All',
style: GoogleFonts.lato(
fontSize: 16.8,
fontWeight: FontWeight.w500,
color: Color(0xFF8a8a8a),
),
),
],
),
),
//ListView for Popular Categories Section
Container(
margin: EdgeInsets.only(top: 33.6,),
height: 45.6,
child: ListView.builder(
itemCount: populars.length,
scrollDirection: Axis.horizontal,
physics: BouncingScrollPhysics(),
padding: EdgeInsets.only(left: 28.8, right: 9.6),
itemBuilder: (context, index){
return Container(
margin: EdgeInsets.only(right: 19.2),
height: 45.6,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(9.6),
color: Color(populars[index].color),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(width: 19.2,),
Image.asset(populars[index].image,height: 16.8,),
SizedBox(width: 19.2,),
],
),
);
},
),
),
//ListView for Beach Section
Container(
margin: EdgeInsets.only(top: 28.8, bottom: 16.8),
height: 124.8,
child: ListView.builder(
itemCount: beaches.length,
padding: EdgeInsets.only(left: 28.8, right: 12),
scrollDirection: Axis.horizontal,
physics: BouncingScrollPhysics(),
itemBuilder: (context, index){
return Container(
height: 124,
width: 188.4,
margin: EdgeInsets.only(right: 16.8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(9.6),
image: DecorationImage(
fit: BoxFit.cover,
image: CachedNetworkImageProvider(beaches[index].image),
)
),
);
},
),
)
],
),
),
),
);
}
}
If you want the full code you can see the code from https://github.com/abdulazizahwan/flutter_travel_app
I tried the same code.

Flutter cannot fix the overflowed issue of a component

This the issue I have, but I want to keep the text
I dont want to change the layout of the widget, I need to know is the a way to change the height of the widget
widget class that have the issue
class CategoryView extends StatelessWidget {
const CategoryView(
{Key key,
this.category,
this.animationController,
this.animation,
this.callback})
: super(key: key);
final void Function(int id) callback;
final Category category;
final AnimationController animationController;
final Animation<dynamic> animation;
#override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: animationController,
builder: (BuildContext context, Widget child) {
return FadeTransition(
opacity: animation,
child: Transform(
transform: Matrix4.translationValues(
0.0, 50 * (1.0 - animation.value), 0.0),
child: InkWell(
splashColor: Colors.transparent,
onTap: () {
callback(category.id);
},
child: SizedBox(
child: Stack(
alignment: AlignmentDirectional.bottomCenter,
children: <Widget>[
Container(
child: Column(
children: <Widget>[
Expanded(
child: Container(
decoration: BoxDecoration(
color: HexColor('#f7f7f7'),
borderRadius: const BorderRadius.all(
Radius.circular(16.0)),
// border: new Border.all(
// color: BlogSiteAppTheme.notWhite),
),
child: Column(
children: <Widget>[
Expanded(
child: Container(
height: 280,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
top: 16, left: 16, right: 16),
child: Text(
category.title,
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 16,
letterSpacing: 0.27,
color:
BlogSiteAppTheme.darkerText,
),
),
),
Padding(
padding: const EdgeInsets.only(
top: 8,
left: 16,
right: 16,
bottom: 4),
child: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
crossAxisAlignment:
CrossAxisAlignment.center,
children: <Widget>[
Text(
'${category.date.substring(0, 10)}',
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w200,
fontSize: 12,
letterSpacing: 0.27,
color:
BlogSiteAppTheme.grey,
),
),
Container(
child: Row(
children: <Widget>[
Text(
'${category.excelentCount}',
textAlign:
TextAlign.left,
style: TextStyle(
fontWeight:
FontWeight.w200,
fontSize: 18,
letterSpacing: 0.27,
color:
BlogSiteAppTheme
.grey,
),
),
Icon(
Icons.star,
color: BlogSiteAppTheme
.brightBlue,
size: 20,
),
],
),
)
],
),
),
Padding(
padding: const EdgeInsets.only(
top: 8,
left: 16,
right: 16,
bottom: 10),
child: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
crossAxisAlignment:
CrossAxisAlignment.center,
children: <Widget>[
Text(
'${category.addedBy}',
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18,
letterSpacing: 0.27,
color: BlogSiteAppTheme
.nearlyBlue,
),
),
Container(
child: Row(
children: <Widget>[
Text(
'${category.goodCount}',
textAlign:
TextAlign.left,
style: TextStyle(
fontWeight:
FontWeight.w200,
fontSize: 18,
letterSpacing: 0.27,
color:
BlogSiteAppTheme
.grey,
),
),
Icon(
Icons.star,
color: BlogSiteAppTheme
.nearlyBlue,
size: 20,
),
],
),
)
],
),
),
],
),
),
),
const SizedBox(
width: 48,
),
],
),
),
),
const SizedBox(
height: 48,
),
],
),
),
Container(
child: Padding(
padding:
const EdgeInsets.only(top: 24, right: 16, left: 16),
child: Container(
decoration: BoxDecoration(
borderRadius:
const BorderRadius.all(Radius.circular(16.0)),
boxShadow: <BoxShadow>[
BoxShadow(
color: BlogSiteAppTheme.grey.withOpacity(0.2),
offset: const Offset(0.0, 0.0),
blurRadius: 6.0),
],
),
child: ClipRRect(
borderRadius:
const BorderRadius.all(Radius.circular(16.0)),
child: AspectRatio(
aspectRatio: 1.28,
child: Image.asset(category.imagePath)),
),
),
),
),
],
),
),
),
),
);
},
);
}
}
Featured blog posts Container part
Padding(
padding: const EdgeInsets.only(top: 8),
child: FutureBuilder<bool>(
future: getData(),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
if (!snapshot.hasData) {
return const SizedBox();
} else {
return GridView(
padding: const EdgeInsets.all(8),
physics: const BouncingScrollPhysics(),
scrollDirection: Axis.vertical,
children: List<Widget>.generate(
posts.length,
(int index) {
final int count = posts.length;
final Animation<double> animation =
Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: animationController,
curve: Interval((1 / count) * index, 1.0,
curve: Curves.fastOutSlowIn),
),
);
animationController.forward();
return CategoryView(
callback: (int id) {
widget.callBack(id);
},
category: posts[index],
animation: animation,
animationController: animationController,
);
},
),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 32.0,
crossAxisSpacing: 32.0,
childAspectRatio: 0.8,
),
);
}
},
),
);
Does anyone have a way to fixed this.
I need to keep the text as it gets, so I need a way to expand the widget when it need to expand
GridView must have a childAspectRatio property, try to play around with that and see if you have the wanted result
try wrapping your stack with Expanded with flex:1

how to add fixed container above x number of scrollable card

I am trying to add a fixed buildHelpCard(context, alldata) above the scrollable list but whenever I try to add the buildHelpCard the list got disappeared and only the buildHelpCard is showing ... can you guys please suggest me how to fix this issues
**here is my code**
```
import 'package:flutter/material.dart';
import '../colors/constants.dart';
import 'package:get/get.dart';
import 'package:flutter_svg/flutter_svg.dart';
class duesDetails extends StatefulWidget {
var data;
var count;
duesDetails(this.data, this.count);
#override
_duesDetailsState createState() => _duesDetailsState();
}
class _duesDetailsState extends State<duesDetails> {
#override
Widget build(BuildContext context) {
var alldata = widget.data; // added all value to data for easy access
int count = widget.count;
return Scaffold(
appBar: buildAppBar(alldata),
body: Container(
decoration: BoxDecoration(
color: kPrimaryColor.withOpacity(0.03),
),
child: Center(
child: ListView.builder(
itemBuilder: (BuildContext context, int index) {
return Card(
child: Padding(
padding: const EdgeInsets.only(
top: 22, bottom: 22, left: 16, right: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
InkWell(
onTap: () {},
child: Text(
'${alldata[count]['pay list'][index]['discription']}',
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 22),
),
),
Text(
'Capital',
style: TextStyle(color: Colors.grey.shade500),
),
],
),
Container(
height: 30,
width: 50,
child: Image.asset('assets/facebook.png'),
)
],
),
),
);
},
itemCount: alldata[count]['pay count'] == null ? 0 : alldata[count]['pay count'],
),
),
),
);
}
AppBar buildAppBar(var data) {
return AppBar(
backgroundColor: kPrimaryColor.withOpacity(.05),
elevation: 0,
//title: Obx(() => Text('Randas ', style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold),),),
title: Text("${data[0]['name']} Pay Details", style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold),),
iconTheme: IconThemeData(
color: kPrimaryColor,
size: 28.0,
),
);
}
Container buildHelpCard(BuildContext context, var data) {
return Container(
height: 150,
width: double.infinity,
child: Stack(
alignment: Alignment.bottomLeft,
children: <Widget>[
Container(
padding: EdgeInsets.only(
// left side padding is 40% of total width
left: MediaQuery.of(context).size.width * .4,
top: 20,
right: 20,
),
height: 130,
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xFF60BE93),
Color(0xFF1B8D59),
],
),
borderRadius: BorderRadius.circular(20),
),
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: "${data[5]["title"]}\n",
style: Theme.of(context)
.textTheme
.headline6
.copyWith(color: Colors.white),
),
TextSpan(
text: "${data[5]["dis"]}",
style: TextStyle(
color: Colors.white.withOpacity(0.7),
),
),
],
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 210.0, 20.0),
child: SvgPicture.asset("assets/svg/friends.svg"),
),
],
),
);
}
}
```
NOTE - I want to add buildHelpCard(context, alldata) function above the start of the card list... but when I try to do this the list got disappeared
Try this
child: Column(
children: [
buildHelpCard()
Expanded(child:
ListView.builder(
itemBuilder: (BuildContext context, int index) {
return Card(
child: Padding(
padding: const EdgeInsets.only(
top: 22, bottom: 22, left: 16, right: 16),
child:........

How to set container width inside Expanded ListView

I am unable to set width for the Container when I wrap ListView inside Expanded widget.
Widget build(BuildContext context) {
return Center(
child: Column(
children: [
Padding(
padding: EdgeInsets.only(top: 30, bottom: 30),
child: Text(
'Transactions History',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 25,
),
),
),
Expanded(
child: ListView.builder(
physics: BouncingScrollPhysics(),
itemCount: 30,
itemBuilder: (BuildContext context, int index) {
return Container(
width: 100,
color: Colors.red,
child: Card(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 15),
),
),
);
},
),
),
],
),
);
}
You need to add the Container of your listItem in the itemBuilder inside an Align widget.
So your code in the itemBuilder will look like this:
return Align(
alignment: Alignment.centerLeft,
child: Container(
width: 100,
color: Colors.red,
child: Card(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 25,
vertical: 15,
),
),
),
),
);