I am making a form for user to add new sellers by inputing the seller's account name and type of account. But before the new seller is added to the firestore, it will check whether the seller has exist or not. Right now my code only checks if the entered name is very similar to the one in the database.
For example: In the database, there is SellerABC, so if user enter,
- sellerABC = not same
- seLLerAbc = not same
- SellerABC = same
Since the seller's account name could be in combination of uppercase and lowercase, I want to check similar letters of the two strings. If the name entered by user has the same alphabets as the one in the database it will return true.
For example:
- SeLLerabC = same
How should I check the string for the same letters?
Here is my code:
Future addSeller({
required String seller_name,
required String? typeOfAcc,
}) async {
final docSeller = FirebaseFirestore.instance.collection('sellers').doc();
final querySnapshot = FirebaseFirestore.instance
.collection('sellers')
.where('seller_name', isEqualTo: seller_name)
.where('account_type', isEqualTo: typeOfAcc);
querySnapshot.get().then((querySnapshot) async {
if (querySnapshot.docs.isNotEmpty) {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: Text('Error'),
content: Text('This seller already exists!'),
actions: <Widget>[
TextButton(
child: Text(
'OK',
style: TextStyle(color: Colors.white),
),
onPressed: () {
Navigator.of(context).pop();
},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
Color.fromARGB(255, 43, 115, 255))),
),
],
));
} else {
final json = {
'seller_name': seller_name,
'account_type': typeOfAcc,
};
await docSeller.set(json);
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: Text('Successful'),
content: Text('New seller has been successfully added!'),
actions: <Widget>[
TextButton(
child: Text(
'OK',
style: TextStyle(color: Colors.white),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => EvaluateCriteria(
sellerName: seller_name,
typeAcc: typeOfAcc)));
},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
Color.fromARGB(255, 43, 115, 255))),
),
],
));
}
});
}
}