flutter inkwell onTap - list

so i have this page called screen1
its work fine and show the data
import 'package:flutter/material.dart';
import 'package:food_app/data/data.dart';
import 'package:food_app/views/home.dart';
class Screen1 extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("japanese recipes"),
backgroundColor: Colors.yellow,
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView.builder(
itemCount: data.length,
itemBuilder: (BuildContext context , int index) {
return Card(
child: ListTile(
leading: CircleAvatar(
backgroundColor: Colors.white,
child: Image.asset(data[index]["image"])),
title: Text(data[index]["name"]),
subtitle:Text(data[index]["about"]),
),
);
}
)
),
),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.yellow,
child: const Icon(Icons.home),
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => HomePage()));
},
),
);
}
}
and my list data is this , has name and image , about
List data = [
{"name": "Chicken-Zosui","image":"assets/recipeApi/Chicken-Zosui.jpg", "about": "Zosui is a comforting Japanese rice soup that works beautifully with pantry-ready ingredients like ready-cooked rice, eggs, and leftover ingredients. The easy template is flexible, yet you’re guaranteed a nourishing meal at the end of the day."},
{"name": "Miso-Salmon","image":"assets/recipeApi/Miso-Salmon.jpg", "about": "Known for its Omega-3 fatty acid, salmon is a great protein to have in the diet. For that reason alone, I always have frozen salmon fillets in my freezer. This Miso Salmon recipe is really simple to make. You just need to marinate the fish for 30 minutes, you’d get a flavorful fish to serve for dinner. We love it with Japanese ginger rice."},
{"name": "Spam-Onigirazu","image":"assets/recipeApi/Spam-Onigirazu.jpg", "about": "Eggs, ham, sushi rice, and nori sheet. That’s all you need to make this yummy Spam Onigirazu. I used a special mold to create a perfect shape for the rice sandwich, but you really don’t need one."},
{"name": "Sweet-Onion","image":"assets/recipeApi/Sweet-Onion.jpg", "about": "This Japanese Mixed Rice is a one-pot wonder! You can literally cook it with any seasonal ingredients or pantry items you have in the refrigerator. Think dried mushrooms, canned tuna, sweet potatoes, carrots, etc."},
{"name": "Vegan-Miso-Soup","image":"assets/recipeApi/Vegan-Miso-Soup.jpg", "about": " cannot live without miso soup. Luckily, you can make a really good bowl of miso soup with only pantry items like dried kombu, silken tofu, and dried wakame. You can even enjoy it plain! Packed with umami goodness, it’s hands-down the easiest soup anyone can pull off anytime."},
{"name": "Yaki-Onigiri","image":"assets/recipeApi/Yaki-Onigiri.jpg", "about": "Lightly brushed with savory soy sauce, these grilled Japanese rice balls are simply irresistible. It requires only rice, salt, and sweet and soy sauce (or my take, delicious Unagi Sauce! It can be a store-bought or my homemade recipe on the blog). You can make them plain or stuffed them with fun fillings such as canned salmon. They are so easy to make that you want to grill them up at home!"},
{"name": "Yaki-Udon","image":"assets/recipeApi/Yaki-Udon.jpg", "about": "Japanese udon noodles stir-fried with vegetables and your choice of protein, Yaki Udon is definitely a keeper when comes to easy pantry meal."},
];
i want to add inkwell so every time user click on name list it go to another page with image and text about it

The ListTile widgets themselves have an onTap event and do not require InkWell
return Card(
child: ListTile(
leading: CircleAvatar(
backgroundColor: Colors.white,
child: Image.asset(data[index]["image"])),
title: Text(data[index]["name"]),
subtitle:Text(data[index]["about"]),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => YourNewPage(name:data[index]["name"],image:data[index]["image"]),),
);
},
);

IN listTile use oneTap for going your detail page and use constractor for passing your data.
import 'package:flutter/material.dart';
import 'package:food_app/data/data.dart';
import 'package:food_app/views/home.dart';
class Screen1 extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("japanese recipes"),
backgroundColor: Colors.yellow,
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView.builder(
itemCount: data.length,
itemBuilder: (BuildContext context , int index) {
return Card(
child: ListTile(
onTap:(){
Navigator.push(
context,
MaterialPageRoute(builder: (context) => DetailsPage(name:data[index]["name"],image:data[index]["image"]),),
);}
leading: CircleAvatar(
backgroundColor: Colors.white,
child: Image.asset(data[index]["image"])),
title: Text(data[index]["name"]),
subtitle:Text(data[index]["about"]),
),
);
}
)
),
),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.yellow,
child: const Icon(Icons.home),
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => HomePage()));
},
),
);
}
}
The detail page will be like
import 'package:flutter/material.dart';
class DetailsPage extends StatefulWidget {
String name;
String image;
#override
_PatientListState createState() => _PatientListState();
}
class _PatientListState extends State<BloodDonateScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Deatils Page"),
),
body: SingleChildScrollView(
child: Container(
height: 600,
child: ListView.builder(
itemCount: 10,
itemBuilder: (BuildContext context, index) {
return Container(
width: 300,
height: 260,
padding: new EdgeInsets.all(10.0),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
color: Colors.red,
elevation: 10,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
leading: Icon(Icons.bloodtype, size: 40),
title: Text(
widget.name,
style: TextStyle(
fontSize: 20.0,
color: theme.changeColor? Colors.white: Colors.black)
),
],
),
],
),
),
);
},
),
),
),
);
}
);
}
}
Then in details page call your data with widget.name / widget.image

Related

How to decrease space of List in Page?

I am trying to insert a list in a row format into an initial page of an app but the UI of it shows too much spacing between. I actually got the UI off a youtube tutorial and was trying to implement its elements. How can I adjust my code accordingly to reduce the spacing as shown below?
Code:
class Firstpage extends StatefulWidget {
#override
_FirstpageState createState() => _FirstpageState();
}
class _FirstpageState extends State<Firstpage> {
int currentPage = 0;
List<Map<String, String>> splashData = [
{
"text": "Welcome to Tokoto, Let’s shop!",
},
{
"text":
"We help people conect with store \naround United State of America",
},
{
"text": "We show the easy way to shop. \nJust stay at home with us",
},
];
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(height: 80),
Container(
width: 340,
height: 250,
child:
new Image.asset('assets/images/trip.png', fit: BoxFit.fill),
),
Center(
child: Text("App", style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.w500,
color: Color(0xFF9a0e2a)
),),
),
SizedBox(height: 10),
Expanded(
child: PageView.builder(
onPageChanged: (value) {
setState(() {
currentPage = value;
});
},
itemCount: splashData.length,
itemBuilder: (context, index) => intro(
text: splashData[index]['text'],
),
),
),
Expanded(
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(
splashData.length,
(index) => buildDot(index: index),
),
),
]
)
),
DefaultButton(
text: "Sign Up",
press: () {
Navigator.push(context, MaterialPageRoute(builder: (context)=>Signup()));
},
),
SizedBox(height: 20),
DefaultButton(
text: "Login",
press: () {
Navigator.push(context, MaterialPageRoute(builder: (context)=>Signup()));
},
),
],
)
)
);
}
AnimatedContainer buildDot({int? index}) {
return AnimatedContainer(
duration: Duration(milliseconds: 200),
margin: EdgeInsets.only(right: 5),
height: 6,
width: currentPage == index ? 20 : 6,
decoration: BoxDecoration(
color: currentPage == index ? Color(0xFFeb1f48) : Color(0xFFD8D8D8),
borderRadius: BorderRadius.circular(3),
),
);
}
}
And just for reference, Class Intro is:
class intro extends StatelessWidget {
const intro({
Key? key,
this.text,
this.image,
}) : super(key: key);
final String? text, image;
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Text(
text!,
textAlign: TextAlign.center,
),
],
);
}
}
If your not using SingleChildScrollView and direct to Column used try Spacer() to have balance on the spacing or put flex to adjust the spacing between.
Spacer()
or
Spacer(flex: 1),
sample
Column(
children:[
Spacer(),
Container(
width: 340,
height: 250,
child:
new Image.asset('assets/images/trip.png', fit: BoxFit.fill),
),
Center(
child: Text("App", style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.w500,
color: Color(0xFF9a0e2a)
),),
),
Spacer(),
]),
you can reduce your spacing by adjusting your SizedBox()
if you notice there's SizedBox() without a child on your code, that's cause you have so much space on your screen.
and just FYI, you can use Spacer() or Expanded() to make empty spaces more flexible or dynamic toward the user's screen
but keep in mind that you can't use Spacer() or Expanded() if:
you have parents of scrollable with the same direction of the main axis of the corresponding Column or Row (for example you have SingleChildScrollView(child: Column(...)) then you cannot use Expanded on Column. Because the widget will have infinity main axis size, which will cause infinity divided by flex amount) TLDR: you can't use Expanded & Spacer on infinity main axis size
when using the Column / Row be careful with "maximum main axis size" (actually, Row and Column don't pass maximum main size to their children, that's why you will have OverFlow exception when trying to write very long long Text inside a Row without using SizedBox or Expanded or Container, etc.)

How to create list of pages and navigate to difference page at once

Here I have a list of id and title,
I would like to create pages. each page contains one sentences of title. Once click ok button it will navigate to next page of the list.
How can I do that within a single page?
I am a newbie but I would like to minimize my code,
it is a bit confusing.
Here are the images of my code.
import 'package:flutter/material.dart';
import 'package:starbucks/appLayout.dart';
import 'package:starbucks/appTheme.dart';
import 'package:starbucks/components/customAppBar.dart';
import 'package:provider/provider.dart';
import 'package:starbucks/pages/payment.dart';
import 'package:starbucks/providers/cartProvider.dart';
import 'package:starbucks/utils/data.dart';
class CartConfirm extends StatelessWidget {
const CartConfirm({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
final totalPrice = context.read<CartProvider>().totalPrice;
return Scaffold(
appBar: CustomAppbar(),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
alignment: Alignment.center,
width: 1024,
decoration: BoxDecoration(
border: Border.all(color: AppTheme.green),
borderRadius: BorderRadius.circular(5),
),
padding: const EdgeInsets.all(50),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"ราคารวม: " ,
style: TextStyle(color: Colors.white),
),
AppLayout.staticField(content: " $totalPrice "),
Text(
" บาท",
style: TextStyle(color: Colors.white),
),
],
),
),
Container(
width: 1024,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
AppLayout.button(title: "จ่ายด้วยบัตร", onPressed: () {}),
AppLayout.button(title: "จ่ายด้วยเงินสด", onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
Payment(id: id, title: title,),
));},),
],
),
),
],
),
),
);
}
}
static List<Payment> payment = [
Payment(
id: 1,
title: "กรุณาใส่เงิน",
),
Payment(
id: 2,
title: "ระบบกำลังตรวจนับเงิน",
),
Payment(
id: 3,
title: "กรุณารับบัตรคิวและเงินทอน",
),
Payment(
id: 4,
title: "ขอบคุณที่ใช้บริการ",
),
];

flutter The argument type 'List<dynamic>' can't be assigned

Hey guys I ran into a problem that I don't know how to resolve.
I have a Character class:
import 'package:flutter/material.dart';
class Character {
final String name;
final String imagePath;
final String description;
final List<Color> colors;
Character({
required this.name,
required this.imagePath,
required this.description,
required this.colors,
});
}
List characters = [
Character(
name: 'Kevin',
imagePath: 'assets/images/Kevin_minions.png',
description:
'Sir Kevin KBE (formerly known as Kevin) is one of the Minions and the protagonist in the film Minions. Kevin is a tall, two-eyed minion with sprout cut hair and is usually seen wearing his golf apparel. Kevin loves to make fun of and tease people or Minions, shown when he made fun of Jerry and teases him for being a coward. He loves playing golf and cricket. In the film Minions he is the leader of the trio in search of a new master. He truly cares about the well-being of the Minion tribe (which is dependent on them having a proper master).',
colors: [Colors.orange.shade200, Colors.deepOrange.shade400]),
Character(
name: "Agnes",
imagePath: "assets/images/Agnes_gru.png",
description:
"Agnes Gru it is one of Gru and Lucy's three adopted daughters, alongside her sisters Margo and Edith. She is the youngest child of the three sisters. She greatly adores unicorns, as shown on various occasions. Agnes is a little girl with dark brown eyes. Her long black hair is tied in an upwards ponytail with a red scrunchie. Most of the time, Agnes wears blue overalls over a yellow and brown striped t-shirt, and white sneakers with yellow socks. She also wears a white ballet outfit like Edith and Margo (at the ballet recital). For pajamas, Agnes wears a long blue nightshirt covered with teddy bears and polar bear slippers; her hair stays the same. On her birthday, Agnes is wearing a dress that resembles a princess riding a unicorn. The colors are similar to her regular outfit. She also wears a blue princess hat on her head.",
colors: [Colors.pink.shade200, Colors.redAccent.shade400]),
];
Also a Character info or detail page:
import 'package:flutter/material.dart';
import 'package:mimir_minions/models/character.dart';
import 'package:mimir_minions/styleguide.dart';
class CharacterDetailPage extends StatefulWidget {
final Character character;
const CharacterDetailPage({
Key? key,
required this.character,
}) : super(key: key);
#override
_CharacterDetailPageState createState() => _CharacterDetailPageState();
}
class _CharacterDetailPageState extends State<CharacterDetailPage> {
#override
Widget build(BuildContext context) {
final screenHeight = MediaQuery.of(context).size.height;
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: [
Hero(
tag: "background_${widget.character.name}",
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(35),
topRight: Radius.circular(35),
),
gradient: LinearGradient(
colors: widget.character.colors,
begin: Alignment.topRight,
end: Alignment.bottomLeft,
),
),
),
),
SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16.0, 56.0, 0, 0),
child: IconButton(
icon: Icon(
Icons.close,
),
iconSize: 48,
color: Colors.white.withOpacity(0.8),
onPressed: () {
Navigator.pop(context);
},
),
),
Align(
alignment: Alignment.topRight,
child: Hero(
tag: "image_${widget.character.name}",
child: Image.asset(
widget.character.imagePath,
height: screenHeight * 0.45,
),
),
),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 32.0, vertical: 8),
child: Hero(
tag: "name_${widget.character.name}",
child: Material(
color: Colors.transparent,
child: Container(
child: Text(widget.character.name,
style: AppTheme.heading)))),
),
Padding(
padding: const EdgeInsets.fromLTRB(16.0, 0, 32.0, 24.0),
child: Text(widget.character.description,
style: AppTheme.subHeading),
),
],
),
),
],
),
);
}
}
and a character widget page:
import 'package:flutter/material.dart';
import 'package:mimir_minions/models/character.dart';
import 'package:mimir_minions/pages/character_detail_page.dart';
import 'package:mimir_minions/styleguide.dart';
class CharacterWidget extends StatelessWidget {
const CharacterWidget({Key? key, required this.character}) : super(key: key);
final Character character;
#override
Widget build(BuildContext context) {
final screenHeight = MediaQuery.of(context).size.height;
final screenWidth = MediaQuery.of(context).size.width;
return InkWell(
onTap: () {
Navigator.push(
context,
PageRouteBuilder(
transitionDuration: Duration(milliseconds: 350),
pageBuilder: (context, _, __) => CharacterDetailPage(
character: characters,
),
),
);
},
child: Stack(
children: [
Align(
alignment: Alignment.bottomCenter,
child: Hero(
tag: "background_${characters[0].name}",
child: ClipPath(
clipper: CharacterCardBackgroundClipper(),
child: Container(
height: screenHeight * 0.6,
width: screenWidth * 0.9,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: characters[0].colors,
begin: Alignment.topRight,
end: Alignment.bottomLeft,
),
),
),
),
),
),
Align(
alignment: Alignment(0, -0.6),
child: Hero(
tag: "image_${characters[0].name}",
child: Image.asset(
characters[0].imagePath,
height: screenHeight * 0.55,
),
),
),
Padding(
padding: const EdgeInsets.only(left: 32, right: 8, bottom: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Hero(
tag: "name_${characters[0].name}",
child: Material(
color: Colors.transparent,
child: Container(
child: Text(characters[0].name,
style: AppTheme.heading)))),
Text('Tap to read more', style: AppTheme.subHeading),
],
),
)
],
),
);
}
}
class CharacterCardBackgroundClipper extends CustomClipper<Path> {
#override
Path getClip(Size size) {
Path clippedPath = Path();
double curveDistance = 40;
clippedPath.moveTo(0, size.height * 0.4);
clippedPath.lineTo(0, size.height - curveDistance);
clippedPath.quadraticBezierTo(
1, size.height - 1, 0 + curveDistance, size.height);
clippedPath.lineTo(size.width - curveDistance, size.height);
clippedPath.quadraticBezierTo(size.width + 1, size.height - 1, size.width,
size.height - curveDistance);
clippedPath.lineTo(size.width, 0 + curveDistance);
clippedPath.quadraticBezierTo(size.width - 1, 0,
size.width - curveDistance - 5, 0 + curveDistance / 3);
clippedPath.lineTo(curveDistance, size.height * 0.29);
clippedPath.quadraticBezierTo(
1, (size.height * 0.30) + 10, 0, size.height * 0.4);
return clippedPath;
}
#override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return true;
}
}
When I use the character as a list like character[0].name I have no problem. However, when I want to change it to the character so I have several character widgets on my first page it gives me an error that says
The argument type 'List' can't be assigned to the parameter
type 'Character'.dart(argument_type_not_assignable)
This is the link to my repo on Github
The error is pretty clear you are trying to use a List when Dart is expecting a single instance of Character.
I think what you are trying to achieve is a master/detail view.
You should have one CharacterList widget
class CharacterList extends StatelessWidget {
final List<Character> characters;
const CharacterList({Key? key, required this.characters}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemCount: characters.length, itemBuilder: (context, index) => CharacterWidget(character: characters[index])),
);
}
}
This ListView will be your master view and on any of the CharacterWidget they should take you to the detail view, but you should start using the character attribute instead of the characters list in your CharacterWidget
return InkWell(
onTap: () {
Navigator.push(
context,
PageRouteBuilder(
transitionDuration: Duration(milliseconds: 350),
pageBuilder: (context, _, __) => CharacterDetailPage(
character: character,
),
),
);
},
child: Stack(
children: [
Align(
alignment: Alignment.bottomCenter,
child: Hero(
tag: "background_${character.name}",// instead of "background_${characters[0].name}"
child: ClipPath(

Flutter Firebase where query arrayContains in List [duplicate]

This question already has answers here:
Firestore search array contains for multiple values
(6 answers)
Closed 1 year ago.
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class SearchPage extends StatefulWidget {
#override
_SearchPageState createState() => _SearchPageState();
}
class _SearchPageState extends State<SearchPage> with TickerProviderStateMixin {
final searchController = TextEditingController();
final _firestore = FirebaseFirestore.instance;
static const defaultSearch = "";
String search = defaultSearch ;
void dispose() {
searchController.dispose();
super.dispose();
}
#override
void initState() {
super.initState();
searchController.addListener(searchChanged);
}
searchChanged() {
setState(() {
search = searchController.text;
});
}
#override
Widget build(BuildContext context) {
var tarifRef = _firestore
.collection("vehicles")
.where("models", arrayContains: search);
return Scaffold(
body: Container(
child: ListView(
children: <Widget>[
Expanded(
child: Container(
height: MediaQuery.of(context).size.height * 0.08,
margin: EdgeInsets.only(top: 25),
child: Text(
"Vehicles",
style: TextStyle(
fontSize: 20, fontFamily: "Quando", color: Colors.indigo),
),
),
),
Expanded(
child: Container(
margin: EdgeInsets.only(
top: 10.0, bottom: 10.0, right: 30, left: 30),
child: TextField(
keyboardType: TextInputType.text,
decoration: InputDecoration(
prefixIcon: Icon(Icons.search),
),
controller: searchController,
),
),
),
Expanded(
child: Container(
height: MediaQuery.of(context).size.height * 0.50,
child: StreamBuilder<QuerySnapshot>(
stream: tarifRef.snapshots(),
builder: (BuildContext context, AsyncSnapshot asyncsnapshot) {
if (asyncsnapshot.hasError) {
return Center(
child: Text("Error"),
);
} else {
if (asyncsnapshot.hasData) {
List<DocumentSnapshot> listOfDocumentSnapshot =
asyncsnapshot.data.docs;
return Flexible(
child: ListView.builder(
itemCount: listOfDocumentSnapshot.length,
itemBuilder: (context, index) {
return Card(
color: Colors.indigo,
child: ListTile(
title: Text(
"${listOfDocumentSnapshot[index]["name"]}",
style: TextStyle(
fontSize: 20,
color: Colors.white,
),
),
subtitle: Text(
"${listOfDocumentSnapshot[index]["models"]}",
style: TextStyle(
fontSize: 15,
color: Colors.white,
),
),
trailing: IconButton(
icon: Icon(
Icons.delete,
color: Colors.white,
),
onPressed: () async {
await listOfDocumentSnapshot[index]
.reference
.delete();
},
),
),
);
},
),
);
} else {
return Center(
child: CircularProgressIndicator(),
);
}
}
},
),
),
),
],
),
),
);
}
}
This my all code and also I have database in Firebase like this;
vehicles: [
{
"name": "Vehicle1",
"models": ["bus", "plane", "motorcycle"]
},
{
"name": "Vehicle2",
"models": ["motorcycle", "sporcar", "plane"]
},
{
"name": "Vehicle3",
"models": ["motorcycle", "plane", "bus"]
}
]
In this example I can take one input from user, I can query and display which list includes this data but I want to query more than one data is in lists or not.
For example in this code if user input bus, program display Vehicle1 list but I want user can input more than one data such as plane and motorcycle. And so when the user input the plane and motorcycle, I want it to be displayed the list of Vehicle 2 and Vehicle 3.
I try a lot of different ways but I can't found proparly solution to this problem.
I think you're looking for arrayContainsAny here:
var tarifRef = _firestore
.collection("vehicles")
.where("models", arrayContainsAny: ["bus", "plane"]);
This query will return documents whose models array contains either "bus", "plane" or both.
Also see the FlutterFire documentation for Query.where.

Dart Lists - I created a list of widgets and add a widget called 'StarterDayTile' which works fine, but can't then remove in the next if statement

I cannot remove the 'StarterDayTile' in the line that I say dayList.remove(StarterDayTile());
This is where I originally took the screenshot from:
Apparently I have to add lots more details because my post is mostely code and I don't know what to add so I am now just writing random stuff to pass the bot who is preventing me from posting I hope this works now.
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:moody/data_screen.dart';
import 'package:moody/starter_day_tile.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:page_transition/page_transition.dart';
import 'day_tile.dart';
class HomeScreen extends StatefulWidget {
final String displayDate;
final String displayEmoji;
final int displayHapp;
HomeScreen({this.displayHapp, this.displayDate, this.displayEmoji});
#override
_HomeScreenState createState() => _HomeScreenState();
}
List<Widget> dayList = [];
class _HomeScreenState extends State<HomeScreen> {
#override
void initState() {
super.initState();
if (widget.displayEmoji != null && widget.displayDate != null && widget.displayHapp != null){
print('2');
setState(() {
dayList.insert(0, DayTile(date: widget.displayDate, emoji: widget.displayEmoji, happ: widget.displayHapp));
});
}
if (dayList.length == 0){
dayList.add(StarterDayTile());
}
else if (dayList.length == 2){
dayList.remove(StarterDayTile());
}
}
#override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.indigoAccent,
onPressed: () {
FocusScope.of(context).requestFocus(FocusNode()); // Keyboard down
Navigator.pushReplacement(
context,
PageTransition(
type: PageTransitionType.rightToLeftWithFade,
child: DataScreen()));
},
child: Icon(Icons.message),
),
backgroundColor: Colors.white12,
appBar: PreferredSize(
preferredSize: Size.fromHeight(60),
child: Hero(
tag: 'hero1',
child: AppBar(
elevation: 15,
backgroundColor: Colors.indigoAccent,
automaticallyImplyLeading: false,
title: Center(
child: Text(
'Moody',
style: TextStyle(fontFamily: 'Baloo', fontSize: 35),
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
bottom: Radius.circular(20),
),
),
leading: Padding(
child: IconButton(icon: Icon(Icons.menu), onPressed: () {}),
padding: EdgeInsets.only(right: 0, left: 10),
),
actions: <Widget>[
Padding(
padding: EdgeInsets.only(right: 10, left: 0),
child: IconButton(
icon: Icon(Icons.pie_chart),
onPressed: () {},
)),
],
),
),
),
body: ListView.builder(
reverse: false,
scrollDirection: Axis.vertical,
itemCount: dayList.length,
itemBuilder: (context, index) {
return dayList[index];
},
),
);
}
}
Try this; since it is the first object you want to remove
dayList.removeAt(0);
Solved it!!
I made a bool called startDayTileExists and made it a global variable and then when I added the StarterDayTile to the list I made it equal true and then I changed the dayList.remove() to a dayList.removeAt(1); but made an extra requirement in the if that startDayTileExists had to equal true then in the if I removed it and made startDayTileExists equal to false again.
Thanks for all your help!