Error when insert Textfield into column Flutter - user-interface

This is my code
SafeArea(
child: Scaffold(
body: Container(
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(
children: <Widget>[
Flexible(
child: Container(
width: 100,
child:
TextFormField(decoration: const InputDecoration()),
),
)
],
),
Column(
children: <Widget>[
Flexible(
child: Container(
width: 100,
child:
TextFormField(decoration: const InputDecoration()),
),
)
],
),
Column(
children: <Widget>[
Flexible(
child: Container(
width: 100,
child:
TextFormField(decoration: const InputDecoration()),
),
)
],
)
],
)
],
),
),
),
);
But when I run that code it shows error like following
═══════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderFlex#1b387 relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1694 pos 12: 'hasSize'
The relevant error-causing widget was
Row
lib\GPA1.dart:24
════════════════════════════════════════════════════════════════════════════════
I can't build my project. Can anyone help me??
I used flutter 1.17.0
I use my mobile device to preview this
I use Samsung Galaxy A5 2016
I use Flexible to wrap TextFormField but it shows the same error again.

You need to wrap Row Widget with Expanded widget.
SafeArea(
child: Scaffold(
body: Container(
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[],
),
Expanded( // added
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(
children: <Widget>[
Flexible(
child: Container(
width: 100,
child: TextFormField(
decoration: const InputDecoration()),
),
)
],
),
Column(
children: <Widget>[
Flexible(
child: Container(
width: 100,
child: TextFormField(
decoration: const InputDecoration()),
),
)
],
),
Column(
children: <Widget>[
Flexible(
child: Container(
width: 100,
child: TextFormField(
decoration: const InputDecoration()),
),
)
],
)
],
),
)
],
),
),
));

I think you should get rid of the "Flexible".
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(
children: <Widget>[
Container(
width: 100,
child: TextFormField(decoration: const InputDecoration()),
),
],
),
Column(
children: <Widget>[
Container(
width: 100,
child: TextFormField(decoration: const InputDecoration()),
),
],
),
Column(
children: <Widget>[
Container(
width: 100,
child: TextFormField(decoration: const InputDecoration()),
),
],
),
],
),

This code will do the job.
SafeArea(
child: Scaffold(
body: Container(
margin: EdgeInsets.all(5),
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: Padding(
padding: EdgeInsets.only(
left: 5, right: 5),
child: TextFormField(
decoration:
const InputDecoration()))),
Expanded(
child: Padding(
padding: EdgeInsets.only(
left: 5, right: 5),
child: TextFormField(
decoration:
const InputDecoration()))),
Expanded(
child: Padding(
padding: EdgeInsets.only(
left: 5, right: 5),
child: TextFormField(
decoration:
const InputDecoration())))
],
),
],
),
),
));
Result

Related

i want to start next container for table data where i start in this code

import 'package:flutter/material.dart';
import 'package:smart_uild/assets.dart';
class Myprofile extends StatelessWidget {
const Myprofile({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: const Color(0xff384A62),
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Navigator.of(context).pop(),
),
title: const Text("My Profile"),
elevation: 0,
),
body: Padding(
padding: const EdgeInsets.only(
left: 18.0,
top: 18,
),
child: Card(
color: Colors.grey[900],
shape: RoundedRectangleBorder(
side: const BorderSide(color: Color(0xff384A62), width: 1),
borderRadius: BorderRadius.circular(10),
),
child: Container(
width: 350,
height: 151,
color: Colors.white,
child: Row(
children: [
Center(
child: Padding(
padding: const EdgeInsets.all(10),
child: Expanded(
child: Image.asset(
image1,
width: 100,
height: 100,
),
flex: 2,
),
),
),
Expanded(
child: Container(
alignment: Alignment.topLeft,
child: Padding(
padding: const EdgeInsets.only(top: 38.0),
child: Column(
children: [
const Expanded(
flex: 5,
child: ListTile(
title: Text(
"Genova",
style: TextStyle(
color: Color(0xff384A62),
fontSize: 20,
fontWeight: FontWeight.w400),
),
),
),
Expanded(
flex: 5,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
const SizedBox(
width: 8,
),
TextButton.icon(
style: TextButton.styleFrom(
textStyle:
const TextStyle(color: Colors.white),
backgroundColor: const Color(0xffFF0000),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6.0),
),
),
onPressed: () => {},
icon: const Icon(
Icons.power_off,
color: Colors.white,
),
label: const Text(
'DUTY SIGN OFF',
style: TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.w400),
),
),
const SizedBox(
width: 8,
),
],
),
),
const SizedBox(
width: 8,
),
],
),
),
),
),
],
),
),
elevation: 0,
margin: const EdgeInsets.all(10),
),
),
);
}
}

How to display array of image from firestore in listview flutter?

I want to display of image in listview which read data from firestore. I declare attribure image as array type.Here is my collection.
When i run the code, the image only display the first index of array and the second will read the first index of array like this. supposedly the second slide of image, it will display the second index of array from firestore.
Here is my code.
import 'package:carousel_pro/carousel_pro.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:fyp/shared/Loading.dart';
import 'package:google_fonts/google_fonts.dart';
class ListTask extends StatefulWidget {
#override
_ListTaskState createState() => _ListTaskState();
}
final FirebaseAuth auth = FirebaseAuth.instance;
Stream<QuerySnapshot> getUserRd(BuildContext context) async* {
final FirebaseUser rd = await auth.currentUser();
yield* Firestore.instance.collection("Task").where('uid',isEqualTo: rd.uid).snapshots();
}
class _ListTaskState extends State<ListTask> {
List<NetworkImage> _listOfImages = <NetworkImage>[];
#override
Widget build(BuildContext context) {
return Container(
child: StreamBuilder(
stream: getUserRd(context),
builder: (context, snapshot){
if (snapshot.hasError || !snapshot.hasData) {
return Loading();
} else{
return ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (BuildContext context, int index){
DocumentSnapshot ba = snapshot.data.documents[index];
_listOfImages =[];
for(int i =0; i < snapshot.data.documents[index].data['url'].length; i++){
_listOfImages.add(NetworkImage(snapshot.data.documents[index].data['url'][i]));
}
return Card(
child:ListTile(
title: Container(
alignment: Alignment.centerLeft,
child: Column(
children: <Widget>[
SizedBox(height: 5.0),
Container(alignment: Alignment.centerLeft,
child: Row(
children: [
Text("Sumber Aduan: ", style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
Text(ba['sumberAduan'], style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
],
),
),
SizedBox(height: 5.0),
Container(alignment: Alignment.centerLeft,
child: Row(
children: [
Text("Nombor Aduan: ", style: GoogleFonts.lato(fontWeight: FontWeight.bold)),
Text(ba['noAduan'], style: GoogleFonts.lato(fontWeight: FontWeight.bold)),
],
),
),
SizedBox(height: 5.0),
Container(alignment: Alignment.centerLeft,
child: Row(
children: [
Text("Status: ", style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
Text(ba['verified'], style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
],
),
),
Column(
children: [
Container(
margin: EdgeInsets.all(10.0),
height: 200,
decoration: BoxDecoration(
color: Colors.white
),
width: MediaQuery.of(context).size.width,
child: Carousel(
boxFit: BoxFit.cover,
images: _listOfImages,
autoplay: false,
indicatorBgPadding: 5.0,
dotPosition: DotPosition.bottomCenter,
animationCurve: Curves.fastLinearToSlowEaseIn,
animationDuration: Duration(milliseconds: 2000),
),
)
],
)
],
),
),
onTap: () {listAddress(ba['id']);}
)
);
});
}
}),
);
}
void listAddress(String id) {
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(10.0),
topRight: const Radius.circular(10.0)
)
),
context: context,
builder: (builder){
return StreamBuilder(
stream:Firestore.instance.collection("Task").document(id).snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Loading();
} else {
return Container(
height: 150,
child: Container(
padding: EdgeInsets.fromLTRB(20.0, 3, 30.0, 5.0),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Align(
alignment: Alignment.topLeft,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
alignment: Alignment.topLeft,
width: 220,
margin: EdgeInsets.only(top:26, left: 14),
child: Row(
children: [
Text("Kawasan: ", textAlign: TextAlign.left,style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
Text( snapshot.data['kawasan'], textAlign: TextAlign.left,style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
],
),
),
Container(
width: 220,
margin: EdgeInsets.only(top:4, left: 15),
child: Row(
children: [
Text("Nama Jalan :", textAlign: TextAlign.left,style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
Text(snapshot.data['naJalan'], textAlign: TextAlign.left,style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
],
),
),
Container(
width: 220,
margin: EdgeInsets.only(top:4, left: 15),
child: Row(
children: [
Text("Kategori : ", textAlign: TextAlign.left,style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
Text(snapshot.data['kategori'], textAlign: TextAlign.left,style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
],
),
),
],
),
)
],
),
],
),
),
);
}
}
);
}
);
}
}
can someone explain to me about this problem? is there anything that I missed out? someone help me please?
The code is correct. You have exactly the same links in your list url, that's why you're getting the same picture.

My stateless widget triggers an error message that I cannot assign

I have often found really quick and very competent help here. And hope you can help me again.
I have had an error message for three days, which I cannot get solved.
I explained the problem to you in a small video.
The link to the video is: "https://drive.google.com/file/d/1T9uOnEaNp5W6_kcO6eV9o64Fp3sRkB3f/view?usp=sharing"
I really hope you see the mistake I don't see!
This is the code of the Foodcard, which according to Flutter should cause the error:
The method '-' was called on null.
Receiver: null
Tried calling: -(30.0)
The relevant error-causing widget was:
FoodCard file:///C:/Users/stefa/AndroidStudioProjects/cronum_app_web%20-%20Kopie/lib/Components/ProviderComponents.dart:298:9
FoodCard:
class FoodCard extends StatelessWidget {
FoodCard({
#required this.description,
#required this.imagePath,
#required this.price,
#required this.foodName,
#required this.foodItem,
#required this.increaseCallback,
#required this.decreaseCallback,
this.count = 0,
});
final double radius = 40;
static double listViewHeight;
final double margin = 15;
final double containerHeight = 130;
final int count;
final String imagePath;
final String foodName;
final String price;
final String description;
final FoodItem foodItem;
final Function increaseCallback;
final Function decreaseCallback;
#override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 10, vertical: margin),
width: 220,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(radius),
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.topRight,
colors: ([
gradientColor1.withOpacity(opacityOfHeader),
primaryColor.withOpacity(opacityOfHeader),
gradientColor2.withOpacity(opacityOfHeader),
]),
),
boxShadow: [
BoxShadow(
blurRadius: 8,
color: Colors.black.withOpacity(0.3),
offset: Offset(5, 5),
),
],
color: Colors.white,
),
child: Column(
children: <Widget>[
Stack(
alignment: Alignment.center,
children: <Widget>[
Column(
children: <Widget>[
SizedBox(
height: listViewHeight - margin * 2 - containerHeight,
),
Container(
height: containerHeight,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(radius),
topRight: Radius.circular(radius),
bottomLeft: Radius.circular(radius),
bottomRight: Radius.circular(radius),
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.2),
offset: Offset(0, -5),
blurRadius: 8)
],
color: Colors.white),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 40),
child: Center(
child: Text(
foodName,
style: TextStyle(
color: Colors.black,
fontSize: 17,
fontWeight: FontWeight.w900,
),
),
),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: 20, vertical: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailPage(
foodItem: foodItem,
increaseCount: increaseCallback,
decreaseCount: decreaseCallback,
),
),
);
},
child: Container(
height: 30,
width: 80,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
offset: Offset(5, 5),
color: Colors.black.withOpacity(0.3),
blurRadius: 8)
],
color: buttonColor,
borderRadius: BorderRadius.circular(25),
),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 7, vertical: 5),
child: Center(
child: Text(
'Details',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
Container(
color: Colors.grey.withOpacity(0.5),
height: 25,
width: 1,
),
Container(
height: 30,
width: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
color: buttonColor,
boxShadow: [
BoxShadow(
blurRadius: 8,
color: Colors.black.withOpacity(0.3),
offset: Offset(5, 5),
),
],
),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: <Widget>[
InkWell(
onTap: decreaseCallback,
child: Container(
height: 22,
width: 22,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(5),
color: buttonColor,
),
child: Center(
child: Icon(
Icons.remove,
color: Colors.white,
size: 22,
),
),
),
),
Text(
count.toString(),
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w900,
),
),
InkWell(
onTap: increaseCallback,
child: Container(
height: 22,
width: 22,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(15),
color: Colors.white,
),
child: Center(
child: Icon(
Icons.add,
color: buttonColor,
size: 22,
),
),
),
),
],
),
),
],
),
),
],
),
),
],
),
Positioned(
top: 30,
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailPage(
foodItem: foodItem,
increaseCount: increaseCallback,
decreaseCount: decreaseCallback,
),
),
);
},
child: Image(
height: listViewHeight / 2,
width: listViewHeight / 2,
image: AssetImage(imagePath),
),
),
),
],
)
],
),
);
}
If it is not because of the FoodCard, the function with which I create the list of Foodcards could also be the problem.
I am amazed by the error message because it is so extremely non-specific. Before I automated the creation of the list, everything worked wonderfully.
List<Widget> buildEntdeckenCards() {
List<Widget> foodCardList = [];
for (FoodItem foodItem in top10) {
print(foodItem.foodName);
foodCardList.add(
FoodCard(
description: foodItem.description,
foodName: foodItem.foodName,
foodItem: foodItem,
price: foodItem.price,
imagePath: foodItem.imagePath,
decreaseCallback: () {
decreaseCount(foodItem);
},
increaseCallback: () {
increaseCount(foodItem);
},
),
);
}
return foodCardList;
}
I think your listViewHeight variable is null, and you are trying to use it in expression
SizedBox(height: listViewHeight - margin * 2 - containerHeight,),
I think that's why you see the following error The method '-' was called on null. Assign some value to listViewHeight before using it.

Flutter for loop with json sublist

I have a json which has a List value and I want to use this value under a gridview.builder,
I tried that with a "for" it just taking first item of first list and repeat that according to lenght of related index, such as for first one (878, 878) second one (878, 878, 878) etc.
What am I missing?
My goal is getting related genre ids(I will turn them names later) beside related cards but now it looks like that;
My code and json sample are below;
body: Container(
padding: EdgeInsets.all(4),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: mediaQueryData.orientation == Orientation.portrait ? 1 : 2,
childAspectRatio: mediaQueryData.orientation == Orientation.portrait ? MediaQuery.of(context).size.height/MediaQuery.of(context).size.width/1.05 : MediaQuery.of(context).size.width/(MediaQuery.of(context).size.height-29),
),
itemCount: snapshot.data.results.length,
itemBuilder: (context, index) {
return
Padding(
padding: const EdgeInsets.all(3.0),
child: Container(
child: Stack(
alignment: AlignmentDirectional.center,
children: <Widget>[
InkWell(
onTap: (){
setState(() {
firstRun = true;
String tempName;
tempName = _name;
String name = "imdbid=${snapshot.data.results[index].id}&language=${AppLocalizations.of(
context)
.translate(
'lan_code')}#$tempName";
saveNamedPreference(name).then((
bool committed) {Navigator.of(context).pushNamed(
MovieDetailPage.routeName);
});
});
},
child: Container(
width: MediaQuery.of(context).size.width,
alignment: Alignment.bottomLeft,
height: 245,
child: Stack(
alignment: Alignment.centerLeft,
children: <Widget>[
Card(
margin: EdgeInsets.only(top: 40),
elevation: 5,
child: Stack(
children: <Widget>[
Container(
padding:EdgeInsets.only(right:10.0),
alignment: Alignment.bottomRight,
child: CircularPercentIndicator(
radius: 40.0,
lineWidth: 5.0,
percent: snapshot.data.results[index].voteAverage/10,
center: Stack(
children: <Widget>[
Text(
snapshot.data.results[index].voteAverage.toString(),
style: TextStyle(
foreground: Paint()
..style = PaintingStyle.stroke
..strokeWidth = 3
..color = Colors.black,
),
),
new Text(snapshot.data.results[index].voteAverage.toString(),
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.amber,),),
],
),
progressColor: Colors.amber,
),
),
Container(
padding: mediaQueryData.orientation == Orientation.portrait ? EdgeInsets.only(left:170.0, top: 10) : EdgeInsets.only(left:140.0, top: 10),
alignment: Alignment.topLeft,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("${snapshot.data.results[index].title}",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14, color: Theme.of(context).brightness == Brightness.dark ? Colors.white : Colors.black,shadows: [
Shadow(color:Colors.grey,blurRadius: 0,offset: Offset(0,2)),
]),maxLines: 3, textAlign: TextAlign.left,),
Text("(${snapshot.data.results[index].releaseDate.toString().substring(0,4)})",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14, color: Theme.of(context).brightness == Brightness.dark ? Colors.white : Colors.black,shadows: [
Shadow(color:Colors.grey,blurRadius: 0,offset: Offset(0,2)),
]),maxLines: 1, textAlign: TextAlign.left),
Container(
width: 150,
height: 120,
child: GridView.builder(
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
childAspectRatio: 2/1,),
itemCount: snapshot.data.results[index].genreIds.length,
itemBuilder: (context, index) {
for(var i = 0; i < snapshot.data.results[index].genreIds.length; i++, index++){
print("${snapshot.data.results[index].genreIds.toString()}");
return Text("${snapshot.data.results[index].genreIds.toString()}",);
}
return Container();}),
),
],
),
),
],
),
),
Card(
elevation: 3,
child: Padding(
padding: mediaQueryData.orientation == Orientation.portrait ? const EdgeInsets.all(6.0) : const EdgeInsets.all(4.0),
child: Container(
alignment: Alignment.centerLeft,
width: mediaQueryData.orientation == Orientation.portrait ? 140 : 120,
height: 245,
child: ClipRRect(
borderRadius: BorderRadius.circular(15.0),
child: Image.network(
snapshot.data.results[index].posterPath != null ? "http://image.tmdb.org/t/p/w500/${snapshot
.data.results[index].posterPath}" : "https://i.hizliresim.com/bbn0VB.jpg", fit: BoxFit.contain,),
),
),
),
),
],
),
),
),
],
),
),
);
}
),
),
First, to avoid confusion, name your index variable differently in both builders, then you can easily see that you can use both indexes instead of the for loop :
GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(...),
itemCount: snapshot.data.results.length,
itemBuilder: (context, index) {
return GridView.builder(
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(...),
itemCount: snapshot.data.results[index].genreIds.length,
itemBuilder: (context, indexGenre) {
return Text("${snapshot.data.results[index].genreIds[indexGenre].toString()}");
},
return Container();
);
}
)
If you still want to use your loops in a more "programmative" way, then use the GridView default constructor directly (not the GridView.builder constructor) so that you can build the list of children "manually" :
GridView(
children: <Widget>[
for (var film in snapshot.data.results)
GridView(
children: <Widget>[
for (var genre in film.genreIds)
Text("${genre.toString()}")
],
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(...),
)
],
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(...),
),
Note that this last solution requires Dart > 2.3.

Inkwell for dummies

(...and with dummies I mean myself)
what am I doing wrong here?
I don't see any animation,
I tried to change the order of container/inkwell
because I saw somewhere that it creates some issue,
but I'm stuck. Can anyone help?
class CardButton extends StatelessWidget {
final String input;
CardButton({this.input});
Widget build(BuildContext context) {
return Container(
color: Colors.grey[100],
width: 50.0,
height: 50.0,
alignment: Alignment.center,
child: Material(
child: InkWell(
splashColor: Colors.amber,
onTap: draw(),
child: Text(input),
),
),
);
}
}
draw() {
//todo
}
thanks in advance
[edit 25/10]
I tried out some of the solutions proposed,
but doing so the widget where this one is 'nested' throw me an error,
writing the widget where I use the "CardButton" below:
class CardGrid extends StatelessWidget {
final List<String> cardList = [
'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
#override
Widget build(BuildContext context) {
return Container(
width: 300.0,
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
CardButton(input: cardList[0]),
CardButton(input: cardList[1]),
CardButton(input: cardList[2])
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
CardButton(input: cardList[3]),
CardButton(input: cardList[4]),
CardButton(input: cardList[5])
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
CardButton(input: cardList[6]),
CardButton(input: cardList[7]),
CardButton(input: cardList[8])
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
CardButton(input: cardList[9]),
CardButton(input: cardList[10]),
CardButton(input: cardList[11]),
CardButton(input: cardList[12])
],
),
],
),
);
}
}
I'm adding here the screenshot of the app, the first is with my original code,
the second (with the error) is with the "proposed" solution
You need to pass the onTap function without the braces:
child: InkWell(
splashColor: Colors.amber,
onTap: draw, // don't use braces here (except your function returns
// a reference to the actual onTap function.
child: Text(input),
),
Note that with the current layout only the inner Text element is animated. If you want the InkWell to cover the entire button area you'll have to reorder the widget tree to:
Material > InkWell > Container > Text
Widget build(BuildContext context) {
return Material(
color: Colors.grey[100],
child: InkWell(
splashColor: Colors.amber,
onTap: draw,
child: Container(
width: 100.0,
height: 100.0,
alignment: Alignment.center,
child: Text(input),
),
),
);
}

Resources