Related
This is what the debug console suggests:
The overflowing RenderFlex has an orientation of Axis.vertical.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be
seen. If the content is legitimately bigger than the available space, consider clipping it with a
ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
like a ListView.
The specific RenderFlex in question is: RenderFlex#33d4b relayoutBoundary=up2 OVERFLOWING:
needs compositing
creator: Column ← MediaQuery ← Padding ← SafeArea ← Stack ← LayoutBuilder ← SizedBox ← Center ←
KeyedSubtree-[GlobalKey#bf933] ← _BodyBuilder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← ⋯
parentData: offset=Offset(0.0, 0.0) (can use size)
constraints: BoxConstraints(0.0<=w<=500.0, 0.0<=h<=237.0)
size: Size(500.0, 237.0)
direction: vertical
This is my code:
class ToDoPage extends StatefulWidget {
const ToDoPage({Key? key}) : super(key: key);
#override
State<ToDoPage> createState() => _ToDoPageState();
}
class _ToDoPageState extends State<ToDoPage> {
bool isActive = false;
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xffFAFAFA),
body: Center(
child: SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: LayoutBuilder(
builder: (context, constraints) => Stack(
children: [
SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Image.asset(
"assets/mountain.jpg",
fit: BoxFit.cover,
),
),
SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(
height: 20.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Padding(
padding: EdgeInsets.fromLTRB(23, 8, 23, 8),
child: Align(
alignment: Alignment.topLeft,
child: Text(
'My success list',
style: GoogleFonts.nunito(
color: Colors.white,
fontSize: 30.0,
fontWeight: FontWeight.w500,
),
),
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(23, 8, 23, 8),
child: Tooltip(
message: 'List options menu',
child: Semantics(
label: 'My success list options menu',
enabled: true,
readOnly: true,
child: IconButton(
icon: const Icon(
Icons.more_vert_outlined,
color: Colors.white,
size: 25,
semanticLabel:
'Pomodoro timer list options menu',
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
Text('list options menu')),
);
},
),
),
),
),
],
),
Padding(
padding: EdgeInsets.fromLTRB(23, 8, 23, 8),
child: Align(
alignment: Alignment.topLeft,
child: Text(
'Thusrday, December 29, 2022',
style: GoogleFonts.nunito(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.w500,
),
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(23, 8, 23, 8),
child: Align(
alignment: Alignment.center,
child: Glassmorphism(
blur: 5,
opacity: 0.2,
radius: 15,
child: Container(
height: 100,
padding: const EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
'task 1',
style: GoogleFonts.nunito(
color: Colors.white,
fontSize: 24.0,
fontWeight: FontWeight.bold,
),
),
SmileFaceCheckbox(
isActive: isActive,
onPress: () {
setState(() {
isActive = !isActive;
});
}),
],
),
Align(
alignment: Alignment.topLeft,
child: Text(
'Explain note',
textAlign: TextAlign.center,
style: GoogleFonts.nunito(
color: Colors.white.withOpacity(0.8),
fontSize: 16.0,
),
),
),
],
),
),
),
),
),
//hiint
Expanded(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.symmetric(
vertical: 10.0, horizontal: 15.0),
child: Glassmorphism(
blur: 20,
opacity: 0.1,
radius: 15.0,
child: TextButton(
onPressed: () {
// handle push to HomeScreen
},
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 10.0,
horizontal: 15.0,
),
child: Text(
'+ Add successful task',
style: GoogleFonts.nunito(
color: Colors.white,
fontSize: 20.0,
),
),
),
),
),
),
],
),
),
),
),
],
),
),
],
),
),
),
),
);
}
}
I tried this but still got the error:
SafeArea(
child: Expanded(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(
height: 20.0,
),
And this on each text widget
child: Flexible(
child: Text(
'My success list',
style: GoogleFonts.nunito(
color: Colors.white,
fontSize: 30.0,
fontWeight: FontWeight.w500,
),
),
),
Update:
Glassmorphism.dart
import 'dart:ui';
import 'package:flutter/material.dart';
class Glassmorphism extends StatelessWidget {
final double blur;
final double opacity;
final double radius;
final Widget child;
const Glassmorphism({
Key? key,
required this.blur,
required this.opacity,
required this.radius,
required this.child,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(radius),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: blur, sigmaY: blur),
child: Container(
decoration: BoxDecoration(
color: Colors.white.withOpacity(opacity),
borderRadius: BorderRadius.all(Radius.circular(radius)),
border: Border.all(
width: 1.5,
color: Colors.white.withOpacity(0.2),
),
),
child: child,
),
),
);
}
}
Smileyface.dart
import 'package:flutter/material.dart';
class SmileFaceCheckbox extends StatefulWidget {
final double height;
final bool isActive;
final VoidCallback onPress;
final Color activeColor;
final Color deactiveColor;
const SmileFaceCheckbox({
Key? key,
this.height = 24.0,
required this.isActive,
required this.onPress,
}) : activeColor = const Color.fromARGB(255, 116, 217, 48),
deactiveColor = const Color(0xffD94530),
super(key: key);
#override
State<SmileFaceCheckbox> createState() => _SmileFaceCheckboxState();
}
class _SmileFaceCheckboxState extends State<SmileFaceCheckbox>
with SingleTickerProviderStateMixin {
late AnimationController _animationController;
late Animation<double> _animationValue;
void setupAnimation() {
_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 300),
);
_animationValue = CurvedAnimation(
parent: _animationController,
curve: const Interval(0.0, 1.0),
);
}
#override
void initState() {
setupAnimation();
super.initState();
}
#override
void dispose() {
_animationController.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
final height = widget.height;
final width = height * 2;
final largeRadius = (height * 0.9) / 2;
final smallRadius = (height * 0.2) / 2;
return GestureDetector(
onTap: widget.onPress,
child: AnimatedBuilder(
animation: _animationController,
builder: (context, _) {
if (widget.isActive) {
_animationController.forward();
} else {
_animationController.reverse();
}
return Container(
height: height,
width: width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(80.0),
color:
widget.isActive ? widget.activeColor : widget.deactiveColor,
),
child: Stack(
alignment: Alignment.center,
children: [
Transform.translate(
offset: Offset(
-largeRadius + largeRadius * 2 * _animationValue.value,
0), // add animation move from -largeRadius to largeRadius
child: Container(
width: largeRadius * 2,
height: largeRadius * 2,
decoration: const BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
child: Stack(
alignment: Alignment.center,
children: [
Transform.translate(
offset: Offset(0, -smallRadius),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
width: smallRadius * 2,
height: smallRadius * 2,
decoration: BoxDecoration(
color: widget.isActive
? widget.activeColor
: widget.deactiveColor,
shape: BoxShape.circle,
),
),
Container(
width: smallRadius * 2,
height: smallRadius * 2,
decoration: BoxDecoration(
color: widget.isActive
? widget.activeColor
: widget.deactiveColor,
shape: BoxShape.circle,
),
),
],
),
),
Transform.translate(
offset: Offset(0, smallRadius * 2),
child: Container(
width: smallRadius * 4,
height:
widget.isActive ? smallRadius * 2 : smallRadius,
decoration: BoxDecoration(
color: widget.isActive
? widget.activeColor
: widget.deactiveColor,
borderRadius: !widget.isActive
? BorderRadius.circular(22.0)
: const BorderRadius.only(
bottomLeft: Radius.circular(40.0),
bottomRight: Radius.circular(40.0),
),
),
),
),
],
),
),
),
],
),
);
},
),
);
}
}
How can I solve this issue?
Thanks for any help you can provide
I think you can use bottomNavigationBar for adding that item. and use Column[HeaderWidget,Expanded(ListViwe)] or just body:ListView on Scaffold body .
You can play with decoration, It depends on your ux how you like to handle scroll event, you may like SliverAppBar on CustomScrolView
class _ToDoPageState extends State<ToDoPage> {
bool isActive = false;
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: Color.fromARGB(255, 42, 36, 36),
// floatingActionButton: newTaskButton(),
bottomNavigationBar: newTaskButton(),
body: LayoutBuilder(
builder: (context, constraints) => Stack(
children: [
SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
// child: Image.asset(
// "assets/mountain.jpg",
// fit: BoxFit.cover,
// ),
),
SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(
height: 20.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Padding(
padding: EdgeInsets.fromLTRB(23, 8, 23, 8),
child: Align(
alignment: Alignment.topLeft,
child: Text(
'My success list',
style: GoogleFonts.nunito(
color: Colors.white,
fontSize: 30.0,
fontWeight: FontWeight.w500,
),
),
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(23, 8, 23, 8),
child: Tooltip(
message: 'List options menu',
child: Semantics(
label: 'My success list options menu',
enabled: true,
readOnly: true,
child: IconButton(
icon: const Icon(
Icons.more_vert_outlined,
color: Colors.white,
size: 25,
semanticLabel:
'Pomodoro timer list options menu',
),
onPressed: () {},
),
),
),
),
],
),
Padding(
padding: EdgeInsets.fromLTRB(23, 8, 23, 8),
child: Align(
alignment: Alignment.topLeft,
child: Text(
'Thusrday, December 29, 2022',
style: GoogleFonts.nunito(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.w500,
),
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(23, 8, 23, 8),
child: Align(
alignment: Alignment.center,
child: Glassmorphism(
blur: 5,
opacity: 0.2,
radius: 15,
child: Container(
height: 100,
padding: const EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
'task 1',
style: GoogleFonts.nunito(
color: Colors.white,
fontSize: 24.0,
fontWeight: FontWeight.bold,
),
),
SmileFaceCheckbox(
isActive: isActive,
onPress: () {
setState(() {
isActive = !isActive;
});
}),
],
),
Align(
alignment: Alignment.topLeft,
child: Text(
'Explain note',
textAlign: TextAlign.center,
style: GoogleFonts.nunito(
color: Colors.white.withOpacity(0.8),
fontSize: 16.0,
),
),
),
],
),
),
),
),
),
//hiint
// SizedBox(
// height: constraints.maxHeight * .4, // your height
// ),
// Align(
// alignment: FractionalOffset.bottomCenter,
// child: newTaskButton(),
// ),
],
),
),
],
),
),
),
);
}
Column newTaskButton() {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 15.0),
child: Glassmorphism(
blur: 20,
opacity: 0.1,
radius: 15.0,
child: TextButton(
onPressed: () {
// handle push to HomeScreen
},
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 10.0,
horizontal: 15.0,
),
child: Text(
'+ Add successful task',
style: GoogleFonts.nunito(
color: Colors.white,
fontSize: 20.0,
),
),
),
),
),
),
],
);
}
}
I am using positioned.fill top value to adjust my text along with image. I am using mediaQuery for responsiveness. When I adjust it on larger mobile screen, then it cause same issue on smaller screen.
This is my stack code:
Stack(children: <Widget>[
GestureDetector(
onTap: (() => Navigator.of(context).push(
Transitions(
transitionType: TransitionType.fade,
curve: Curves.bounceInOut,
duration: const Duration(milliseconds: 500),
reverseCurve: Curves.bounceOut,
widget: detailinvest(title)),
)),
child: Container(
// height: 260,
height: MediaQuery.of(context).size.height / 3,
padding: const EdgeInsets.all(8),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Image.network(
"https://arzenafees.com/wp-content/uploads/2021/06/Invest_Rudn_Enclave.jpg",
fit: BoxFit.cover,
)),
),
),
Positioned.fill(
// top: 255,
top: MediaQuery.of(context).size.width * 0.5,
child: Align(
alignment: Alignment.bottomCenter,
child: ListTile(
title: Text(
'Rudn Enclave',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
fontFamily: 'Roboto'),
),
subtitle: Row(
children: [
Icon(
Icons.location_on,
color: Constants.colorMain,
),
Expanded(
child: Text(
'Adiala Road, Rawalpindi, Rawalpindi Cantonment, Rawalpindi District, Punjab, 46600, Pakistan',
style: TextStyle(
fontSize: MediaQuery.of(context).size.width / 45,
),
),
),
],
),
)),
),
]),
Screenshot:
Note: This UI was working good on smaller screen
Edit: My GridView code:
body: GridView.count(
primary: false,
padding: const EdgeInsets.all(8),
crossAxisSpacing: 12,
mainAxisSpacing: 22,
crossAxisCount: 2,
childAspectRatio: 0.6,
children: <Widget>[
GridView.count(
primary: false,
padding: const EdgeInsets.all(8),
crossAxisSpacing: 10,
mainAxisSpacing: 20,
crossAxisCount: 2,
childAspectRatio: 0.5,
children: <Widget> [
Column(
children: <Widget>[
GestureDetector(
onTap: (() => Navigator.of(context).push(
Transitions(
transitionType: TransitionType.fade,
curve: Curves.bounceInOut,
duration: const Duration(milliseconds: 500),
reverseCurve: Curves.bounceOut,
widget: detailinvest(title)),
)),
child: Container(
height: MediaQuery.of(context).size.height / 3,
padding: const EdgeInsets.all(8),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Image.network(
"https://arzenafees.com/wp-content/uploads/2021/06/Invest_Rudn_Enclave.jpg",
fit: BoxFit.cover,
)
),
),
),
ListTile(
title: Text(
'Rudn Enclave',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
fontFamily: 'Roboto',
color: Colors.black
),
),
subtitle: Row(
children: [
Icon(Icons.location_on, color: Colors.red,),
Expanded(
child: Text(
'Adiala Road, Rawalpindi, Rawalpindi Cantonment, Rawalpindi District, Punjab, 46600, Pakistan',
style: TextStyle(
color: Colors.black,
fontSize: MediaQuery.of(context).size.width / 45,
),
),
),
],
),
),
]
),
]
),
This one working Fine :
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:page_view_builder_demo/configration/size_config.dart';
class TextFieldExample extends StatefulWidget {
const TextFieldExample({Key? key}) : super(key: key);
#override
State<TextFieldExample> createState() => _TextFieldExampleState();
}
class _TextFieldExampleState extends State<TextFieldExample> {
Widget build(BuildContext context) {
SizeConfig().init(context);
return Scaffold(
body: GridView.count(
crossAxisCount: 2,
children: [
commmanWidget(
"https://arzenafees.com/wp-content/uploads/2021/06/Invest_Rudn_Enclave.jpg"),
commmanWidget(
"https://arzenafees.com/wp-content/uploads/2021/06/Invest_Rudn_Enclave.jpg"),
],
),
);
}
Widget commmanWidget(String img) {
return Column(
children: [
Expanded(
flex: 10,
child: GestureDetector(
child: Container(
height: MediaQuery.of(context).size.height / 5,
padding: const EdgeInsets.all(8),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Image.network(
img,
fit: BoxFit.cover,
)),
),
),
),
Expanded(
flex: 3,
child: ListTile(
title: Text(
'Rudn Enclave',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
fontFamily: 'Roboto',
color: Colors.black),
),
subtitle: Row(
children: [
Icon(
Icons.location_on,
color: Colors.red,
),
Expanded(
child: Text(
'Adiala Road, Rawalpindi, Rawalpindi Cantonment, Rawalpindi District, Punjab, 46600, Pakistan',
style: TextStyle(
color: Colors.black,
fontSize: MediaQuery.of(context).size.width / 45,
),
),
),
],
),
),
),
],
);
}
}
i am tried to run my project and this error still appearing
Failed assertion: boolean expression must not be null
i was run it more than 30 times and it was worked but now it doesn't and i don't know the reason for this problem i am not change any thing in my code before the error , and i tried some solutions and it doesn't work also , so what should i do now !
this is my screen which has the problem
class _TourguideDetailesState extends State<TourguideDetailes>
with TickerProviderStateMixin {
AppProvider appProvider;
ScrollController scrollController = ScrollController(initialScrollOffset: 0);
AnimationController animationController;
#override
void initState() {
animationController = AnimationController(
duration: Duration(milliseconds: 2000), vsync: this);
animationController.forward();
super.initState();
}
#override
void dispose() {
animationController.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
appProvider = Provider.of<AppProvider>(context);
return Scaffold(
backgroundColor: AppTheme.getTheme().backgroundColor,
body: Stack(
children: <Widget>[
NestedScrollView(
controller: scrollController,
physics: NeverScrollableScrollPhysics(),
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverPersistentHeader(
pinned: true,
floating: true,
delegate: ContestTabHeader(
(MediaQuery.of(context).size.height),
appProvider.selectedTourguide,
() {
scrollController.animateTo(MediaQuery.of(context).size.height - MediaQuery.of(context).size.height / 5,
duration: Duration(milliseconds: 500), curve: Curves.fastOutSlowIn);
},
getGuideDetails(),
),
),
];
},
body: ListView(
padding: EdgeInsets.only(top: 24),
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 24, right: 24),
child: getGuideDetails(isInList: true),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: Divider(
height: 1,
),
),
Padding(
padding: const EdgeInsets.only(left: 24, right: 24),
child: Row(
children: <Widget>[
Expanded(
child: Text(
"Biography",
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18,
letterSpacing: 0.5,
),
),
),
],
),
),
Padding(
padding:
EdgeInsets.only(left: 24, right: 24, top: 4, bottom: 8),
child: Text(
appProvider.selectedTourguide.bio == null
? ""
: appProvider.selectedTourguide.bio,
style: TextStyle(
fontSize: 14,
color: AppTheme.getTheme().disabledColor,
),
)),
Padding(
padding: const EdgeInsets.only(left: 24, right: 24),
child: Row(
children: <Widget>[
Expanded(
child: Text(
"Native Language",
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18,
letterSpacing: 0.5,
),
),
),
],
),
),
Padding(
padding:
EdgeInsets.only(left: 24, right: 24, top: 4, bottom: 8),
child: Text(
appProvider.selectedTourguide.nativeLanguage == null ? "" : appProvider.selectedTourguide.nativeLanguage,
style: TextStyle(
fontSize: 14,
color: AppTheme.getTheme().disabledColor,
),
)),
Padding(
padding:
EdgeInsets.only(left: 24, right: 24, top: 4, bottom: 8),
),
SizedBox(
height: 16,
),
Padding(
padding: const EdgeInsets.only(
left: 16, right: 16, bottom: 16, top: 16),
child: Container(
height: 48,
decoration: BoxDecoration(
color: AppTheme.getTheme().primaryColor,
borderRadius: BorderRadius.all(Radius.circular(24.0)),
boxShadow: <BoxShadow>[
BoxShadow(
color: AppTheme.getTheme().dividerColor,
blurRadius: 8,
offset: Offset(4, 4),
),
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.all(Radius.circular(24.0)),
highlightColor: Colors.transparent,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BookingScreen(
index: appProvider.selectedTourguide,
),
fullscreenDialog: true,
));
},
child: Center(
child: Text(
"Book now",
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 16,
color: Colors.white),
),
),
),
),
),
),
SizedBox(
height: MediaQuery.of(context).padding.bottom,
),
],
),
),
Padding(
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
child: Container(
height: AppBar().preferredSize.height,
child: Row(
children: <Widget>[
SizedBox(
height: AppBar().preferredSize.height,
child: Padding(
padding: EdgeInsets.only(top: 8, left: 8),
child: Container(
width: AppBar().preferredSize.height - 8,
height: AppBar().preferredSize.height - 8,
decoration: BoxDecoration(color: AppTheme.getTheme().disabledColor.withOpacity(0.4), shape: BoxShape.circle),
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.all(
Radius.circular(32.0),
),
onTap: () {
if (scrollController.offset != 0.0) {
scrollController.animateTo(0.0, duration: Duration(milliseconds: 500), curve: Curves.easeInOutQuad);
} else {
Navigator.pop(context);
}
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(Icons.arrow_back, color: AppTheme.getTheme().backgroundColor),
),
),
),
),
),
),
Expanded(
child: SizedBox(),
),
],
),
),
)
],
),
);
}
Widget getGuideDetails({bool isInList = false}) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
appProvider.selectedTourguide.name,
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 22,
color: isInList == null
? AppTheme.getTheme().textTheme.body1.color
: Colors.white,
),
),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
appProvider.selectedTourguide.address,
style: TextStyle(
fontSize: 14,
color: isInList == null
? AppTheme.getTheme().disabledColor.withOpacity(0.5)
: Colors.white,
),
),
SizedBox(
width: 4,
),
Icon(
FontAwesomeIcons.mapMarkerAlt,
size: 12,
color: AppTheme.getTheme().primaryColor,
),
],
),
isInList == null
? SizedBox()
: Padding(
padding: const EdgeInsets.only(top: 4),
child: Row(
children: <Widget>[
Text(
" ${appProvider.selectedTourguide.review} Reviews",
style: TextStyle(
fontSize: 14,
color: isInList
? AppTheme.getTheme().disabledColor
: Colors.white,
),
),
],
),
),
],
),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Row(
children: <Widget>[
Text(
appProvider.selectedTourguide.tariffValue= null ? '' : appProvider.selectedTourguide.tariffValue,
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 22,
color: isInList == null
? AppTheme.getTheme().textTheme.body1.color
: Colors.white,
),
),
Text(
appProvider.selectedTourguide.currency= null ? '' : appProvider.selectedTourguide.currency,
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 22,
color: isInList == null
? AppTheme.getTheme().textTheme.body1.color
: Colors.white,
),
),
],
),
Text(
"/per hour",
style: TextStyle(
fontSize: 14,
color: isInList == null
? AppTheme.getTheme().disabledColor.withOpacity(0.5)
: Colors.white,
),
),
],
),
],
);
}
}
class ContestTabHeader extends SliverPersistentHeaderDelegate {
final Widget ui;
final VoidCallback callback;
final TourGuide tourguideData;
final double heightValue;
ContestTabHeader(
this.heightValue,
this.tourguideData,
this.callback,
this.ui,
);
#override
Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
var minValue = (shrinkOffset < heightValue - heightValue / 5? shrinkOffset: heightValue / 5);
return Container(
height: heightValue - minValue,
decoration: BoxDecoration(
color: AppTheme.getTheme().primaryColor,
boxShadow: <BoxShadow>[
BoxShadow(
color: AppTheme.getTheme().dividerColor,
blurRadius: 8,
offset: Offset(4, 4),
),
],
),
child: Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
Positioned(
bottom: 0,
left: 0,
right: 0,
top: 0,
child: Container(
width: MediaQuery.of(context).size.width,
child: Image.network(
tourguideData.photo == null
? 'https://i.ytimg.com/vi/TWaReNkjTLk/maxresdefault.jpg'
: tourguideData.photo,
fit: BoxFit.cover,
),
),
),
Positioned(
bottom: MediaQuery.of(context).padding.bottom + 16,
left: 0,
right: 0,
child: Opacity(
opacity: getOpValue(minValue, heightValue / 5),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 24, right: 24),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(24)),
child: new BackdropFilter(
filter:
new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
child: Container(
color: Colors.black12,
padding: const EdgeInsets.all(4.0),
child: Column(
children: <Widget>[
SizedBox(
height: 4,
),
Padding(
padding: const EdgeInsets.only(
left: 16, right: 16, top: 8),
child: ui,
),
Padding(
padding: const EdgeInsets.only(
left: 16, right: 16, bottom: 16, top: 16),
child: Container(
height: 48,
decoration: BoxDecoration(
color: AppTheme.getTheme().primaryColor,
borderRadius:
BorderRadius.all(Radius.circular(24.0)),
boxShadow: <BoxShadow>[
BoxShadow(
color: AppTheme.getTheme().dividerColor,
blurRadius: 8,
offset: Offset(4, 4),
),
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.all(
Radius.circular(24.0)),
highlightColor: Colors.transparent,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
BookingScreen(),
fullscreenDialog: true,
),
);
},
child: Center(
child: Text(
"Book now",
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 16,
color: Colors.white),
),
),
),
),
),
),
],
),
),
),
),
),
SizedBox(
height: 16,
),
Center(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(24)),
child: new BackdropFilter(
filter:
new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
child: Container(
color: Colors.black12,
child: Material(
color: Colors.transparent,
child: InkWell(
highlightColor: Colors.transparent,
splashColor: AppTheme.getTheme()
.primaryColor
.withOpacity(0.2),
borderRadius:
BorderRadius.all(Radius.circular(38)),
onTap: () {
try {
callback();
} catch (e) {}
},
child: Padding(
padding: const EdgeInsets.only(
left: 16, right: 16, top: 4, bottom: 4),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
'More Details',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
),
),
Padding(
padding: const EdgeInsets.only(top: 2),
child: Icon(
Icons.keyboard_arrow_down,
color: Colors.white,
size: 24,
),
)
],
),
),
),
),
),
),
),
),
],
),
),
)
],
),
);
}
double getOpValue(double minValue, double maxValue) {
var data = (1.0 - (minValue / maxValue));
if (data < 0.0) {
return 0.0;
} else if (data >= 0 && data <= 1) {
return data;
} else {
return 1.0;
}
}
#override
double get maxExtent => heightValue;
#override
double get minExtent => heightValue / 5;
#override
bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
return true;
}
}
Look at the Text Widget, hope it helps. Too lazy to read the whole thing carefully. By the way, you can replace a == null ? 'whatever' : a with a ?? 'whatever'. ?? is equal with if null
Row(
children: <Widget>[
Text(
/// The problem is probably here, missing '='
appProvider.selectedTourguide.tariffValue= null ? '' : appProvider.selectedTourguide.tariffValue,
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 22,
color: isInList == null
? AppTheme.getTheme().textTheme.body1.color
: Colors.white,
),
),
Text(
/// The problem is probably here, missing '='
appProvider.selectedTourguide.currency= null ? '' : appProvider.selectedTourguide.currency,
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 22,
color: isInList == null
? AppTheme.getTheme().textTheme.body1.color
: Colors.white,
),
),
],
),
I am trying to place text under a image in my carousel slider but now the text appears on the image, not under.
It looks like this:
But I want it to look like this:
Here is my code:
final CarouselSlider autoPlayDemo = CarouselSlider(
viewportFraction: 0.9,
aspectRatio: 2.0,
autoPlay: false,
enlargeCenterPage: true,
items: imgList.map(
(child) {
return Container(
margin: EdgeInsets.all(10.0),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
child: Stack(children: <Widget>[
Image.asset(
child,
fit: BoxFit.cover,
width: 1000.0,
),
Padding(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
child: Text(
'Text',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
))
])),
);
},
).toList(),
);
What can I do to place the text under the image insted of on the image?
Stack(children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
height: 600,
decoration: BoxDecoration(
color: Color.fromRGBO(217,225,216,1),
),
padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 20.0),
child: Text(
'News',
style: TextStyle(
color: Colors.black,
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 50.0),
child: Column(children: [
autoPlayDemo,
])),
]),
Wrapping them with a Stack widget is wrong. Stack is a widget that displays its children over each other. Instead, wrap them in a Column widget that displays its children in a horizontal manner under each other.
Also wrap the image with the ClipRRect to achieve your goal.
final CarouselSlider autoPlayDemo = CarouselSlider(
viewportFraction: 0.9,
aspectRatio: 2.0,
autoPlay: false,
enlargeCenterPage: true,
items: imgList.map(
(child) {
return Container(
margin: EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
child: Image.asset(
child,
fit: BoxFit.cover,
width: 1000.0,
),
),
Expanded(
child: Padding(
padding:
EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
child: Text(
'Text',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
);
},
).toList(),
);
This is complete working code with Image on top with text and dots. For this you need to use these two libraries:- " carousel_slider: ^4.1.1 ", "smooth_page_indicator: ^1.0.0+2", update them to the latest.
class MyItem {
String itemName;
String path;
MyItem(this.itemName, this.path);
}
class craouselImage extends StatefulWidget {
#override
_craouselImage createState() => _craouselImage();
}
class _craouselImage extends State<craouselImage> {
int activeIndex = 0;
List<MyItem> items = [
MyItem("item 1", 'assets/images/appiconlogo.png'),
MyItem("item 2", 'assets/images/Mockup4.png'),
];
#override
Widget build(BuildContext context) {
return Container(
child: Column(
children: [
CarouselSlider.builder(
itemCount: items.length,
options: CarouselOptions(
height: 400,
viewportFraction: 1,
autoPlay: true,
enlargeCenterPage: true,
enlargeStrategy: CenterPageEnlargeStrategy.height,
autoPlayInterval: const Duration(seconds: 1),
onPageChanged: (index, reason) {
setState(() {
activeIndex = index;
});
},
),
itemBuilder: (context, index, realIndex) {
final imgList = items[index];
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Expanded(child: buildImage(imgList.path, index)),
const SizedBox(
height: 15,
),
buildText(imgList.itemName, index),
],
);
},
),
const SizedBox(
height: 22,
),
buildIndicator(),
const SizedBox(
height: 22,
),
//buildText(itemName, index),
// buildText(),
],
),
);
}
Widget buildImage(String imgList, int index) => Container(
margin: const EdgeInsets.symmetric(horizontal: 12),
color: Colors.transparent,
child: Align(
alignment: Alignment.center,
child: Image.asset(
imgList,
fit: BoxFit.cover,
),
),
);
buildIndicator() => AnimatedSmoothIndicator(
activeIndex: activeIndex,
count: items.length,
effect: const JumpingDotEffect(
dotColor: Colors.black,
dotHeight: 15,
dotWidth: 15,
activeDotColor: mRed),
);
buildText(String itemName, int index) => Align(
alignment: FractionalOffset.bottomCenter,
child: Text(
itemName,
style: const TextStyle(
fontWeight: FontWeight.w700, fontSize: 23, color: mRed),
));
}
I am trying to make this type of view
there 3 types of news latest,sport and old news which are having 3 listview the data is populating but i am unable to scroll it the list view or the complete scroll view is not scrolling i had trying it from the 1 week please find the below code
I am able to the layout but it's not scrolling at all
First tab view
class First_Tab_Layout extends StatefulWidget {
#override
State<StatefulWidget> createState() {
First_State fst_state() => new First_State();
return fst_state();
}
}
class First_State extends State<First_Tab_Layout> {
List latest_news_list;
List sports_news_list;
List cinema_news_list;
latestnews() async {
var latest_news_url = common_url + 'getlatestPosts';
print(latest_news_url);
http.Response latest_newsresponse = await http.get(latest_news_url);
var latest_news_response = json.decode(latest_newsresponse.body);
setState(() {
latest_news_list = latest_news_response['posts'];
});
}
sportsnews() async {
var sports_news_url = common_url + 'getsportsPosts';
print(sports_news_url);
http.Response sports_newsresponse = await http.get(sports_news_url);
var sports_news_response = json.decode(sports_newsresponse.body);
setState(() {
sports_news_list = sports_news_response['posts'];
});
}
cinemanews() async {
var cinema_news_url = common_url + 'getcinemaPosts';
print(cinema_news_url);
http.Response cinema_newsresponse = await http.get(cinema_news_url);
var cinema_news_response = json.decode(cinema_newsresponse.body);
setState(() {
cinema_news_list = cinema_news_response['posts'];
});
}
#override
void initState() {
super.initState();
latestnews();
sportsnews();
cinemanews();
}
#override
Widget build(BuildContext context) {
return new MaterialApp(
debugShowCheckedModeBanner: false,
home: new Scaffold(
body: new ListView(
primary: true,
children: <Widget>[
new Container(
child: new Text(
'Latest News',
style: new TextStyle(fontSize: 16.0),
),
margin: EdgeInsets.only(left: 10.0, right: 10.0, bottom: 5.0),
alignment: Alignment(-1.0, 0.0),
),
new Container(
child: new Divider(
color: secondarycolor,
),
margin: EdgeInsets.only(right: 10.0, left: 10.0),
),
new Container(
child: new ListView.builder(
shrinkWrap: true,
itemCount: latest_news_list == null ? 0 : latest_news_list.length,
itemBuilder: (BuildContext context, int indexpos) {
return new GestureDetector(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new News_Details(
postid: latest_news_list[indexpos]['id'],
)));
},
child: new Card(
elevation: 4.0,
margin: EdgeInsets.only(left: 10.0, right: 10.0, top: 5.0),
child: new Row(
children: <Widget>[
new Container(
child: new Image.network(
latest_news_list[indexpos]['image'],
width: 150.0,
fit: BoxFit.fill,
),
),
new Flexible(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Container(
child: new Text(
latest_news_list[indexpos]['title']),
margin: EdgeInsets.only(left: 10.0),
),
new Container(
child: new Text(
latest_news_list[indexpos]['content'],
softWrap: true,
maxLines: 4,
),
margin: EdgeInsets.only(left: 10.0, top: 5.0),
),
],
),
)
],
),
),
);
},
),
),
new Container(
child: new Text(
'Sports News',
style: new TextStyle(fontSize: 16.0),
),
margin: EdgeInsets.only(left: 10.0, right: 10.0, top: 5.0),
alignment: Alignment(-1.0, 0.0),
),
new Container(
child: new Divider(
color: secondarycolor,
),
margin: EdgeInsets.only(right: 10.0, left: 10.0),
),
new Container(
child: new ListView.builder(
shrinkWrap: true,
itemCount: sports_news_list == null ? 0 : sports_news_list.length,
itemBuilder: (BuildContext context, int indexpos) {
return new GestureDetector(
child: new Card(
elevation: 4.0,
margin: EdgeInsets.only(left: 10.0, right: 10.0, top: 5.0),
child: new Row(
children: <Widget>[
new Container(
child: new Image.network(
sports_news_list[indexpos]['image'],
width: 150.0,
height: 75.0,
fit: BoxFit.fill,
),
),
new Column(
children: <Widget>[
new Container(
child:
new Text(sports_news_list[indexpos]['title']),
margin: EdgeInsets.only(left: 10.0),
),
new Container(
child:
new Text(sports_news_list[indexpos]['title']),
margin: EdgeInsets.only(left: 10.0, top: 5.0),
),
],
)
],
),
),
);
},
),
),
new Container(
child: new Text(
'Cinema News',
style: new TextStyle(fontSize: 16.0),
),
margin: EdgeInsets.only(
left: 10.0, right: 10.0, top: 10.0, bottom: 5.0),
alignment: Alignment(-1.0, 0.0),
),
new Container(
child: new Divider(
color: secondarycolor,
),
margin: EdgeInsets.only(right: 10.0, left: 10.0),
),
new Container(
child: new ListView.builder(
shrinkWrap: true,
itemCount: cinema_news_list == null ? 0 : cinema_news_list.length,
itemBuilder: (BuildContext context, int indexpos) {
return new GestureDetector(
child: new Card(
elevation: 4.0,
margin: EdgeInsets.only(left: 10.0, right: 10.0, top: 5.0),
child: new Row(
children: <Widget>[
new Container(
child: new Image.network(
cinema_news_list[indexpos]['image'],
width: 150.0,
height: 75.0,
fit: BoxFit.fill,
),
),
new Column(
children: <Widget>[
new Container(
child: new Text(
cinema_news_list[indexpos]['categorytitle']),
margin: EdgeInsets.only(left: 10.0),
),
new Container(
child: new Text(
cinema_news_list[indexpos]['categorytitle']),
margin: EdgeInsets.only(left: 10.0, top: 5.0),
),
],
)
],
),
),
);
},
),
),
],
)),
);
}
}
This worked for me. Not sure whether this will work for you. Try once. I just added physics to inner ListView.
new Container(
child: new ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
This worked for me :
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: Padding(
padding: const EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
child: Container(
child: ListView(
children: <Widget>[
selectedAddressSection(),
Padding(
padding: EdgeInsets.fromLTRB(15, 10, 0, 10),
child: Text("YOUR FAVOURITE PAYMENT METHODS",
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 14.0,
fontFamily: 'Novecento Book',
fontWeight: FontWeight.bold)),
),
selectedPaymentMethod(),
Padding(
padding: EdgeInsets.fromLTRB(15, 10, 0, 10),
child: Text("PAYMENT DETAILS",
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 14.0,
fontFamily: 'Novecento Book',
fontWeight: FontWeight.bold)),
),
SizedBox(
height: 8.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 15),
child: Text(
"Subtotal",
textAlign: TextAlign.start,
style: TextStyle(
color: const Color(0xFF000000),
fontSize: 12.0,
fontFamily: 'Novecento Book',
fontWeight: FontWeight.w300),
),
),
Container(
margin: EdgeInsets.only(right: 15),
child: Text(
'\u{20B9}${2500.00}',
textAlign: TextAlign.start,
style: TextStyle(
color: const Color(0xFF000000),
fontSize: 12.0,
fontFamily: 'Novecento Book',
fontWeight: FontWeight.w300),
),
),
],
),
SizedBox(
height: 8.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 15),
child: Text(
"Shipping",
textAlign: TextAlign.start,
style: TextStyle(
color: const Color(0xFF000000),
fontSize: 12.0,
fontFamily: 'Novecento Book',
fontWeight: FontWeight.w300),
),
),
Container(
margin: EdgeInsets.only(right: 15),
child: Text(
'Free',
textAlign: TextAlign.start,
style: TextStyle(
color: const Color(0xFF000000),
fontSize: 12.0,
fontFamily: 'Novecento Book',
fontWeight: FontWeight.w300),
),
),
],
),
SizedBox(
height: 8.0,
),
Divider(
color: Colors.grey.shade400,
height: 10,
thickness: 0.5,
indent: 10,
endIndent: 10,
),
SizedBox(
height: 8.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 15),
child: Text(
"Grand total",
textAlign: TextAlign.start,
style: TextStyle(
color: const Color(0xFF000000),
fontSize: 12.0,
fontFamily: 'Novecento Book',
fontWeight: FontWeight.bold),
),
),
Container(
margin: EdgeInsets.only(right: 15),
child: Text(
'\u{20B9}${2500.00}',
textAlign: TextAlign.start,
style: TextStyle(
color: const Color(0xFF000000),
fontSize: 12.0,
fontFamily: 'Novecento Book',
fontWeight: FontWeight.bold),
),
),
],
),
Divider(
color: Colors.grey.shade400,
height: 20,
thickness: 0.5,
indent: 10,
endIndent: 10,
),
// standardDelivery(),
//priceSection()
],
),
),
),
],
),
),
);
}