Related
I am trying to recreate the main page of Spotify. At first I wasn't able to make my navigation bar transparent then I learned that I should use extendBody: true property. It worked and I got a transparent navigation bar but now it seems like it changed the space between the items on the screen and I am clueless at this point. This is the part where I added extendBody property:
#override
Widget build(BuildContext context) {
return Scaffold(
extendBody: true,
appBar: AppBar(
backgroundColor: Color(0xFF212121),
title: Text("Spotify", style: TextStyle(fontFamily: 'Work Sans', fontWeight: FontWeight.bold)),
elevation: 0,
actions: [
IconButton(onPressed: (){}, icon: Icon(Icons.notifications_outlined)),
IconButton(onPressed: (){}, icon: Icon(Icons.history)),
IconButton(onPressed: (){}, icon: Icon(Icons.settings)),
],
),
And this is the part that forms gridlist and the problematic part:
FutureBuilder<List<GridListe>>(
future: gridListeyiGetir(),
builder: (context, snapshot){
if(snapshot.hasData){
var gridListe = snapshot.data;
return Padding(
padding: const EdgeInsets.only(top: 15),
child: GridView.builder(
shrinkWrap: true,
itemCount: gridListe!.length,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2, childAspectRatio: 3/1),
itemBuilder: (context, index){
var list = gridListe[index];
return Card(
semanticContainer: true,
color: Color(0xFF535353),
child: Row(
children: [
Image.asset("resimler/${list.listeResmi}", fit: BoxFit.fitHeight),
Padding(
padding: const EdgeInsets.only(left: 5),
child: Text(list.listeAdi, style:TextStyle(color: Colors.white,fontFamily: 'Work Sans' ,fontWeight: FontWeight.bold) , ),
),
],
),
);
}
),
);
}else{
return const Center();
}
},
),
Padding(
padding: const EdgeInsets.only(right: 280),
child: const Text("Made For You", style: TextStyle(color: Colors.white, fontFamily: 'Work Sans',fontWeight: FontWeight.bold, fontSize: 15)),
),
Padding(
padding: const EdgeInsets.only(top: 10),
child: SizedBox(
height: 180,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
SizedBox(
width: 160,
child: Card(
elevation: 0,
color: Color(0xFF212121),
child:
Column(mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Image.asset("resimler/dailymix1.jpg"),
Text("Daily Mix 1", style: TextStyle(color: Colors.white, fontFamily: "Work Sans", fontWeight: FontWeight.bold), ),
],
),
),
),
As can be seen in the images the grid list and "Made For You" text should be somewhat close to eachother however its not the case.
when extendBody:false
when extendBody:true
In my list view in a Flutter project, I need to show items i.e. pieces of text that are stored in a List variable. Each item (i.e. piece of text) will have rounded borders but the length of each item will vary according to the number of characters in the text. And on tapping each of the list item i.e. the piece of text, some action will take place.
Following is an image showing how the output should be:
Currently each list item takes the maximum size of the horizontally available space and text is aligned in the middle. But I want the background of each list item to be just containing the piece of text and not to be the full size horizontally and then text should be in the middle of the background. Current result is in the following image.
Code:
final List<String> names = <String>['Topic 1', 'Topic 2 ', 'Topic 3', 'Topic 4', 'Topic 5'];
ListView.builder(
shrinkWrap: true,
padding: const EdgeInsets.all(8),
itemCount: names.length,
itemBuilder: (BuildContext context, int index) {
return Container(
height: 50,
margin: EdgeInsets.all(2),
// color: msgCount[index]>=10? Colors.blue[400] msgCount[index]>3? Colors.blue[100]: Colors.grey,
child: Container(
child: Padding(
padding:EdgeInsets.fromLTRB(3, 0,0,0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children:[
Expanded(
child: TextButton(
onPressed: () {
print("Do something!");
},
style: ButtonStyle(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
minimumSize:MaterialStateProperty.all(Size(double.infinity, 14)),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40.0)),
),
backgroundColor:
MaterialStateProperty.all(
Colors.white
)),
child:Text('${names[index]} ',
style: TextStyle(fontSize: 18),
textAlign: TextAlign.left,
),
),
),
]
),
),
),
);
}
)
How can I achieve the list items to be as in the 1st screenshot ?
EDIT:
The above list view is inside the following code i.e. the following code should be appended to the above code and necessary brackets should be suffixed.
SingleChildScrollView(
// child: Container(
// padding: const EdgeInsets.only(top: 80, left: 24, right: 24),
child:Container(
height: MediaQuery.of(context).size.height, // or something simular :)
child: Column(
children: [
Text('Select a Topich000'),
EDIT2:
I am pasting the full code (i.e. not only the list view related code as the list view is inside other code snippet) from my application below.
So when you post answer, make sure that you use the format of my full code below:
final List<String> names = <String>['Topic 1', 'Topic 2 ', 'Topic 3', 'Topic 4', 'Topic 5'];
return Scaffold(
appBar: AppBar(
systemOverlayStyle: SystemUiOverlayStyle.light,
title: const Text('Topics'),
),
body: SingleChildScrollView(
child:Container(
height: MediaQuery.of(context).size.height, // or something simular :)
child: Column(
children: [
Text('Select a Topic'),
Expanded(
child: ListView.builder(
shrinkWrap: true,
padding: const EdgeInsets.all(8),
itemCount: names.length,
itemBuilder: (BuildContext context, int index) {
return Container(
height: 50,
margin: EdgeInsets.all(2),
child: Container(
child: Padding(
padding:EdgeInsets.fromLTRB(3, 0,0,0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children:[
Expanded(
child: TextButton(
onPressed: () {
print("Do something !");
Navigator.of(context).pushNamed("/subtopicScreen", arguments: {'index_found': index+1,
'uploadable_image_path':uploadable_image_path });
},
// );
style: ButtonStyle(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
minimumSize:MaterialStateProperty.all(Size(double.infinity, 14)),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40.0)),
),
backgroundColor:
MaterialStateProperty.all(
//Colors.green[900]
Colors.white
)),
child:Text('${names[index]} ',
style: TextStyle(fontSize: 18),
textAlign: TextAlign.left,
),
),
),
]
),
),
),
);
}
)
)
],
),
),
// ),
),
bottomNavigationBar: BottomAppBar(
child: Container(
height: 35.0,
width: double.maxFinite,
/*decoration: BoxDecoration(
color: Colors.deepOrange,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
),*/
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
//IconButton(icon: Icon(Icons.chat), onPressed: (){ },),
InkWell(
onTap: () {
//Navigator.pushNamed(context, "YourRoute");
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => topicScreen(),
),
);
},
child: TextButton(
child: Padding(
padding: const EdgeInsets.only(left: 10.0, right: 10.0),
child: Text('..',
style: TextStyle(
color: Colors.white,
// backgroundColor: Colors.blue,
fontSize: 14,
fontWeight: FontWeight.w500)),
),
style: TextButton.styleFrom(
primary: Colors.teal,
backgroundColor: Colors.blue,
onSurface: Colors.yellow,
side: BorderSide(color: Colors.teal, width: 2),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(25))),
),
onPressed: () {
print('Pressed');
},
),
),
],
),
),
),
);
}
Try removing the Expanded widget and remove minimumSize:MaterialStateProperty.all(Size(double.infinity, 14)) from your TextButton Widget.
Code:
ListView.builder(
shrinkWrap: true,
padding: const EdgeInsets.all(8),
itemCount: names.length,
itemBuilder: (BuildContext context, int index) {
return Container(
height: 50,
margin: EdgeInsets.all(2),
// color: msgCount[index]>=10? Colors.blue[400] msgCount[index]>3? Colors.blue[100]: Colors.grey,
child: Container(
child: Padding(
padding: EdgeInsets.fromLTRB(3, 0, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextButton(
onPressed: () {
print("Do something!");
},
style: ButtonStyle(
tapTargetSize:
MaterialTapTargetSize.shrinkWrap,
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(40.0)),
),
backgroundColor: MaterialStateProperty.all(
Colors.white)),
child: Text(
'${names[index]} ',
style: TextStyle(fontSize: 18),
textAlign: TextAlign.left,
),
),
]),
),
),
);
})
Try below code and used UnconstrainedBox.
UnconstrainedBox means render at its natural size.
Your List:
List list = [
'Science',
'Mathematics',
'English',
'Mental Ability',
];
Your Widget:
ListView.builder(
itemCount: list.length,
itemBuilder: (BuildContext context, int index) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
UnconstrainedBox(
child: Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.all(4),
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey,
),
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
),
child: InkWell(
onTap: () {
print('You Tapped on ${list[index]} subject');
},
child: Text(
list[index],
),
),
),
),
],
);
},
);
Result Screen->
You should try giving the widget in the builder method of the ListView.builder widget a height, specifically to your Container.
itemBuilder: (BuildContext context, int index) {
return Container(
height: 50,
width: <your width here> <<<<<------
EDIT:
Working code.
final names = <String>[
'Topic 1',
'Topic 2 ',
'Topic 3',
'Topic 4',
'Topic 5'
];
return Scaffold(
appBar: AppBar(
systemOverlayStyle: SystemUiOverlayStyle.light,
title: const Text('Topics'),
),
body: SingleChildScrollView(
child: SizedBox(
height: MediaQuery.of(context).size.height, // or something simular :)
child: Column(
children: [
const Text('Select a Topic'),
Expanded(
child: ListView.builder(
shrinkWrap: true,
padding: const EdgeInsets.all(8),
itemCount: names.length,
itemBuilder: (BuildContext context, int index) {
return Container(
height: 50,
width: 100,
margin: const EdgeInsets.all(2),
padding: const EdgeInsets.fromLTRB(3, 0, 0, 0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
TextButton(
onPressed: () {
print("Do something !");
// Navigator.of(context).pushNamed("/subtopicScreen", arguments: {'index_found': index+1,
// 'uploadable_image_path':uploadable_image_path });
},
// );
style: ButtonStyle(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
minimumSize: MaterialStateProperty.all(
const Size.fromWidth(100),
),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
40,
),
),
),
backgroundColor: MaterialStateProperty.all(
//Colors.green[900]
Colors.white,
),
),
child: Text(
'${names[index]} ',
style: const TextStyle(fontSize: 18),
textAlign: TextAlign.left,
),
),
],
),
);
},
),
)
],
),
),
// ),
),
bottomNavigationBar: BottomAppBar(
child: Container(
height: 35.0,
width: double.maxFinite,
/*decoration: BoxDecoration(
color: Colors.deepOrange,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
),*/
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
//IconButton(icon: Icon(Icons.chat), onPressed: (){ },),
InkWell(
onTap: () {
//Navigator.pushNamed(context, "YourRoute");
},
child: TextButton(
child: Padding(
padding: const EdgeInsets.only(left: 10.0, right: 10.0),
child: Text('..',
style: TextStyle(
color: Colors.white,
// backgroundColor: Colors.blue,
fontSize: 14,
fontWeight: FontWeight.w500)),
),
style: TextButton.styleFrom(
primary: Colors.teal,
backgroundColor: Colors.blue,
onSurface: Colors.yellow,
side: BorderSide(color: Colors.teal, width: 2),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(25))),
),
onPressed: () {
print('Pressed');
},
),
),
],
),
),
),
);
My listview widget is overflowed over another widget like the below screen.
Here is my full code.
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:propsoft/utils/dotted_decor.dart';
import '../../utils/app_theme.dart';
import '../../widget/elevated_icon_button_widget.dart';
import '../../widget/helper_utils.dart';
import '../../widget/label_widget.dart';
import 'create_user_logic.dart';
class CreateUserPage extends GetView<CreateUserLogic> {
final logic = Get.find<CreateUserLogic>();
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: customAppbar(),
body: SafeArea(child: getBodyDetails()),
);
}
Widget getBodyDetails() {
return Column(
children: [
getSearchWidget(),
DefaultTabController(
length: 2,
child: Expanded(
child: Column(
children: [getTabBar(), getTabVarView()],
),
),
),
],
);
}
Widget getTabBar() {
return TabBar(
indicator: UnderlineTabIndicator(
borderSide: BorderSide(width: 2.0, color: AppTheme.colors.black)),
labelColor: AppTheme.colors.black,
unselectedLabelColor: AppTheme.colors.gray,
indicatorSize: TabBarIndicatorSize.tab,
tabs: const [
Tab(text: "Users"),
Tab(
text: 'Status',
),
],
);
}
Widget getTabVarView() {
return Expanded(
child: TabBarView(
children: [
usersList(),
const Center(
child: Text("Status"),
),
]),
);
}
Widget usersList() {
return Column(
children: [
Expanded(
child: Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 22, horizontal: 16),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: DottedDecoration(
color: AppTheme.colors.darkBlue, shape: Shape.circle),
child: Icon(
Icons.add,
color: AppTheme.colors.darkBlue,
),
),
const SizedBox(
width: 20,
),
PLabel(
text: "Invite New Users",
enumFontWeight: PSFontWeight.bold,
textColor: AppTheme.colors.darkBlue,
)
],
),
),
Expanded(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder: (context, position) {
return InkWell(
onTap: () {},
child: Container(
margin:
const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
child: Row(
children: [
PIconButton(
backgroundColor: AppTheme.colors.lightBlue,
icon: const PLabel(
fontSize: 22,
text: "HT",
),
),
const SizedBox(
width: 16,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
PLabel(text: "My Contact List"),
SizedBox(
height: 4,
),
PLabel(text: "Activated"),
],
)
],
),
),
);
},
itemCount: 10,
),
)
],
),
),
],
);
}
Widget getSearchWidget() {
return Container(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Expanded(
child: TextField(
controller: controller.searchController,
onChanged: (query) {
controller.filterSearchResult(query);
},
decoration: InputDecoration(
prefixIcon: const Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(4)),
labelText: "Search for a user",
)),
)
],
));
}
AppBar customAppbar() {
return AppBar(
actions: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: InkWell(
onTap: () {},
child: PLabel(
text: "Save",
fontSize: 18,
textColor: AppTheme.colors.darkBlue,
)),
),
)
],
leading: IconButton(
icon: getSVGImage("assets/images/cross.svg"),
onPressed: () {
Get.back();
},
),
leadingWidth: 40,
title: const PLabel(
text: "Users & Group",
fontSize: 22,
),
backgroundColor: AppTheme.colors.white,
elevation: 0);
}
}
I have worked on your code....its work fine only...
Things changed... instead of PLabel Widget I have used Text Widget and Instead of PIconButton Widget I have used normal Icon Widget.... take my code as reference only...because I have changed your icons because of not having getSVGImage package and some other package.. And attaching image for your reference
Working example:
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: customAppbar(),
body: SafeArea(child: getBodyDetails()),
);
}
Widget getBodyDetails() {
return Column(
children: [
getSearchWidget(),
DefaultTabController(
length: 2,
child: Expanded(
child: Column(
children: [getTabBar(), getTabVarView()],
),
),
),
],
);
}
Widget getTabBar() {
return const TabBar(
indicator: UnderlineTabIndicator(
borderSide: BorderSide(width: 2.0, color: Colors.black)),
labelColor: Colors.black,
unselectedLabelColor: Colors.grey,
indicatorSize: TabBarIndicatorSize.tab,
tabs: [
Tab(text: "Users"),
Tab(
text: 'Status',
),
],
);
}
Widget getTabVarView() {
return Expanded(
child: TabBarView(
children: [
usersList(),
const Center(
child: Text("Status"),
),
]),
);
}
Widget usersList() {
return Column(
children: [
Expanded(
child: Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 22, horizontal: 16),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.blueAccent, shape: BoxShape.circle),
child: Icon(
Icons.add,
color: Colors.black12,
),
),
const SizedBox(
width: 20,
),
Text(
"Invite New Users",
)
],
),
),
Expanded(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder: (context, position) {
return InkWell(
onTap: () {},
child: Container(
margin:
const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
child: Row(
children: [
IconButton(
color: Colors.lightBlue,
icon : const Icon(
Icons.home,
),
onPressed: () { },
),
const SizedBox(
width: 16,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text("My Contact List"),
SizedBox(
height: 4,
),
Text("Activated"),
],
)
],
),
),
);
},
itemCount: 10,
),
)
],
),
),
],
);
}
Widget getSearchWidget() {
return Container(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Expanded(
child: TextField(
// controller: controller.searchController,
// onChanged: (query) {
// controller.filterSearchResult(query);
// },
decoration: InputDecoration(
prefixIcon: const Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(4)),
labelText: "Search for a user",
)),
)
],
));
}
AppBar customAppbar() {
return AppBar(
actions: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: InkWell(
onTap: () {},
child: Text(
"Save",
)),
),
)
],
leading: IconButton(
icon: Icon(Icons.book),
onPressed: () {
// Get.back();
},
),
leadingWidth: 40,
title: const Text(
"Users & Group",
),
backgroundColor: Colors.white,
elevation: 0);
}
I am stuck right now with the little app that I am trying to create.
The user when he will tap on an icon is supposed to get an alert dialog with 2 buttons (OK and Cancel), and in the body of the alert box, a Cupertino Picker. Below you will find the code. I am getting this error message.
Failed assertion: line 85 pos 15: 'children != null': is not true.
class Engage extends StatefulWidget {
Engage ({Key key}) : super(key:key);
#override
_EngageState createState() => _EngageState();
}
class _MyEngageState extends State<MyEngage> {
#override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey[350])),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(3.0),
child: Container(
// margin: const EdgeInsets.all(30.0),
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey[350])
),
child : Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
child: Column(
children: [
IconButton(
splashColor: Colors.lightGreenAccent,
icon : Image.asset('assets/icons/icon1',
height: iconHeighEngage,),
onPressed:(){
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('TEST'),
content: Container(
height: 350,
child: Column(
children: <Widget>[
CupertinoPicker(),
FlatButton(
child: Text("OK"),
onPressed: () {
Navigator.pop(context);
},
)
],
),
));
});
},
),
Text('TEST')],
),
),
Give it a try to this!
Padding(
padding: const EdgeInsets.all(3.0),
child: Container(
// margin: const EdgeInsets.all(30.0),
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey[350])),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
child: Column(
children: [
IconButton(
splashColor: Colors.lightGreenAccent,
icon: Icon(
Icons.add,
),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext ctx) {
return AlertDialog(
title: Text('My Titile'),
content: Container(
height: 350,
width: 350.0,
child: Column(
children: <Widget>[
CupertinoPicker(
itemExtent: 200.0,
onSelectedItemChanged:
(int value) {
print("Test");
},
children: <Widget>[
FlatButton(
child: Container(
color:
Colors.orangeAccent,
width: 350.0,
height: 160.0,
child: Center(
child: Text(
"OK",
style: TextStyle(
fontSize: 20.0),
)),
),
onPressed: () {
Navigator.pop(context);
},
)
],
),
],
),
),
);
},
);
},
),
Text('TEST')
],
),
),
],
),
),
)
Note: The problem was, you weren't passing the parameters of CupertinoPicker()
EDIT :
First Initialize
int selected = 0;
and then:
Padding(
padding: const EdgeInsets.all(3.0),
child: Container(
padding: const EdgeInsets.all(10.0),
decoration:
BoxDecoration(border: Border.all(color: Colors.grey[350])),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
child: Column(
children: [
IconButton(
splashColor: Colors.lightGreenAccent,
icon: Icon(
Icons.add,
),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext ctx) {
return StatefulBuilder(
builder: (context, setState) {
return AlertDialog(
backgroundColor: Colors.lightBlueAccent,
title: Text(
'My Dialog',
style: TextStyle(
color: Colors.white,
fontSize: 30.0,
fontWeight: FontWeight.bold,
),
),
content: Container(
height: 350.0,
width: 350.0,
child: Column(
children: <Widget>[
Expanded(
child: CupertinoPicker(
useMagnifier: true,
magnification: 1.5,
backgroundColor: Colors.white,
itemExtent: 40.0,
onSelectedItemChanged: (int index) {
print(selected);
setState(() {
selected = index;
});
print(selected);
},
children: <Widget>[
Text(
"Text 1",
style: TextStyle(
color: selected == 0
? Colors.blue
: Colors.black,
fontSize: 22.0),
),
Text(
"Text 2",
style: TextStyle(
color: selected == 1
? Colors.blue
: Colors.black,
fontSize: 22.0),
),
Text(
"Text 3",
style: TextStyle(
color: selected == 2
? Colors.blue
: Colors.black,
fontSize: 22.0),
),
],
),
)
],
),
),
);
},
);
},
);
},
),
Text('Add')
],
),
),
],
),
),
),
The code is tested and working pretty fine now!
how do i create a list builder that's going to return a row like in the picture or a list builder that goes horizontal axis until it finds the end of the screen and then goes next line please see this Image
Use a GridView.builder() to dynamically render as user scrolls.
Below example modified from this: https://www.kindacode.com/article/flutter-gridview-builder-example/
List<String> data = ["1", "2", "3", "4", "5", "6"];
return GridView.builder(
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200,
childAspectRatio: 3 / 2,
crossAxisSpacing: 20,
mainAxisSpacing: 20),
itemCount: data.length,
itemBuilder: (BuildContext ctx, index) {
// Add your card/widget/grid element here
return Container(
alignment: Alignment.center,
child: Text(data[index]),
decoration: BoxDecoration(
color: Colors.amber,
borderRadius: BorderRadius.circular(15),
),
);
},
);
check this out - it worked for me
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.teal,
body: SafeArea(
child: Row(
children: <Widget>[
SizedBox(width: 15),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Card(
color: Colors.white,
child: Center(
child: Padding(
padding: EdgeInsets.all(75.0),
child: Text(
'1',
style: TextStyle(fontSize: 40, color: Colors.black),
),
),
),
),
Card(
color: Colors.white,
child: Center(
child: Padding(
padding: EdgeInsets.all(75.0),
child: Text(
'3',
style: TextStyle(fontSize: 40, color: Colors.black),
),
),
),
),
Card(
color: Colors.white,
child: Center(
child: Padding(
padding: EdgeInsets.all(75.0),
child: Text(
'5',
style: TextStyle(fontSize: 40, color: Colors.black),
),
),
),
),
],
),
SizedBox(width: 15),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Card(
color: Colors.white,
child: Center(
child: Padding(
padding: EdgeInsets.all(75.0),
child: Text(
'2',
style: TextStyle(fontSize: 40, color: Colors.black),
),
),
),
),
Card(
color: Colors.white,
child: Center(
child: Padding(
padding: EdgeInsets.all(75.0),
child: Text(
'4',
style: TextStyle(fontSize: 40, color: Colors.black),
),
),
),
),
Card(
color: Colors.white,
child: Center(
child: Padding(
padding: EdgeInsets.all(75.0),
child: Text(
'6',
style: TextStyle(fontSize: 40, color: Colors.black),
),
),
),
),
],
),
],
),
)),
);
}
}