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 would like to be able to implement a showModalTopSheet on the booking.com site
On the first image (img1), a search has already been performed. The search criteria are included in an input button.
By clicking on this button, I get a more detailed search.(img2)
img1
img2
Have you tried using stack widget as the parent and making a separate widget for the top search and filter section. And make a Boolean state for the filter. So the state will turn true when a search is made.
So try to use stack as the parent and make the list of hotels as the first child and make the search text box as the second child with container having padding and alignment property as Alignment.topCenter and make the stack fit property as StackFit.loose .
Below is the example code for implementing the above suggestion.
Link for the sample working images and video.
https://drive.google.com/drive/folders/1BrEtcQCg8VEN7WQgXUorBc34R04gipAA?usp=sharing
import 'package:flutter/material.dart';
class SampleWidget extends StatefulWidget {
const SampleWidget({Key? key}) : super(key: key);
#override
State<SampleWidget> createState() => _SampleWidgetState();
}
class _SampleWidgetState extends State<SampleWidget>
with TickerProviderStateMixin {
late TabController _tabController;
bool _isFilterEnabled = false;
#override
void initState() {
_tabController = new TabController(length: 3, vsync: this, initialIndex: 0);
super.initState();
}
TabBar getTabBar() {
return TabBar(
indicatorColor: Colors.white,
controller: _tabController,
tabs: [
Container(
padding: EdgeInsets.only(top: 20),
height: 65,
child: Tab(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: const [
Icon(
Icons.import_export,
color: Colors.grey,
),
Text(
"Trier",
style: TextStyle(
color: Colors.grey,
),
),
],
),
),
),
Container(
padding: const EdgeInsets.only(top: 20),
height: 50,
child: Tab(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: const [
Icon(
Icons.tune,
color: Colors.grey,
),
Text(
"Filter",
style: TextStyle(
color: Colors.grey,
),
),
],
),
),
),
Container(
padding: const EdgeInsets.only(top: 20),
height: 50,
child: Tab(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: const [
Icon(
Icons.map,
color: Colors.grey,
),
Text(
"Carte",
style: TextStyle(
color: Colors.grey,
),
),
],
),
),
),
],
);
}
#override
Widget build(BuildContext context) {
return Stack(
children: [
Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
backgroundColor: const Color(0xFF013580),
bottom: PreferredSize(
preferredSize: getTabBar().preferredSize,
child: ColoredBox(
color: Colors.white,
child: getTabBar(),
),
),
),
body: TabBarView(
controller: _tabController,
children: [
ListView.builder(
itemBuilder: (index, context) => const ListTile(
leading: Icon(Icons.abc),
),
itemCount: 20,
),
ListView.builder(
itemBuilder: (index, context) => const ListTile(
leading: Icon(Icons.access_alarm),
),
itemCount: 20,
),
ListView.builder(
itemBuilder: (index, context) => const ListTile(
leading: Icon(Icons.ac_unit),
),
itemCount: 20,
)
],
),
),
Material(
color: Colors.transparent,
child: InkWell(
splashColor: Colors.transparent,
onTap: () {
print("container is pressed");
setState(() {
_isFilterEnabled = !_isFilterEnabled;
});
},
child: Container(
height: 60,
child: Row(
children: const [
Icon(
Icons.chevron_left,
color: Colors.grey,
),
SizedBox(width: 20),
Text(
"Sample Text text",
style: TextStyle(
color: Colors.grey,
fontSize: 18,
decoration: TextDecoration.none,
),
)
],
),
margin: const EdgeInsets.only(
left: 20, right: 20, bottom: 20, top: 5),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(5),
border: Border.all(color: Colors.amber, width: 4),
),
),
),
),
if (_isFilterEnabled)
Material(
elevation: 5,
color: Colors.transparent,
child: Container(
color: Colors.white,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
InkWell(
onTap: () {
setState(() {
_isFilterEnabled = !_isFilterEnabled;
});
},
child: Icon(
Icons.close,
),
),
Text(
"Modifiez Votre recherche",
style: TextStyle(
color: Colors.black,
fontSize: 20,
decoration: TextDecoration.none,
fontWeight: FontWeight.w600),
)
],
),
const SizedBox(height: 10),
Container(
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(5),
border: Border.all(color: Colors.amber, width: 4),
),
child: Column(
children: [
Container(
padding: const EdgeInsets.only(
top: 8,
bottom: 5,
),
child: Row(
children: const [
SizedBox(width: 10),
Icon(Icons.search),
SizedBox(width: 10),
Text("France")
],
),
),
const Divider(color: Colors.black38),
Container(
padding: const EdgeInsets.only(
top: 8,
bottom: 5,
),
child: Row(
children: const [
SizedBox(width: 10),
Icon(Icons.search),
SizedBox(width: 10),
Text("France")
],
),
),
const Divider(color: Colors.black38),
Container(
padding: const EdgeInsets.only(
top: 8,
bottom: 8,
),
child: Row(
children: const [
SizedBox(width: 10),
Icon(Icons.search),
SizedBox(width: 10),
Text("France")
],
),
),
Container(
color: Color(0xFF0171c2),
height: 50,
width: double.infinity,
child: const Center(
child: Text(
" Recharge",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
)
],
),
),
const SizedBox(height: 10),
],
),
),
)
],
);
}
}
I have gridviewbuilder that takes data from itemGriddata which has onTap function that directs it to a new page that takes data from that model as well but when I click on it the error in the title appears, any help or some kind of enlightement would be appreciated
this is gridview page
import 'package:flutter/material.dart';
import 'package:wild_wild_rift/builds/SinglePage.dart';
import 'package:wild_wild_rift/data/model.dart';
import 'package:google_fonts/google_fonts.dart';
class GridViewPage extends StatefulWidget {
#override
_GridViewPage createState() => _GridViewPage();
}
class _GridViewPage extends State<GridViewPage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.grey,
automaticallyImplyLeading: true,
title: const Text(
'Champions',
style: TextStyle(
fontFamily: 'Lexend Doca',
color: Colors.white,
fontSize: 32,
fontWeight: FontWeight.bold,
),
),
elevation: 2,
),
body: Column(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(15, 15, 15, 15),
child: GridView.builder(
itemCount: itemGriddata.length,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
childAspectRatio: 1,
),
itemBuilder: (context, index) {
return GridSingleItem(
itemGriddata: itemGriddata[index],
onTap: () async {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SinglePage(itemGriddata[index])));
},
);
},
),
),
),
],
));
}
}
class GridSingleItem extends StatelessWidget {
final itemGriddata;
final Function onTap;
const GridSingleItem({Key key, #required this.itemGriddata, this.onTap})
: super(key: key);
#override
Widget build(BuildContext context) {
return InkWell(
onTap: onTap,
child: ClipRRect(
borderRadius: BorderRadius.circular(5),
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: const Color(0xEEEEEE),
image: DecorationImage(
fit: BoxFit.cover,
image: Image.asset(itemGriddata.image).image,
),
boxShadow: const [
BoxShadow(
blurRadius: 3,
color: Color(0xDA000000),
)
],
borderRadius: BorderRadius.circular(9),
border: Border.all(
color: Colors.black,
),
),
child: Align(
alignment: AlignmentDirectional(-0.45, 0.85),
child: Text(
itemGriddata.name,
style: TextStyle(
fontFamily: 'Lexend Deca',
color: Color(0xFFFFFCFC),
fontWeight: FontWeight.normal,
shadows: [
Shadow(
blurRadius: 8.0,
color: Colors.black,
offset: Offset(1.0, 1.0),
),
],
),
),
),
),
),
);
}
}
this is page that I'd want to take data
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import '../data/model.dart';
class SinglePage extends StatefulWidget {
#override
_SinglePage createState() => _SinglePage();
final Data data;
SinglePage(this.data);
}
class _SinglePage extends State<SinglePage> {
PageController pageViewController;
bool isFirstButton = false;
bool isSecondButton = false;
#override
void initState() {
super.initState();
pageViewController = PageController(initialPage: 0);
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: const Color(0xFF090F13),
automaticallyImplyLeading: true,
title: Text(
itemGriddata.name,
style: TextStyle(
fontFamily: 'Lexend Deca',
color: Colors.white,
fontSize: 32,
fontWeight: FontWeight.bold,
),
),
actions: const [],
centerTitle: false,
elevation: 2,
),
backgroundColor: const Color(0xFF262D34),
body: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(0, 0, 0, 25),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Row(
mainAxisSize: MainAxisSize.max,
children: [
Material(
color: Colors.transparent,
elevation: 3,
child: Container(
width: MediaQuery.of(context).size.width,
height: 150,
decoration: BoxDecoration(
color: const Color(0xFF090F13),
image: DecorationImage(
fit: BoxFit.cover,
image: Image.asset(
itemGriddata.backgroundimage,
).image,
),
),
),
),
],
),
Padding(
padding:
const EdgeInsetsDirectional.fromSTEB(20, 12, 20, 0),
child: Row(
mainAxisSize: MainAxisSize.max,
children: const [
Text(
'Choose role',
style: TextStyle(
fontFamily: 'Lexend Deca',
color: Color(0xFF8B97A2),
fontSize: 14,
fontWeight: FontWeight.normal,
),
),
],
),
),
Padding(
padding:
const EdgeInsetsDirectional.fromSTEB(0, 12, 1, 0),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
16, 0, 0, 0),
child: InkWell(
onTap: () async {
isSecondButton = false;
isFirstButton = true;
setState(() {});
await pageViewController.animateToPage(
0,
duration: const Duration(milliseconds: 500),
curve: Curves.ease,
);
},
child: Material(
color: Colors.transparent,
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: const Color(0xFF090F13),
borderRadius: BorderRadius.circular(8),
shape: BoxShape.rectangle,
border: isFirstButton
? Border.all(color: Colors.white)
: null),
child: Stack(
children: [
Align(
alignment: const AlignmentDirectional(
0, -0.05),
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Image.asset(
'assets/images/icon-position-jungle.png',
width: 50,
height: 50,
fit: BoxFit.cover,
),
const Padding(
padding: EdgeInsetsDirectional
.fromSTEB(0, 8, 0, 0),
child: AutoSizeText(
'BUILD 1',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Lexend Deca',
color: Color(0xFF8B97A2),
fontSize: 14,
fontWeight:
FontWeight.normal,
),
),
),
],
),
),
],
),
),
),
),
),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
16, 0, 0, 0),
child: Material(
color: Colors.transparent,
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: const Color(0xFF090F13),
borderRadius: BorderRadius.circular(8),
border: isSecondButton
? Border.all(color: Colors.white)
: null),
child: InkWell(
onTap: () async {
isSecondButton = true;
isFirstButton = false;
setState(() {});
await pageViewController.animateToPage(
1,
duration:
const Duration(milliseconds: 500),
curve: Curves.ease,
);
},
child: Stack(
children: [
Align(
alignment: const AlignmentDirectional(
0, -0.05),
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Image.asset(
'assets/images/icon-position-jungle.png',
width: 50,
height: 50,
fit: BoxFit.cover,
),
const Padding(
padding: EdgeInsetsDirectional
.fromSTEB(0, 8, 0, 0),
child: AutoSizeText(
'BUILD 2',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Lexend Deca',
color: Color(0xFF8B97A2),
fontSize: 14,
fontWeight:
FontWeight.normal,
),
),
),
],
),
),
],
),
),
),
),
),
],
),
),
),
Padding(
padding:
const EdgeInsetsDirectional.fromSTEB(20, 8, 20, 8),
child: Row(
mainAxisSize: MainAxisSize.max,
children: const [
Text(
'Builds',
style: TextStyle(
fontFamily: 'Lexend Deca',
color: Color(0xFF8B97A2),
fontSize: 14,
fontWeight: FontWeight.normal,
),
),
],
),
),
SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
16, 8, 16, 0),
child: Container(
width: MediaQuery.of(context).size.width,
height: 200,
decoration: BoxDecoration(
color: const Color(0x00090F13),
boxShadow: const [
BoxShadow(
blurRadius: 3,
color: Colors.transparent,
offset: Offset(0, 2),
)
],
borderRadius: BorderRadius.circular(8),
),
child: SizedBox(
width: double.infinity,
height: 500,
child: PageView(
controller: pageViewController,
scrollDirection: Axis.horizontal,
children: [
Image.asset(
'assets/images/image_1.png',
width: 100,
height: 100,
fit: BoxFit.cover,
),
Image.asset(
'assets/images/image_2.png',
width: 100,
height: 100,
fit: BoxFit.scaleDown,
),
],
),
),
),
),
],
),
),
],
),
),
),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(20, 0, 20, 8),
child: Row(
mainAxisSize: MainAxisSize.max,
children: const [
Text(
'Text',
style: TextStyle(
fontFamily: 'Poppins',
color: Color(0xFF8B97A2),
),
),
],
),
),
],
),
),
);
}
}
and this is the model with data
final dynamic itemGriddata = [
Data(
name: "Ahri",
image: "assets/images/Ahri.png",
backgroundimage: "assets/images/Ahri_0.jpg"),
Data(
name: "Akali",
image: "assets/images/Akali.png",
backgroundimage: "assets/images/Akali_0.jpg")
];
class Data {
final String name;
final String image;
final String backgroundimage;
Data({this.name, this.image, this.backgroundimage});
}
The issue is that your SinglePage widget has a prop named final Data data; but the _SinglePageState widget is calling itemGriddata for your title and images. You'll need to change your code like so:
class SinglePage extends StatefulWidget {
const SinglePage(Key? key, this.data): super(key: key);
final Data data;
#override
State<StatefulWidget> createState() => _SinglePageState();
}
class _SinglePageState extends State<SinglePage> {
// use widget.data to get name, image, and backgroundImage
// ex... widget.data.name or widget.data.image
#override
Widget build(BuildContext context) {
return Text(widget.data.name);
}
}
You're passing the data correctly to SinglePage, but just change a few lines to ensure you're calling something with actual data! :D
I just started learning flutter and am trying to build a todo app, the problem I encountered was the Dismissible container and the todo list view item have different heights and after trying everything I still couldn't fix it, the next problem was that the todo item would be dismissed from left to right whereas the container would go up. Any help would be much appreciated. My code:
class _HomePageState extends State<HomePage> {
List todos = [];
List<TextEditingController> _titleController = [];
List<TextEditingController> _detailController = [];
#override
void initState() {
super.initState();
todos.add('');
_titleController.add(TextEditingController());
_detailController.add(TextEditingController());
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
horizontal: 24.0,
),
color: const Color(0xfff6f6f6f6),
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.only(bottom: 32.0, top: 32.0),
child: const Text(
"Reminders",
style: TextStyle(
fontSize: 25.0,
fontWeight: FontWeight.bold
),
),
),
Expanded(
child: ListView.builder(
itemCount: todos.length,
physics: const BouncingScrollPhysics(),
itemBuilder: (BuildContext context, int index) {
return Dismissible(
background: buildActionSwipeLeft(),
onDismissed: (direction) {
setState(() {
todos.removeAt(index);
_titleController.removeAt(index);
_detailController.removeAt(index);
DismissDirection.startToEnd;
});
},
direction: DismissDirection.startToEnd,
key: Key(todos[index]),
child: Padding(
padding: const EdgeInsets.only(
bottom: 15.0
),
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
elevation: 4,
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
vertical: 15.0,
horizontal: 24.0
),
margin: const EdgeInsets.only(
bottom: 20.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextField(
cursorColor: Colors.black,
controller: _titleController[index],
style: const TextStyle(
fontSize: 22.0,
fontWeight: FontWeight.bold
),
decoration: const InputDecoration(
hintText: "Enter a title",
border: InputBorder.none,
),
),
const Divider(
color: Colors.black,
),
Padding(
padding: const EdgeInsets.only(top: 0.0),
child: TextField(
controller: _detailController[index],
style: TextStyle(
fontSize: 20.0,
color: Colors.grey[900],
),
cursorColor: Colors.black,
maxLines: null,
decoration: const InputDecoration(
hintText: "Enter the description",
label: Text("description"),
border: InputBorder.none
),
),
),
],
),
),
),
),
);
},
),
)
],
),
Positioned(
bottom: 24.0,
right: 0.0,
child: GestureDetector(
onTap: () {
setState(() {
todos.add('');
_titleController.add(TextEditingController());
_detailController.add(TextEditingController());
});
},
child: Container(
width: 60.0,
height: 60.0,
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.circular(20.0),
),
child: const Icon(Icons.add, color: Colors.white, size: 35.0),
),
),
)
],
),
),
),
);
}
}
Widget buildActionSwipeLeft() => Container(
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.red,
),
padding: const EdgeInsets.symmetric(horizontal: 30),
child: const Icon(Icons.delete, color: Colors.white, size: 30),
);
class _HomePageState extends State<HomePage> {
List todos = [];
List<TextEditingController> _titleController = [];
List<TextEditingController> _detailController = [];
#override
void initState() {
super.initState();
todos.add('');
_titleController.add(TextEditingController());
_detailController.add(TextEditingController());
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
horizontal: 24.0,
),
color: const Color(0xfff6f6f6f6),
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.only(bottom: 32.0, top: 32.0),
child: const Text(
"Reminders",
style: TextStyle(
fontSize: 25.0, fontWeight: FontWeight.bold),
),
),
Expanded(
child: ListView.builder(
itemCount: todos.length,
physics: const BouncingScrollPhysics(),
itemBuilder: (BuildContext context, int index) {
return Stack(
clipBehavior: Clip.hardEdge,
children: [
Padding(
padding: const EdgeInsets.only(top:10.0,left: 8.0, right: 8.0),
child: buildActionSwipeLeft(),
),
Dismissible(
onDismissed: (direction) {
setState(() {
todos.removeAt(index);
_titleController.removeAt(index);
_detailController.removeAt(index);
DismissDirection.startToEnd;
});
},
direction: DismissDirection.startToEnd,
key: UniqueKey(),
child: Padding(
padding: const EdgeInsets.only(bottom: 15.0),
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
elevation: 4,
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
vertical: 15.0, horizontal: 24.0),
margin: const EdgeInsets.only(
bottom: 20.0,
),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
TextField(
cursorColor: Colors.black,
controller: _titleController[index],
style: const TextStyle(
fontSize: 22.0,
fontWeight: FontWeight.bold),
decoration: const InputDecoration(
hintText: "Enter a title",
border: InputBorder.none,
),
),
const Divider(
color: Colors.black,
),
Padding(
padding:
const EdgeInsets.only(top: 0.0),
child: TextField(
controller:
_detailController[index],
style: TextStyle(
fontSize: 20.0,
color: Colors.grey[900],
),
cursorColor: Colors.black,
maxLines: null,
decoration: const InputDecoration(
hintText:
"Enter the description",
label: Text("description"),
border: InputBorder.none),
),
),
],
),
),
),
),
)
],
);
},
),
)
],
),
Positioned(
bottom: 24.0,
right: 0.0,
child: GestureDetector(
onTap: () {
setState(() {
todos.add('');
_titleController.add(TextEditingController());
_detailController.add(TextEditingController());
});
},
child: Container(
width: 60.0,
height: 60.0,
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.circular(20.0),
),
child:
const Icon(Icons.add, color: Colors.white, size: 35.0),
),
),
)
],
),
),
),
);
}
}
Widget buildActionSwipeLeft() => Container(
height: 180,
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.red,
),
padding: const EdgeInsets.only(left: 30),
child: const Icon(Icons.delete, color: Colors.white, size: 30),
);
Achieving this has a disadvantage of loosing a few animation. Will research more:
I know enable a button to bounce on tap but the problem i am facing is that i want to implement this on a listview containing containers but i am unable to do it.There are only questions regarding a single button like here https://pub.dev/packages/bouncing_widget but not for whole list of buttons/containers or so. I tried the above link package but it is also causing other issues like the list is not scrolling , and sometimes it is not working at all, Please help
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage()
);
}
}
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> with SingleTickerProviderStateMixin{
AnimationController animationController;
double _scale;
#override
void initState(){
animationController=AnimationController(vsync: this,duration: Duration(milliseconds: 500),
lowerBound: 0.0,upperBound: 0.2);
animationController.addListener(() {
setState(() {
});
});
super.initState();
}
void Ontapdown(TapDownDetails details){
animationController.forward();
}
void Ontapup(TapUpDetails details){
animationController.reverse();
}
bool lights=false;
int count1=0;
int count2=0;
#override
Widget build(BuildContext context) {
_scale =1-animationController.value;
return Scaffold(
appBar: AppBar(
title: Text("Quickier"),
centerTitle: true,
backgroundColor: Colors.indigo,
),
body: Container(
height: 250,
margin: EdgeInsets.fromLTRB(10, 10, 5, 10),
child: ListView(
scrollDirection: Axis.horizontal,
physics: BouncingScrollPhysics(),
children: <Widget>[
GestureDetector(
onTap: (){
Navigator.push(context,MaterialPageRoute(builder:
(context)=> camerapp()));
},
child: Container(
margin: EdgeInsets.fromLTRB(5, 0, 5, 0),
height: 100,
width: 200,
decoration: BoxDecoration(
color: Colors.grey[700],
borderRadius: BorderRadius.all(Radius.circular(10),)
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.camera_alt,
color: Colors.black,
size: 70,
),
SizedBox(height: 20.0),
Text(
"Camera",
style: TextStyle(
fontSize: 20.0,
color: Colors.black
),
)
],
)
),
),
GestureDetector(
onTap: (){
setState(() {
if(count1%2==1){
lights=false;
Flashlight.lightOff();}
else{
lights=true;
Flashlight.lightOn();
}
count1+=1;
});
},
child: Container(
margin: EdgeInsets.fromLTRB(5, 0, 5, 0),
height: 100,
width: 200,
padding: EdgeInsets.symmetric(vertical: 20.0,horizontal: 20.0),
decoration: BoxDecoration(
color: Colors.teal[300],
borderRadius: BorderRadius.all(Radius.circular(10),)
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.highlight,
color: lights ? Colors.yellow.shade600 : Colors.black,
size: 70,
),
SizedBox(height: 20.0),
Text(
"Flashlight",
style: TextStyle(
fontSize: 20.0,
color: Colors.black
),
)
],
)
),
),
GestureDetector(
onTap: (){
HapticFeedback.lightImpact();
},
onTapDown: Ontapdown,
onTapUp: Ontapup,
child: Transform.scale(
scale: _scale,
child: Container(
margin: EdgeInsets.fromLTRB(5, 0, 5, 0),
height: 100,
width: 200,
decoration: BoxDecoration(
color: Colors.teal[400],
borderRadius: BorderRadius.all(Radius.circular(10),)
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.vibration,
color: Colors.black,
size: 70,
),
SizedBox(height: 20.0),
Text(
"Vibration",
style: TextStyle(
fontSize: 20.0,
color: Colors.black
),
)
],
)
),
),
),
Container(
margin: EdgeInsets.fromLTRB(5, 0, 5, 0),
height: 100,
width: 200,
decoration: BoxDecoration(
color: Colors.teal[500],
borderRadius: BorderRadius.all(Radius.circular(10),)
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.settings,
color: Colors.black,
size: 70,
),
SizedBox(height: 20.0),
Text(
"Settings",
style: TextStyle(
fontSize: 20.0,
color: Colors.black
),
)
],
)
)
],
),
)
);
}
}
I have enable it on one container i.e. third the vibration one but when i apply ontapup and ontapdown on other's GestureDetectors very different things happen like if i click any one of the containers all are bouncing at the same time,type......
so, please tell me what I should do or if there is any other approach it will be helpful as I'm only a beginner.
Any other suggestions will be grateful too.