Card layouts - Flutter - mobile

I am trying to build a card using flutter, that looks like the concept shown below, but I am getting this instead.
Here's the card widget code in Dart:
#override
Widget build(BuildContext context) {
return Center(
child: Card(
margin: EdgeInsets.symmetric(horizontal: 14.0),
color: Colors.white,
elevation: 6.0,
child: InkWell(
splashColor: Colors.blue.withAlpha(30),
onLongPress: () {_copy();},
onTap: () {},
child: Container(
child: Padding(
padding: EdgeInsets.all(12.0),
child: Row(
children: <Widget>[
Text(widget.cardTitle),
Spacer(),
ButtonBar(
children: <Widget>[
new IconButton(
icon: Icon(CardsIcons.arrows_ccw, color: primaryDark,),
onPressed: () {_refresh();},
),
new IconButton(
icon: Icon(CardsIcons.heart_empty, color: Colors.redAccent,),
onPressed: () {_bookmark();},
),
],
),
SizedBox(height: 24.0,),
Text(
widget.cardContent,
),
],
),
),
),
),
),
);
}
This is the output I am getting currently
This is the desired output

Your structure is close but to get the layout you'll need to wrap everything in a Column widget first with children containing your row and then text.
The code below should be a good start, you'll just need to adjust padding/text style etc to get it like your mockup
#override
Widget build(BuildContext context) {
return Center(
child: Card(
margin: EdgeInsets.symmetric(horizontal: 14.0),
color: Colors.white,
elevation: 6.0,
child: InkWell(
splashColor: Colors.blue.withAlpha(30),
onLongPress: () {_copy();},
onTap: () {},
child: Container(
child: Padding(
padding: EdgeInsets.all(12.0),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Text(widget.cardTitle),
Spacer(),
ButtonBar(
children: <Widget>[
new IconButton(
icon: Icon(CardsIcons.arrows_ccw, color: primaryDark,),
onPressed: () {_refresh();},
),
new IconButton(
icon: Icon(CardsIcons.heart_empty, color: Colors.redAccent,),
onPressed: () {_bookmark();},
),
],
),
SizedBox(height: 24.0,),
],
),
Container(
child: Text(
widget.cardContent,
),
),
],
),
),
),
),
),
);
}

Related

how to show sub category data by category in flutter from sqlite db

import 'package:flutter/material.dart';
import 'package:stone_recipe_app/homepage.dart';
import 'package:stone_recipe_app/models/recipe.dart';
import 'package:share_plus/share_plus.dart';
class DetailedScreen extends StatelessWidget {
DetailedScreen({Key? key, required this.recipe, required this.index}) : super(key: key);
List<Recipe>? recipe;
int index;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: Row(
children: [
IconButton(
icon: const Icon(Icons.arrow_back_ios),
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => HomePage()));
},
),
Text(
'Back',
style: TextStyle(color: Color(0xff007AFF)),
)
],
),
iconTheme: const IconThemeData(color: Color(0xff007AFF)),
title: Center(
child: Text(
recipe![index].recipe_name,
style: TextStyle(color: Colors.black),
),
),
backgroundColor: Colors.white,
elevation: 0,
),
body: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: [
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(200),
),
child: Container(
width: 400,
height: 200,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(9.0)),
image: DecorationImage(
image: AssetImage("images/cook.jpg"),
fit: BoxFit.cover,
),
boxShadow: [
BoxShadow(
blurRadius: 5,
color: Colors.black,
)
],
),
),
),
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
const Icon(
Icons.file_download_sharp,
color: Colors.blue,
size: 40,
),
const Icon(
Icons.document_scanner,
size: 40,
),
IconButton(
onPressed: () {
Share.share(recipe![index].recipe_prep);
},
icon: const Icon(
Icons.share,
color: Colors.blue,
size: 40,
)),
const Icon(
Icons.favorite,
color: Colors.red,
size: 40,
),
]),
SizedBox(
height: 500,
child: Card(
elevation: 4,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Text(
'Ingredients',
style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
),
),
Column(
children: [
Text(recipe![index].recipe_ingrdients),
],
),
Center(
child: Text(
'Method',
style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
),
),
Text(
recipe![index].recipe_prep,
style: TextStyle(
fontSize: 20,
),
)
],
),
),
)
],
),
),
);
// Scaffold(
// appBar: AppBar(
// title: Text(recipe![index].recipe_name),
// ),
// body: Center(
// child: SingleChildScrollView(
// child: Column(
// mainAxisSize: MainAxisSize.min,
// children: [
// SelectableText(recipe![index].recipe_cat),
// Text(recipe![index].recipe_prep),
// Text(recipe![index].recipe_id.toString()),
// Text(recipe![index].recipe_ingrdients),
// Text(recipe![index].image_name),
// OutlinedButton(
// onPressed: () {
// Share.share(recipe![index].recipe_prep);
// },
// child: Text('Share'))
// ],
// ),
// ),
// ),
// );
}
}
import 'package:flutter/material.dart';
import 'package:stone_recipe_app/detailedScreen.dart';
import 'package:stone_recipe_app/models/recipe.dart';
import 'package:stone_recipe_app/services/db_services.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
#override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final dbservice = DataBaseService();
#override
void dispose() {
dbservice.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Recipe App')),
body: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: FutureBuilder<List<Recipe>>(
future: dbservice.getRecipe(),
builder: (context, snapshot) {
if (!snapshot.hasData) return Center(child: CircularProgressIndicator());
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data?.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailedScreen(
recipe: snapshot.data,
index: index,
)));
},
title: Text(snapshot.data![index].recipe_name, style: TextStyle(color: Colors.black)),
// trailing: Text(
// snapshot.data![index].recipe_cat,
// style: TextStyle(color: Colors.black),
// overflow: TextOverflow.fade,
// ),
);
},
);
},
)),
);
}
}
enter image description herei am trying to show data from sqlite db in flutter when user click on country category like india china after user click user navigate to other page which are recipe name related to chine or related to india i am trying to show data from sqlite db in flutter when user click on country category like india china after user click user navigate to other page which are recipe name related to chine or related to india enter image description here
add group_list_view: ^1.1.1 package in your pubspec.yaml file.
try below the example then implement it in your project
import 'package:flutter/material.dart';
import 'package:group_list_view/group_list_view.dart';
import 'package:group_listview_example/app_colors.dart';
void main() => runApp(MyApp());
Map<String, List> _elements = {
'Team A': ['Klay Lewis', 'Ehsan Woodard', 'River Bains'],
'Team B': ['Toyah Downs', 'Tyla Kane'],
'Team C': ['Marcus Romero', 'Farrah Parkes', 'Fay Lawson', 'Asif Mckay'],
'Team D': [
'Casey Zuniga',
'Ayisha Burn',
'Josie Hayden',
'Kenan Walls',
'Mario Powers'
],
'Team Q': ['Toyah Downs', 'Tyla Kane', 'Toyah Downs'],
};
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Group List View Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: Text('Group List View Demo'),
),
body: GroupListView(
sectionsCount: _elements.keys.toList().length,
countOfItemInSection: (int section) {
return _elements.values.toList()[section].length;
},
itemBuilder: _itemBuilder,
groupHeaderBuilder: (BuildContext context, int section) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8),
child: Text(
_elements.keys.toList()[section],
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
),
);
},
separatorBuilder: (context, index) => SizedBox(height: 10),
sectionSeparatorBuilder: (context, section) => SizedBox(height: 10),
),
),
);
}
Widget _itemBuilder(BuildContext context, IndexPath index) {
String user = _elements.values.toList()[index.section][index.index];
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Card(
elevation: 8,
child: ListTile(
contentPadding:
const EdgeInsets.symmetric(horizontal: 18, vertical: 10.0),
leading: CircleAvatar(
child: Text(
_getInitials(user),
style: TextStyle(color: Colors.white, fontSize: 18),
),
backgroundColor: _getAvatarColor(user),
),
title: Text(
_elements.values.toList()[index.section][index.index],
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w400),
),
trailing: Icon(Icons.arrow_forward_ios),
),
),
);
}
String _getInitials(String user) {
var buffer = StringBuffer();
var split = user.split(" ");
for (var s in split) buffer.write(s[0]);
return buffer.toString().substring(0, split.length);
}
Color _getAvatarColor(String user) {
return AppColors
.avatarColors[user.hashCode % AppColors.avatarColors.length];
}
}

how to update flutter UI according to firebase

I have this list of Post where user can like, comment and share.
Widget build(BuildContext context) {
return Container(
child: FutureBuilder(
future: _data,
builder: (_, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
} else {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (_, index) {
return Card(
elevation: 4,
child: Padding(
padding: EdgeInsets.only(left: 10.0, top: 10),
child: InkWell(
onTap: () => navigateToDetail(
snapshot.data[index],
snapshot.data[index].data["Userid"],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Row(
children: <Widget>[
Container(
width: 45,
height: 45,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(snapshot
.data[index].data["User Pic"]),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.all(
Radius.circular(50.5)),
),
),
Padding(
padding: EdgeInsets.only(left: 15),
child: Text(
snapshot.data[index].data["Name"],
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18),
),
),
],
),
Padding(
padding: EdgeInsets.only(left: 60, bottom: 10),
child: Text(
DateFormat.yMMMd().add_jm().format(
DateTime.parse(snapshot
.data[index].data["Creation Time"]
.toDate()
.toString())),
style: TextStyle(
color: Colors.black38, fontSize: 12),
),
),
Flexible(
child: Padding(
padding: EdgeInsets.only(left: 75, right: 15),
child: Text(
snapshot.data[index].data["Description"],
style: TextStyle(fontSize: 16),
),
),
),
Padding(
padding: EdgeInsets.only(
left: 75, top: 15, bottom: 8),
child: Text(
snapshot.data.length.toString() +
"Files uploaded",
style: TextStyle(
color: Colors.blueAccent,
fontSize: 14,
fontStyle: FontStyle.italic),
),
),
Divider(),
new Row(
children: <Widget>[
Expanded(
child: Row(
children: <Widget>[
IconButton(
onPressed: () {
Firestore.instance.runTransaction((transaction) async{
DocumentSnapshot freshData = await transaction.get(snapshot.data[index].reference);
await transaction.update(freshData.reference, {
'Likes':freshData['Likes']+1,
});
});
},
icon: Icon(Icons.favorite_border,
color: Colors.redAccent,
size: 23.0),
),
Text(snapshot.data[index].data["Likes"].toString())
],
),
),
Expanded(
child: IconButton(
onPressed: () {},
icon: Icon(
Icons.chat_bubble_outline,
color: Colors.blue,
size: 23.0,
),
),
),
Expanded(
child: IconButton(
onPressed: () {},
icon: Icon(
Icons.near_me,
color: Colors.blue,
size: 23.0,
),
),
),
],
),
],
),
),
),
);
});
}
}),
);
}
and have a Firestore like this :
storing likes in Post collection.
I need:
when the user press on like icon it will update the firestore as well as count in flutter UI.
what I have done so far:
it will only update the firestore and for updation in flutter UI I have to refresh the screen.
Thanks.
Update:
#override
void initState() {
super.initState();
_data = UserManagement().getPosts();
}
from UserManagement:
getPosts() async {
QuerySnapshot Qn = await Firestore.instance.collection("Posts").orderBy(
"Creation Time", descending: true).getDocuments();
return Qn.documents;
}
Just replace your FutureBuilder with StreamBuilder to get the stream whenever there is an update in your collection
Widget build(BuildContext context) {
return Container(
child: StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection("Posts").orderBy(
"Creation Time", descending: true).snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
} else {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (_, index) {
return Card(
elevation: 4,
child: Padding(
padding: EdgeInsets.only(left: 10.0, top: 10),
child: InkWell(
onTap: () => navigateToDetail(
snapshot.data[index],
snapshot.data[index].data["Userid"],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Row(
children: <Widget>[
Container(
width: 45,
height: 45,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(snapshot
.data[index].data["User Pic"]),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.all(
Radius.circular(50.5)),
),
),
Padding(
padding: EdgeInsets.only(left: 15),
child: Text(
snapshot.data[index].data["Name"],
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18),
),
),
],
),
Padding(
padding: EdgeInsets.only(left: 60, bottom: 10),
child: Text(
DateFormat.yMMMd().add_jm().format(
DateTime.parse(snapshot
.data[index].data["Creation Time"]
.toDate()
.toString())),
style: TextStyle(
color: Colors.black38, fontSize: 12),
),
),
Flexible(
child: Padding(
padding: EdgeInsets.only(left: 75, right: 15),
child: Text(
snapshot.data[index].data["Description"],
style: TextStyle(fontSize: 16),
),
),
),
Padding(
padding: EdgeInsets.only(
left: 75, top: 15, bottom: 8),
child: Text(
snapshot.data.length.toString() +
"Files uploaded",
style: TextStyle(
color: Colors.blueAccent,
fontSize: 14,
fontStyle: FontStyle.italic),
),
),
Divider(),
new Row(
children: <Widget>[
Expanded(
child: Row(
children: <Widget>[
IconButton(
onPressed: () {
Firestore.instance.runTransaction((transaction) async{
DocumentSnapshot freshData = await transaction.get(snapshot.data[index].reference);
await transaction.update(freshData.reference, {
'Likes':freshData['Likes']+1,
});
});
},
icon: Icon(Icons.favorite_border,
color: Colors.redAccent,
size: 23.0),
),
Text(snapshot.data[index].data["Likes"].toString())
],
),
),
Expanded(
child: IconButton(
onPressed: () {},
icon: Icon(
Icons.chat_bubble_outline,
color: Colors.blue,
size: 23.0,
),
),
),
Expanded(
child: IconButton(
onPressed: () {},
icon: Icon(
Icons.near_me,
color: Colors.blue,
size: 23.0,
),
),
),
],
),
],
),
),
),
);
});
}
}),
);
}
I assume you should use a StreamBuilder instead of a FutureBuilder.
StreamBuilders are like FutureBuilders that continuously update, depending on their stream.
You should also subscribe to the stream of the Firestore collection, instead of getting it only once.
Instead of getPosts maybe use this:
Stream<QuerySnapshot> getPostsStream() {
return Firestore.instance.collection("Posts").orderBy(
"Creation Time", descending: true).snapshots();
}
And change your FutureBuilder to a StreamBuilder:
StreamBuilder<QuerySnapshot>(
stream: getPostsStream(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
} else {
final List<DocumentSnapshot> documents = snapshot.data.documents;
// use as documents[index].
// ....
}
},
),

Why can't I scroll my list when I have carousels above it?

I created a homepage containing horizontal carousels, and under this carousel I created a vertical scrolling list,
I don't know why, but my vertical list doesn't scroll, can anyone have any idea why? I would like vertical scrolling to scroll through everything, both carousels and lists
my code:
#override
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;
return StoreConnector<AppState, OrdersScreenProps>(
converter: (store) => mapStateToProps(store),
onInitialBuild: (props) => this.handleInitialBuild(props),
builder: (context, props) {
List<Order> data = props.listResponse.data;
bool loading = props.listResponse.loading;
Widget body;
if (loading) {
body = Center(
child: CircularProgressIndicator(),
);
} else {
body =
Container(
height: 150.0,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: data.length,
itemBuilder: (context, i) {
Order order = data[i];
return GestureDetector(
onTap: () {
props.getOrderDetails(order.id);
Navigator.pushNamed(context, AppRoutes.orderDetails);
},
child: Container(
margin: EdgeInsets.all(5.0),
width: 210.0,
child: Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Positioned(
bottom: 15.0,
child: Container(
height: 120.0,
width: 200.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset(0.0, 2.0),
blurRadius: 6.0,
),
],
),
child: Padding(
padding: EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
order.title,
style: TextStyle(
fontSize: 22.0,
fontWeight: FontWeight.w600,
letterSpacing: 1.2),
),
Text(
order.city,
style: TextStyle(color: Colors.grey),
)
],
),
),
),
),
],
),
),
);
},
),
),
ListView.separated(
scrollDirection: Axis.vertical,
shrinkWrap: true,
padding: const EdgeInsets.all(10.0),
itemCount: data.length,
separatorBuilder: (context, index) => Divider(),
itemBuilder: (context, i) {
Order order = data[i];
return Card(
child: ListTile(
isThreeLine: true,
contentPadding: EdgeInsets.all(25.0),
leading: CircleAvatar(
child: Icon(Icons.person),
foregroundColor: Colors.white,
backgroundColor: Colors.green),
title: Text(
order.title,
style: TextStyle(
fontSize: 24.0, fontWeight: FontWeight.bold),
),
subtitle: Text(order.city),
trailing: Icon(Icons.arrow_forward_ios),
dense: true,
onTap: () {
props.getOrderDetails(order.id);
Navigator.pushNamed(context, AppRoutes.orderDetails);
},
));
},
)
],
);
}
return Scaffold(
// resizeToAvoidBottomInset: false,
backgroundColor: Colors.white,
appBar: PreferredSize(
preferredSize: Size.fromHeight(height * 0.15),
child: AppBar(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.vertical(bottom: Radius.circular(10))),
title: Image(
image: AssetImage('assets/images/logo.png'),
height: 60.0,
),
],
),
),
body: SingleChildScrollView(child: body,),
),
);
},
);
thanks for any help in advance :)
Try adding physics: ClampingScrollPhysics() or physics: BouncingScrollPhysics() on your second/vertical ListView
Also, your Widget body contains a Container and a ListView.separated widget. Wrap it in a column like below code:
Widget body = Column(
children: <Widget>[
Container(
height: 150.0,
child: ListView.builder(
//rest of your code
),
),
ListView.builder(
physics: ClampingScrollPhysics(),
//rest of your code
),
],
);
Then add it to your Scaffold
return Scaffold(
body: SingleChildScrollView(
child: body,
),
);

Flutter: Building a Cupertino Picker that shows rows containing 2 widgets, from looping through a Map

I've created a picker that displays a Icon and a String, next to each other. The pickers items are taken from a Map I created that contains Key: String and Value: Icon.
In my code right now, I'm using the Cupertino Picker and adding children: [ Row(Icon + String)] but that's quite bad if I want to update them.
I was trying to get a loop going to generate those rows + children but I can't figure out how.
Could someone show me the way or perhaps a more efficient way of getting this result? I'm thinking Extracting row and creating a constructor to input the icon and string, but I'm sure there's a better way...
Here's the code:
Expanded(
child: CupertinoPicker(
itemExtent: 40,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[0],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[0],
style:
TextStyle(color: Colors.white70),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[1],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[1],
style:
TextStyle(color: Colors.white70),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[2],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[2],
style:
TextStyle(color: Colors.white70),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[3],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[3],
style:
TextStyle(color: Colors.white70),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[4],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[4],
style:
TextStyle(color: Colors.white70),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[5],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[5],
style:
TextStyle(color: Colors.white70),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[6],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[6],
style:
TextStyle(color: Colors.white70),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[7],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[7],
style:
TextStyle(color: Colors.white70),
),
)
],
)
],
onSelectedItemChanged: (int index) {
print('good boi');
},
looping: true,
backgroundColor: Color(0xff2e3032),
),
),
How it looks like:
You can copy paste run full code below
You can use control-flow-collections
code snippet
children: <Widget>[
for (var i = 0;
i < BuildingProblem.problemListIcons.length;
i++)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[i],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[i],
style: TextStyle(color: Colors.white70),
),
)
],
),
],
working demo
You need to add file analysis_options.yaml to root of your project and the following line
analyzer:
enable-experiment:
- control-flow-collections
full code
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class BuildingProblem {
static List<Icon> problemListIcons = [];
static List<String> problemListNames = [];
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
void initState() {
BuildingProblem.problemListIcons.add(Icon(Icons.add));
BuildingProblem.problemListIcons.add(Icon(Icons.cast));
BuildingProblem.problemListNames.add("add");
BuildingProblem.problemListNames.add("cast");
// TODO: implement initState
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: CupertinoPicker(
itemExtent: 40,
children: <Widget>[
for (var i = 0;
i < BuildingProblem.problemListIcons.length;
i++)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
BuildingProblem.problemListIcons[i],
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
BuildingProblem.problemListNames[i],
style: TextStyle(color: Colors.white70),
),
)
],
),
],
onSelectedItemChanged: (int index) {
print('good boi');
},
looping: true,
backgroundColor: Color(0xff2e3032),
),
),
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}

Flutter - Position list view below another widget

I'm starting with Flutter, and I came across a layout with which I'm having trouble building, below a visual example:
I already tried something like:
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Welcome to Flutter',
home: new Scaffold(
appBar: new AppBar(
title: new Text('App'),
),
body: new Column(
children: <Widget>[
new Text('LISTA',
style: new TextStyle(
fontSize: 15.2,
fontWeight: FontWeight.bold,
)
),
new Container(
height: 200.0,
child: new ListView(
children: <Widget>[
new RaisedButton(
onPressed: null,
child: new Text("text button"),
),
new Padding(padding: new EdgeInsets.all(5.00)),
new RaisedButton(
onPressed: null,
child: new Text("text button 2"),
)
],
),
)
]
)
),
);
}
}
But for Container it needs a height, and I need it to take up the rest of the screen.
new Column(
children: <Widget>[
new Text('LISTA', style: new TextStyle(
fontSize: 15.2,
fontWeight: FontWeight.bold,
)),
new Expanded(
child: new Container(
decoration: new BoxDecoration(color: Colors.blue),
child: new ListView(
children: <Widget>[
new RaisedButton(
onPressed: null,
child: new Text("text button"),
),
new Padding(padding: new EdgeInsets.all(5.00)),
new RaisedButton(
onPressed: null,
child: new Text("text button 2"),
)
],
),
)
)
]
)

Resources