<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: mukhtharcm</title>
    <description>The latest articles on DEV Community by mukhtharcm (@mukhtharcm).</description>
    <link>https://dev.to/mukhtharcm</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F420536%2F50f196ec-330c-41ce-b49d-6efab16e7d44.png</url>
      <title>DEV Community: mukhtharcm</title>
      <link>https://dev.to/mukhtharcm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mukhtharcm"/>
    <language>en</language>
    <item>
      <title>Deleting a Firestore Document in Flutter</title>
      <dc:creator>mukhtharcm</dc:creator>
      <pubDate>Fri, 20 Aug 2021 22:30:00 +0000</pubDate>
      <link>https://dev.to/mukhtharcm/deleting-a-firestore-document-in-flutter-4bd7</link>
      <guid>https://dev.to/mukhtharcm/deleting-a-firestore-document-in-flutter-4bd7</guid>
      <description>&lt;p&gt;There is no need for a huge story here. Deleting a Firestore document is a straightforward thing.&lt;/p&gt;

&lt;p&gt;We just have to point to a doc and call &lt;code&gt;delete&lt;/code&gt; on it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final _db = FirebaseFirestore.instance;
await _db.collection("notes").doc("note1").delete();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it.&lt;/p&gt;

&lt;p&gt;The pointed document will be deleted by the above function.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Update Firestore Document Flutter</title>
      <dc:creator>mukhtharcm</dc:creator>
      <pubDate>Thu, 19 Aug 2021 22:30:00 +0000</pubDate>
      <link>https://dev.to/mukhtharcm/update-firestore-document-flutter-im0</link>
      <guid>https://dev.to/mukhtharcm/update-firestore-document-flutter-im0</guid>
      <description>&lt;p&gt;Updating documents in Firestore is pretty easy.&lt;/p&gt;

&lt;p&gt;One method is to use the &lt;code&gt;update&lt;/code&gt; function available in Firestore Library.&lt;/p&gt;

&lt;h2&gt;
  
  
  Update Method
&lt;/h2&gt;

&lt;p&gt;Let’s look at an example by using the NoteModel class we created in &lt;a href="https://dev.to/mukhtharcm/adding-dart-objects-to-firestore-in-flutter-1keb-temp-slug-4797401"&gt;Adding Data to Firestore article&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final _db = FirebaseFirestore.instance;
NoteModel noteToUpdate = NoteModel(
title:"This is an Awesome Title",
content:"This is the Content of the Note",
);
await _db.collection("notes").doc("doc-id").update(noteToUpdate.toMap());

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above function will update the document with the document id we passed with the new data.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The One thing we should consider here is that, if there is no document existing with the document Id we provided, our &lt;strong&gt;Update will Fail&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This brings us to the second option.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set Method
&lt;/h2&gt;

&lt;p&gt;As I have pointed out in the &lt;a href="https://dev.to/mukhtharcm/adding-dart-objects-to-firestore-in-flutter-1keb-temp-slug-4797401"&gt;article about adding data to Firestore&lt;/a&gt;, set function can be used to Add document with a custom Id to Firestore Collections.&lt;/p&gt;

&lt;p&gt;It is also useful for updating a document. For that we have to pass &lt;code&gt;merge:true&lt;/code&gt; into &lt;code&gt;setOptions&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If we didn’t pass the &lt;code&gt;merge:true&lt;/code&gt;, the older document will be completely overwritten. But if we did this, the document will only update with new Data.&lt;/p&gt;

&lt;p&gt;And this method &lt;strong&gt;will create a new document&lt;/strong&gt; if no other document exists with the given document Id.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final _db = FirebaseFirestore.instance;
NoteModel noteToUpdate = NoteModel(
title:"This is an Awesome Title",
content:"This is the Content of the Note",
);
await _db.collection("notes").doc("doc-id").set(
noteToUpdate.toMap(),
SetOptions(
merge: true,
),
);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code will update a document if it exists and will create a new document if it exists.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap
&lt;/h2&gt;

&lt;p&gt;You can find more articles related to Firebase &lt;a href="https://mukhtharcm.com/tags/firebase/"&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you found something useful here.&lt;/p&gt;

&lt;p&gt;I’m always open to suggestions!&lt;/p&gt;

&lt;p&gt;Let me know your suggestions and opinions on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; DM or drop a mail a &lt;a href="//mailto:mukhtharcm@gmail.com"&gt;mukhtharcm@gmail.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you’re feeling too generous, you can support me through &lt;a href="https://buymeacoffee.com/mukhtharcm"&gt;Buy Me a Coffee&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally, if you found this helpful, please share this within your reach so that more people can benefit from this. And Follow me on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; for getting more posts like these 😉.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Adding Dart Objects to Firestore in Flutter</title>
      <dc:creator>mukhtharcm</dc:creator>
      <pubDate>Wed, 18 Aug 2021 22:30:00 +0000</pubDate>
      <link>https://dev.to/mukhtharcm/adding-dart-objects-to-firestore-in-flutter-i15</link>
      <guid>https://dev.to/mukhtharcm/adding-dart-objects-to-firestore-in-flutter-i15</guid>
      <description>&lt;p&gt;I had previously written an article on &lt;a href="https://dev.to/mukhtharcm/flutter-listview-from-firebase-firestore-20e8"&gt;How to Load Data from Firestore into a ListView&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add To Firestore with Automatic Id
&lt;/h2&gt;

&lt;p&gt;In this article, we’ll learn How to add Data into a Firestore Collection without Using the Firebase Console UI.&lt;/p&gt;

&lt;p&gt;It is quite simple. There is a function to add a document to a Collection in the Firestore Library. We can pass a Map to it and we are done.&lt;/p&gt;

&lt;p&gt;Here’s an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FirebaseFirestore.instance.collection("collection-name").add({
"title":"This is the value for Title",
"content":"This is the Content"
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But as told in my &lt;a href="https://dev.to/mukhtharcm/flutter-listview-from-firestore-using-dart-objects-30a1-temp-slug-8215781"&gt;Latest post on Firestore listview,&lt;/a&gt; we can convert Firestore data into Dart Objects and Vice-versa.&lt;/p&gt;

&lt;h3&gt;
  
  
  Convert Dart Object to Map
&lt;/h3&gt;

&lt;p&gt;For that, let’s create a Model class Like the previous Post.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class NoteModel{
String title;
String content;
NoteModel({
required this.title,
required this.content,
});
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we have to create a Function that Will convert this Object into a Map.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Map&amp;lt;String,dynamic&amp;gt; toMap(){
return {
"title":title,
"content":content,
};
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Put the above Function Inside our Model Class and It’ll convert our Dart Object into a Map.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding to Firestore
&lt;/h3&gt;

&lt;p&gt;With the second method, we can add Data to Firestore simply.&lt;/p&gt;

&lt;p&gt;First, create An Instance of our Notes Class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NoteModel noteToAdd = NoteModel(
title:"This is an Awesome Title",
content:"This is the Content of the Note",
);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we can simply add the above note to Firestore.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NoteModel noteToAdd = NoteModel(
title:"This is an Awesome Title",
content:"This is the Content of the Note",
);
FirebaseFirestore.instance.collection("Notes").add(noteToAdd.toMap());

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add to Firestore With Custom Id
&lt;/h2&gt;

&lt;p&gt;All the above methods will create an Automatic document Id for the document we add. But If we want to provide a custom Id for a document, we can do it easily.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NoteModel noteToAdd = NoteModel(
title:"This is an Awesome Title",
content:"This is the Content of the Note",
);
FirebaseFirestore.collection("notes").
doc("your-desired-doc-id").
set(noteModel.toMap());

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code will create a document with the Id we provided.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Please Note&lt;/strong&gt; when we use &lt;code&gt;set&lt;/code&gt;, if there exists a document with the Same Id, It’ll be overwritten by the latest One.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap
&lt;/h2&gt;

&lt;p&gt;You can find more articles related to Firebase &lt;a href="https://mukhtharcm.com/tags/firebase/"&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you found something useful here.&lt;/p&gt;

&lt;p&gt;I’m always open to suggestions!&lt;/p&gt;

&lt;p&gt;Let me know your suggestions and opinions on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; DM or drop a mail a &lt;a href="//mailto:mukhtharcm@gmail.com"&gt;mukhtharcm@gmail.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you’re feeling too generous, you can support me through &lt;a href="https://buymeacoffee.com/mukhtharcm"&gt;Buy Me a Coffee&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally, if you found this helpful, please share this within your reach so that more people can benefit from this. And Follow me on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; for getting more posts like these 😉.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Flutter Listview From Firestore using Dart Objects</title>
      <dc:creator>mukhtharcm</dc:creator>
      <pubDate>Tue, 17 Aug 2021 22:30:00 +0000</pubDate>
      <link>https://dev.to/mukhtharcm/flutter-listview-from-firestore-using-dart-objects-3hmd</link>
      <guid>https://dev.to/mukhtharcm/flutter-listview-from-firestore-using-dart-objects-3hmd</guid>
      <description>&lt;p&gt;Firebase and Flutter are like a match made in heaven. They both work well together very amazingly.&lt;/p&gt;

&lt;p&gt;In a previous article, I have shown you how to create a &lt;a href="https://dev.to/mukhtharcm/flutter-listview-from-firebase-firestore-20e8"&gt;Flutter ListView from Firestore&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That was by extracting the information we need directly from the data property like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;doc.data()["title"]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this article, we are gonna learn how to change those data into an actual Dart Object and use that in our listView Instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Model File
&lt;/h2&gt;

&lt;p&gt;First of all, we have to create a model dart file. In that file, create a class for our Note Object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class NoteModel{
String title;
String content;
NoteModel({
required this.title,
required this.content,
});
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are going to create a function that will convert our Firestore Docs into the Dart Object we created above.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oDTFxN9---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/listview-from-firestore-dart-objects/notes-collection_hudcb10c54548f8016bd5619e36367502e_37431_800x0_resize_box_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oDTFxN9---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/listview-from-firestore-dart-objects/notes-collection_hudcb10c54548f8016bd5619e36367502e_37431_800x0_resize_box_2.png" alt="Our Notes Collection in Firestore"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Our Notes Collection in Firestore&lt;/p&gt;



&lt;h2&gt;
  
  
  Factory for Converting Firestore Docs to Dart Objects
&lt;/h2&gt;

&lt;p&gt;For this, we need to write a factory function. Don’t fear, this is just a fancy name for a function that will return an instance of a Class.&lt;/p&gt;

&lt;p&gt;In the same dart class, create let’s create our Factory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;factory NoteModel.fromDocumentSnapshot({required DocumentSnapshot&amp;lt;Map&amp;lt;String,dynamic&amp;gt;&amp;gt; doc}){
return NoteModel(
title: doc.data()!["title"],
content:doc.data()!["content"],
);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above Function will accept a &lt;code&gt;DocumentSnapshot&lt;/code&gt; (A Firestore Document) and turn it into a NoteModel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Streaming our Notes from Firstore
&lt;/h2&gt;

&lt;p&gt;Next, on the page which we’ll show the data, let’s create a Function to get all those Notes from Firestore.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final _db = FirebaseFirestore.instance;
Stream&amp;lt;List&amp;lt;NoteModel&amp;gt;&amp;gt; noteStream(){
try{
return
_db.collection("notes)
.snapshots
.map((notes){
final List&amp;lt;NoteModel&amp;gt; notesFromFirestore = &amp;lt;NoteModel&amp;gt;[];
for(final DocumentSnapshot&amp;lt;Map&amp;lt;String,dynamic&amp;gt;&amp;gt; doc in notes.docs){
notesFromFirestore.add(NoteModel.fromDocumentSnapshot(doc:doc));
}
return notesFromFirestore;
});
} catch(e){
rethrow;
}
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above function will stream Notes from our Firestore Collection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Showing The Data
&lt;/h2&gt;

&lt;p&gt;For showing the Notes, we will use &lt;strong&gt;StreamBuilder&lt;/strong&gt; as we have previously done.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;StreamBuilder&amp;lt;List&amp;lt;NoteModel&amp;gt;&amp;gt;(
stream: noteStream();
builder: (context,snapshot){
if(!snapshot.hasData){
return Center(
child:Text("No Data");
)
} else if(snapshot.hasError){
return Center(
child: Text("An Error Occured);
)
} else if(snapshot.hasData){
return ListView.Builder(
itemCount: snapshot.data!.index,
itemBuilder: (context,index){
NoteModel currentModel = snapshot.data![index];
return Card(
child: ListTile(
title: Text(currentNote .title)
subtitle:Text(currentModel.content)
)
);
}
)
}
else return Center(child: Text("An Error occured));
}
)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code will bring a list View from those Firestore Data. Please notice that We are directly accessing the Dart Objects properties instead of accessing &lt;code&gt;.data&lt;/code&gt; directly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap
&lt;/h2&gt;

&lt;p&gt;You can find more articles related to Firebase &lt;a href="https://mukhtharcm.com/tags/firebase/"&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you found something useful here.&lt;/p&gt;

&lt;p&gt;I’m always open to suggestions!&lt;/p&gt;

&lt;p&gt;Let me know your suggestions and opinions on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; DM or drop a mail a &lt;a href="//mailto:mukhtharcm@gmail.com"&gt;mukhtharcm@gmail.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you’re feeling too generous, you can support me through &lt;a href="https://buymeacoffee.com/mukhtharcm"&gt;Buy Me a Coffee&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally, if you found this helpful, please share this within your reach so that more people can benefit from this. And Follow me on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; for getting more posts like these 😉.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Disabling Touch Events in Flutter</title>
      <dc:creator>mukhtharcm</dc:creator>
      <pubDate>Mon, 16 Aug 2021 22:30:00 +0000</pubDate>
      <link>https://dev.to/mukhtharcm/disabling-touch-events-in-flutter-3kdi</link>
      <guid>https://dev.to/mukhtharcm/disabling-touch-events-in-flutter-3kdi</guid>
      <description>&lt;p&gt;At some point in our app, we have a requirement to disable touch inputs. The one immediate use case coming into my mind is the loading time after Submitting Forms.&lt;/p&gt;

&lt;p&gt;Whatever may be our use-case, Flutter has widgets (😄) for this too. Specifically, there are 2 widgets for this use case.&lt;/p&gt;

&lt;h2&gt;
  
  
  AbsorbPointer Widget
&lt;/h2&gt;

&lt;p&gt;The first one is the AbsorbPointer Widget. What we have to do is to wrap the widget we want to disable touch with this Widget.&lt;/p&gt;

&lt;p&gt;This widget has a property called &lt;code&gt;absorbing&lt;/code&gt;. If this is set to true, the touch will be disabled for the child widgets.&lt;/p&gt;

&lt;p&gt;If it is false, the widgets will behave normally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AbsorbPointer(
absorbing: true,
child: MaterialButton(
child: Text("Click Me"),
onPressed: () {
// nothing :)
 },
color: Colors.purple,
),
)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Above is an example of a disabled Button. We can’t click on the Button while &lt;strong&gt;absorbing&lt;/strong&gt; is set to true.&lt;/p&gt;

&lt;h2&gt;
  
  
  IgnorePointer Widget
&lt;/h2&gt;

&lt;p&gt;The next one is IgnorePointer Widget. The only noticeable difference with the first one is the change in name of the widget and the property which controls the Touch Status.&lt;/p&gt;

&lt;p&gt;Here also, we have to wrap the widget we want to disable touch with this widget.&lt;/p&gt;

&lt;p&gt;In this widget, the property which controls touch is &lt;code&gt;ignoring&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Like the first one, if we set &lt;strong&gt;ignoring&lt;/strong&gt; to true, we can’t click the underlying widgets. If it’s false it’ll behave normally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IgnorePointer(
ignoring: true,
child: MaterialButton(
child: Text("Click Me"),
onPressed: () {
// nothing :)
 },
color: Colors.purple,
),
)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the same example with &lt;strong&gt;IgnorePointer&lt;/strong&gt; Widget. We have to change &lt;strong&gt;ignoring&lt;/strong&gt; to false if we want to click the Button.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ideas
&lt;/h2&gt;

&lt;p&gt;In Both of these scenarios, an ideal way would be to don’t hard code the values for &lt;strong&gt;ignoring&lt;/strong&gt; and &lt;strong&gt;absorbing&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead, we can use a variable and control them from outside.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool ignoring = true; // A global Variable

// Inside A Column
IgnorePointer(
ignoring: ignoring,
child: MaterialButton(
child: Text("Click the below button to toggle status"),
onPressed: () {
ignoring = !ignoring
},
color: Colors.purple,
),
),
MaterialButton(
child: Text("Click Me to Toggle my Status"),
onPressed: () {
ignoring = !ignoring
},
color: Colors.purple,
),

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, Clicking the below button will toggle the touch status of the above Button.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap
&lt;/h2&gt;

&lt;p&gt;You can find more articles related to Firebase &lt;a href="https://mukhtharcm.com/tags/firebase/"&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you found something useful here.&lt;/p&gt;

&lt;p&gt;I’m always open to suggestions!&lt;/p&gt;

&lt;p&gt;Let me know your suggestions and opinions on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; DM or drop a mail a &lt;a href="//mailto:mukhtharcm@gmail.com"&gt;mukhtharcm@gmail.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you’re feeling too generous, you can support me through &lt;a href="https://buymeacoffee.com/mukhtharcm"&gt;Buy Me a Coffee&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally, if you found this helpful, please share this within your reach so that more people can benefit from this. And Follow me on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; for getting more posts like these 😉.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Change Logo in Flutter Android Application</title>
      <dc:creator>mukhtharcm</dc:creator>
      <pubDate>Sun, 15 Aug 2021 23:00:00 +0000</pubDate>
      <link>https://dev.to/mukhtharcm/change-logo-in-flutter-android-application-dl0</link>
      <guid>https://dev.to/mukhtharcm/change-logo-in-flutter-android-application-dl0</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;The Default Logo of a Flutter application is the Flutter Logo. I don’t think most applications will not be sufficient with this Logo.&lt;/p&gt;

&lt;p&gt;There are many ways to change this default Logo. This includes using packages like &lt;a href="https://pub.dev/packages/flutter_launcher_icons"&gt;Flutter Launcher Icons&lt;/a&gt; or using the built-in &lt;a href="https://developer.android.com/studio/write/image-asset-studio"&gt;Image Asset Studio&lt;/a&gt; in the Android Studio.&lt;/p&gt;

&lt;p&gt;But the First method needs to install a package and the second method needs us to use &lt;strong&gt;Android Studio&lt;/strong&gt;. If you are like me, who doesn’t use Android Studio, There is a simpler and easy method.&lt;/p&gt;

&lt;p&gt;There is a Website Called &lt;a href="https://romannurik.github.io/AndroidAssetStudio/"&gt;Android Asset Studio&lt;/a&gt;. It is created by an amazing developer called &lt;a href="https://github.com/romannurik"&gt;Roman Nurik&lt;/a&gt;. We can use this website instead of the &lt;strong&gt;Image Asset Studio&lt;/strong&gt; which is only available on Android Studio. Let’s get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get Started
&lt;/h2&gt;

&lt;p&gt;First of all, go to the above-mentioned website &lt;a href="https://romannurik.github.io/AndroidAssetStudio/"&gt;https://romannurik.github.io/AndroidAssetStudio/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6nofYNJ0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/change-logo-flutter-android/asset-studio_hu4243508552c8495e03978e3dabd3109b_80406_800x0_resize_box_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6nofYNJ0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/change-logo-flutter-android/asset-studio_hu4243508552c8495e03978e3dabd3109b_80406_800x0_resize_box_2.png" alt="Android Asset Studio"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Android Asset Studio&lt;/p&gt;



&lt;p&gt;Then click on &lt;strong&gt;Launcher Icon Generator&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You will be navigated to a studio-like page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kxwNAVuS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/change-logo-flutter-android/icon-generator_hua6ff155514ddf3e6882d723a7b19490e_74494_800x0_resize_box_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kxwNAVuS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/change-logo-flutter-android/icon-generator_hua6ff155514ddf3e6882d723a7b19490e_74494_800x0_resize_box_2.png" alt="Icon Generator Page"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Icon Generator Page&lt;/p&gt;



&lt;p&gt;If we look closely, we can see that we have &lt;strong&gt;3&lt;/strong&gt; Options for creating an Icon.&lt;/p&gt;

&lt;p&gt;The first one is Image. If we click on that, we’ll be prompted to select an Image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Yc3Vf5tF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/change-logo-flutter-android/select-image_hue925e1e7634e5c9f4788f630a4defb33_104590_800x0_resize_box_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Yc3Vf5tF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/change-logo-flutter-android/select-image_hue925e1e7634e5c9f4788f630a4defb33_104590_800x0_resize_box_2.png" alt="Select Image Dialog"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Select Image Dialog&lt;/p&gt;



&lt;p&gt;The second one is Clipart. If we select it, we’ll have to select an Icon.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0WBHVBq4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/change-logo-flutter-android/select-clipart.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0WBHVBq4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/change-logo-flutter-android/select-clipart.png" alt="Select Icon"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Select Icon&lt;/p&gt;



&lt;p&gt;And the third one is Text. And It allows us to Type a letter or a word.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r7EJldLW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/change-logo-flutter-android/text_hud63e5c3b2e89ea683404786300bf2c43_59723_800x0_resize_box_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r7EJldLW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/change-logo-flutter-android/text_hud63e5c3b2e89ea683404786300bf2c43_59723_800x0_resize_box_2.png" alt="Type Text"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Type Text&lt;/p&gt;



&lt;h2&gt;
  
  
  Download Logo
&lt;/h2&gt;

&lt;p&gt;After we prepared our logo, let’s Continue generating our Logo. For that, click on the blue Download icon on the top right corner. By default, it will download a file named &lt;code&gt;ic_launcher.zip&lt;/code&gt;. This ZIP file contains all the files needed to change our Logo.&lt;/p&gt;

&lt;p&gt;Next, extract this ZIP to somewhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  Changing Logo
&lt;/h2&gt;

&lt;p&gt;If you have observed the file structure inside the Android Folder in a Flutter Project, you may have noticed there is an &lt;code&gt;src&lt;/code&gt; folder inside it.&lt;/p&gt;

&lt;p&gt;Inside that folder, there will be folders named &lt;strong&gt;debug&lt;/strong&gt; , &lt;strong&gt;main&lt;/strong&gt; , and &lt;strong&gt;profile&lt;/strong&gt;. Our target is a folder named &lt;code&gt;res&lt;/code&gt; inside the &lt;strong&gt;main&lt;/strong&gt; folder.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U91UNLrc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/change-logo-flutter-android/folder-structure.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U91UNLrc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/change-logo-flutter-android/folder-structure.png" alt="Folder Structure"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Folder Structure&lt;/p&gt;



&lt;p&gt;We can see that many folders are starting with &lt;strong&gt;mipmap&lt;/strong&gt; in them.&lt;/p&gt;




&lt;p&gt;Now open the extracted &lt;strong&gt;ic_launcher&lt;/strong&gt; folder. We can see a folder named &lt;strong&gt;src&lt;/strong&gt; similar to that we saw on the main folder.&lt;/p&gt;

&lt;p&gt;The content of the &lt;strong&gt;src&lt;/strong&gt; folder is also similar to the previous &lt;strong&gt;src&lt;/strong&gt; folder we saw. But this one only has folders starting with &lt;strong&gt;mipmap&lt;/strong&gt;. These are the folders which contain our new Logo.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LKyNehnm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/change-logo-flutter-android/inside-folder.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LKyNehnm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/change-logo-flutter-android/inside-folder.png" alt="Folder Contents"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Folder Contents&lt;/p&gt;



&lt;p&gt;Now copy all these folders to the First &lt;strong&gt;src&lt;/strong&gt; Folder we opened. It will replace our old (Default Flutter Logo) with our New Logo.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Steps
&lt;/h2&gt;

&lt;p&gt;After Changing the Files, we have to completely rebuild our app to see the changes. For that, let’s clean our Flutter Project by running the below command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flutter clean

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we run our project now, We can see that our Logo has been changed to the new One.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap
&lt;/h2&gt;

&lt;p&gt;You can find more articles related to Firebase &lt;a href="https://mukhtharcm.com/tags/firebase/"&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you found something useful here.&lt;/p&gt;

&lt;p&gt;I’m always open to suggestions!&lt;/p&gt;

&lt;p&gt;Let me know your suggestions and opinions on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; DM or drop a mail a &lt;a href="//mailto:mukhtharcm@gmail.com"&gt;mukhtharcm@gmail.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you’re feeling too generous, you can support me through &lt;a href="https://buymeacoffee.com/mukhtharcm"&gt;Buy Me a Coffee&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally, if you found this helpful, please share this within your reach so that more people can benefit from this. And Follow me on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; for getting more posts like these 😉.&lt;/p&gt;

</description>
      <category>flutter</category>
    </item>
    <item>
      <title>Firebase Messaging Flutter</title>
      <dc:creator>mukhtharcm</dc:creator>
      <pubDate>Sat, 14 Aug 2021 22:30:00 +0000</pubDate>
      <link>https://dev.to/mukhtharcm/firebase-messaging-flutter-5832</link>
      <guid>https://dev.to/mukhtharcm/firebase-messaging-flutter-5832</guid>
      <description>&lt;p&gt;Firebase Messaging is another cool feature of &lt;a href="https://mukhtharcm.com/tags/firebase/"&gt;Firebase&lt;/a&gt; Suite. It allows us to send notifications to our users and much more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;First, we have to set up Firebase for our Flutter Project. Checkout &lt;a href="https://dev.to/mukhtharcm/flutter-firebase-android-setup-4bgf-temp-slug-871398"&gt;my post on setting up Firebase&lt;/a&gt; if you haven’t already.&lt;/p&gt;

&lt;p&gt;Then we have to add the Firebase Messaging plugin to our project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
firebase_core: ^1.3.0
firebase_messaging: ^10.0.4 # add this

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Basically, &lt;em&gt;this is all you need&lt;/em&gt; to send notifications to using Firebase!.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Firebase Messaging Token
&lt;/h2&gt;

&lt;p&gt;Firebase Messaging token is used to send notifications to specific devices.&lt;/p&gt;

&lt;p&gt;For getting this, there is a function in the Firebase Messaging plugin. So let’s get the token and print it to the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future getToken()async{
var token = await FirebaseMessaging.instance.getToken();
print("Your FCM token is : $token");
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running the above code will output something like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dG_9FYgjSiOmHlv_XxyQ8h:APA91bEsV52c873LipKZZQgU2M__XuvKHZn2EsjN2LY8NNiA9_lF_jXNvmnfqi7F5lOEhi5A2kLILGqSY71yrJGNfwcNHUgQ-kXNAP88KIMoFHuDrq5Y2cENV4h2a139JqHFVajaH4pW

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Take note of the token we got from this step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preparing our Test Notification
&lt;/h2&gt;

&lt;p&gt;We can use the Firebase Console to Send a notification to our Device. First of all, go to &lt;code&gt;https://console.firebase.google.com&lt;/code&gt; and Select your project. Then from the sidebar, select &lt;strong&gt;Cloud Messaging&lt;/strong&gt; under the Engage Section.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Zj5hrs13--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/engage-section.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Zj5hrs13--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/engage-section.png" alt="Click on Cloud Messaging"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Click on Cloud Messaging&lt;/p&gt;



&lt;p&gt;This will open the FCM Section.&lt;/p&gt;

&lt;p&gt;Then Click on New Notification. It’ll open a dialog to send a new Notification.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PJ7qN_ZG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/new-notification_hu8ee932b903b47b9bb7bbfde629a91560_47491_800x0_resize_box_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PJ7qN_ZG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/new-notification_hu8ee932b903b47b9bb7bbfde629a91560_47491_800x0_resize_box_2.png" alt="New Notification Dialog"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;New Notification Dialog&lt;/p&gt;



&lt;p&gt;Fill out the &lt;strong&gt;Notification Title&lt;/strong&gt; and &lt;strong&gt;Notification Text&lt;/strong&gt;. And Optionally, you can also add an Image to your Notification. You can see the Device preview on the Right side.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1pHCAfly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/notification-filled_hud9f7b34fc5033aff49b2261c40001bda_66492_800x0_resize_box_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1pHCAfly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/notification-filled_hud9f7b34fc5033aff49b2261c40001bda_66492_800x0_resize_box_2.png" alt="Filled the Notification Fields"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;filled the Notification Fields&lt;/p&gt;



&lt;h2&gt;
  
  
  Sending our Test Notification
&lt;/h2&gt;

&lt;p&gt;For this step, Just click on &lt;strong&gt;Send Test Message&lt;/strong&gt; on the Right Side. This will open a dialog to enter the token we previously noticed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y4QmlUeE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/add-device.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y4QmlUeE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/add-device.png" alt="Add New Test Device"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Add New Test Device&lt;/p&gt;



&lt;p&gt;Copy-paste the token we noted earlier and click the plus button on the right.&lt;/p&gt;

&lt;p&gt;Then Click &lt;strong&gt;Test&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Voila! You have sent your First Notification!&lt;/p&gt;

&lt;p&gt;Check your device and you’ll see something like this on the Notifications Panel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xVANIYeC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/notification.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xVANIYeC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/notification.jpg" alt="Notification we send"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Notification we send&lt;/p&gt;



&lt;p&gt;PS: That unlimit on the top is one of my Client Works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sending Notification to Multiple Devices
&lt;/h2&gt;

&lt;p&gt;From the Firebase Console itself, we can also send Notification to multiple Devices.&lt;/p&gt;

&lt;p&gt;Instead of clicking the &lt;strong&gt;Send Test Message&lt;/strong&gt; , Just click Next. It’ll take us to select our Target.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oIQNuY5z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/select-target_huf326d6f063ffab1b421c4727bcf158a7_21474_800x0_resize_box_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oIQNuY5z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/select-target_huf326d6f063ffab1b421c4727bcf158a7_21474_800x0_resize_box_2.png" alt="Select Target"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Select Target .&lt;/p&gt;



&lt;p&gt;This is dialog is for Selecting the Apps we want our notification to send to ( One of the Apps connected to our Firebase Project). You Can also target Topics Here.&lt;/p&gt;

&lt;p&gt;The Next Step is to Schedule the Notification.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1BikExbC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/shedule_hu9c75fa81d37c6cdb53c1179f7b317355_18700_800x0_resize_box_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1BikExbC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/shedule_hu9c75fa81d37c6cdb53c1179f7b317355_18700_800x0_resize_box_2.png" alt="Shedule Dialog"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We can shedule to a Future Date or Can Just Set Now&lt;/p&gt;



&lt;p&gt;The next two steps are optional. So just skip and click On &lt;strong&gt;Review&lt;/strong&gt; at the bottom right.&lt;/p&gt;

&lt;p&gt;This will open the Dialog to Finally publish our Notification.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FegWAyCT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/publish_hub56b938edf3640a746bee956a29b73be_26639_800x0_resize_box_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FegWAyCT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/firebase-messaging-flutter/publish_hub56b938edf3640a746bee956a29b73be_26639_800x0_resize_box_2.png" alt="Publish the Notificaton"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Publish the Notification&lt;/p&gt;



&lt;p&gt;This will deliver our Notification to every device which matches the criteria we set.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap
&lt;/h2&gt;

&lt;p&gt;You can find more articles related to Firebase &lt;a href="https://mukhtharcm.com/tags/firebase/"&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you found something useful here.&lt;/p&gt;

&lt;p&gt;I’m always open to suggestions!&lt;/p&gt;

&lt;p&gt;Let me know your suggestions and opinions on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; DM or drop a mail a &lt;a href="//mailto:mukhtharcm@gmail.com"&gt;mukhtharcm@gmail.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you’re feeling too generous, you can support me through &lt;a href="https://buymeacoffee.com/mukhtharcm"&gt;Buy Me a Coffee&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally, if you found this helpful, please share this within your reach so that more people can benefit from this. And Follow me on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; for getting more posts like these 😉.&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>firebase</category>
    </item>
    <item>
      <title>Persisting Data on Firebase Emulator</title>
      <dc:creator>mukhtharcm</dc:creator>
      <pubDate>Fri, 13 Aug 2021 22:30:00 +0000</pubDate>
      <link>https://dev.to/mukhtharcm/persisting-data-on-firebase-emulator-474c</link>
      <guid>https://dev.to/mukhtharcm/persisting-data-on-firebase-emulator-474c</guid>
      <description>&lt;p&gt;&lt;a href="https://dev.to/mukhtharcm/firebase-emulator-setup-for-flutter-5e81-temp-slug-9286537"&gt;Firebase Emulator Suite&lt;/a&gt; is a great tool to develop with Firebase locally. It allows us to even use Firebase Functions without the &lt;em&gt;paid&lt;/em&gt; Blaze plan.&lt;/p&gt;

&lt;p&gt;But by default, Firebase Emulators don’t store any data. That is, if I ran Firebase Auth Emulator and created a User when I run It next time, The User would’ve been deleted.&lt;/p&gt;

&lt;p&gt;Or, All those &lt;a href="https://dev.to/mukhtharcm/flutter-listview-from-firebase-firestore-59bl-temp-slug-3367788"&gt;Notes you created in Firestore&lt;/a&gt; would’ve wiped.&lt;/p&gt;

&lt;p&gt;I don’t know about you, It is a mess to play with Emulator UI to add mock Data. So I’d rather save them.&lt;/p&gt;

&lt;p&gt;Even though Firebase Emulators Don’t have something like Saving Data, Luckily, they Can Export and Import Data. Let’s dig into it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exporting Firebase Emulator Data
&lt;/h2&gt;

&lt;p&gt;While the Emulators are running, run the below command in another terminal to export emulator Data. Of course, it should be in the same folder as you’re running the Emulators&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase emulators:export &amp;lt;export-directory&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will export the emulator data to the Directory you specify.&lt;/p&gt;

&lt;p&gt;There is another method to do it. If we start the Emulators with an &lt;code&gt;--export-on-exit&lt;/code&gt; flag, the Firebase Emulator will automatically export Data when we shutdown it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase emulators:start --export-on-exit

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Importing Emulator Data
&lt;/h2&gt;

&lt;p&gt;We can import data from an earlier export by starting the emulator by running the below command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase emulators:start --import &amp;lt;export-directory&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will import data from the directory we earlier exported.&lt;/p&gt;

&lt;h2&gt;
  
  
  Combined method
&lt;/h2&gt;

&lt;p&gt;What if we can do both of these in a single command?&lt;/p&gt;

&lt;p&gt;We can combine the above commands to make another command which will do both the functions. ie, Importing and Exporting.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase emulators:start --import &amp;lt;export-directory&amp;gt; --export-on-exit

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command will import data from the directory we specify at &lt;code&gt;&amp;lt;export-directory&amp;gt;&lt;/code&gt; and exports the emulator data on Exit to the same directory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap
&lt;/h2&gt;

&lt;p&gt;You can find more articles related to Firebase &lt;a href="https://mukhtharcm.com/tags/firebase/"&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you found something useful here.&lt;/p&gt;

&lt;p&gt;I’m always open to suggestions!&lt;/p&gt;

&lt;p&gt;Let me know your suggestions and opinions on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; DM or drop a mail a &lt;a href="//mailto:mukhtharcm@gmail.com"&gt;mukhtharcm@gmail.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you’re feeling too generous, you can support me through &lt;a href="https://buymeacoffee.com/mukhtharcm"&gt;Buy Me a Coffee&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally, if you found this helpful, please share this within your reach so that more people can benefit from this. And Follow me on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; for getting more posts like these 😉.&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>firebase</category>
    </item>
    <item>
      <title>Firebase Emulator setup for Flutter</title>
      <dc:creator>mukhtharcm</dc:creator>
      <pubDate>Thu, 12 Aug 2021 22:30:00 +0000</pubDate>
      <link>https://dev.to/mukhtharcm/firebase-emulator-setup-for-flutter-4ae0</link>
      <guid>https://dev.to/mukhtharcm/firebase-emulator-setup-for-flutter-4ae0</guid>
      <description>&lt;p&gt;Maybe you’re trying to set up a local dev environment for your Firebase Project. Or you may want to try out Firebase Functions, but are on the spark plan of Firebase.&lt;/p&gt;

&lt;p&gt;Whatever It may be, Firebase offers us an emulator suite we can use to experiment with Firebase locally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Firebase CLI
&lt;/h2&gt;

&lt;p&gt;First of all, we need to Install the Official Firebase CLI on our Computer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install firebase-tools -g

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the above command to Install the Firebase CLI globally to our System.&lt;/p&gt;

&lt;p&gt;Next, we have to log in to the Firebase CLI using &lt;code&gt;firebase login&lt;/code&gt;. This will take you to the browser for confirming login. Click allow to login to the cli. And It will show a Successful Message.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmukhtharcm.com%2Ffirebase-emulator-flutter%2Fcli-login-success.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmukhtharcm.com%2Ffirebase-emulator-flutter%2Fcli-login-success.png" alt="CLI login Succesful!"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;CLI login succesful!&lt;/p&gt;



&lt;h2&gt;
  
  
  Initializing Firebase Project
&lt;/h2&gt;

&lt;p&gt;The next step is to initialize your firebase project. Go to your Flutter project which you want to use Firebase, and run the below command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase init

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will show &lt;strong&gt;Firebase&lt;/strong&gt; in a large yellow font. The prompt will ask you some questions, the first being are you ready to proceed. Press &lt;strong&gt;Y&lt;/strong&gt; to continue.&lt;/p&gt;

&lt;h3&gt;
  
  
  Selecting Services
&lt;/h3&gt;

&lt;p&gt;The next prompt will be to select the Services we want to initialize. Select all the services you need by pressing the spacebar to select. Then click &lt;strong&gt;enter&lt;/strong&gt; to continue.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;? Which Firebase features do you want to set up for this directory? Press Space to select features, then Enter to confirm your choices.
( ) Hosting: Set up GitHub Action deploys
( ) Storage: Configure a security rules file for Cloud Storage
( ) Emulators: Set up local emulators for Firebase products
&amp;gt;( ) Remote Config: Configure a template file for Remote Config
( ) Realtime Database: Configure a security rules file for Realtime Database and (optionally) provision default instance
( ) Firestore: Configure security rules and indexes files for Firestore
( ) Functions: Configure a Cloud Functions directory and its files
(Move up and down to reveal more choices)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Don’t forget to select &lt;em&gt;Emulators&lt;/em&gt; Here!&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Selecting Project
&lt;/h3&gt;

&lt;p&gt;The next step is to select which project we want our Flutter project to associate with. For the sake of this tutorial, I have already created a Firebase Project in my &lt;a href="https://console.firebase.google.com/" rel="noopener noreferrer"&gt;Firebase Console&lt;/a&gt;. If you haven’t yet, you can follow &lt;a href="https://dev.to/mukhtharcm/flutter-firebase-android-setup-4bgf-temp-slug-871398"&gt;My post on setting up Firebase for Android on Flutter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So select &lt;strong&gt;Use an existing project&lt;/strong&gt; in this prompt&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;? Please select an option: (Use arrow keys)
&amp;gt; Use an existing project
Create a new project
Add Firebase to an existing Google Cloud Platform project
Don't set up a default project

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will show a list of all the projects you’ve created and you’ll have to select one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OR&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;you can just select &lt;em&gt;Don’t set up a default project&lt;/em&gt; and move on!.&lt;/p&gt;

&lt;p&gt;The next couple of prompts will be based on the services you’ve selected in the previous step.&lt;/p&gt;

&lt;p&gt;For this post, we’ll be covering only the Emulator Setup. The CLI will ask which emulators we want to set up.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;? Which Firebase emulators do you want to set up? Press Space to select emulators, then Enter to confirm your choices. (Press &amp;lt;space&amp;gt; to select, &amp;lt;a&amp;gt; to toggle all, &amp;lt;i&amp;gt; to invert selection)
&amp;gt;( ) Authentication Emulator
(*) Functions Emulator
( ) Firestore Emulator
( ) Database Emulator
( ) Hosting Emulator
( ) Pub/Sub Emulator
( ) Storage Emulator

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Select all the emulators you want to use in this project.&lt;/p&gt;

&lt;p&gt;Then it will ask which post should be used for each emulator. Click enter to select the default options.&lt;/p&gt;

&lt;p&gt;When the CLI asks whether to download the emulators now or later, click &lt;em&gt;Y&lt;/em&gt; to download them now.&lt;/p&gt;

&lt;p&gt;After these, the CLI will show a success message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+ Firebase initialization complete!

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  To the Flutter-Side
&lt;/h2&gt;

&lt;p&gt;Next, we are going to set up our Flutter project use the local emulators instead of our Production Firebase Project.&lt;/p&gt;

&lt;p&gt;Each of the Firebase plugins for Flutter has something like &lt;code&gt;.useEmulator&lt;/code&gt; in them. So for convenience, I have created a function to make all of the Firebase products use Emulators.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future _connectToFirebaseEmulator() async {
final localHostString = '{your system Ip Address}';
FirebaseFirestore.instance.settings = Settings(
host: '$localHostString:8080',
sslEnabled: false,
persistenceEnabled: false,
);
await FirebaseStorage.instance
.useStorageEmulator('http://$localHostString', 9199);
await FirebaseAuth.instance.useAuthEmulator('http://$localHostString', 9099);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The official documentation recommends just use localhost instead of your system Ip Address, But I will explain it in a bit.&lt;/p&gt;

&lt;p&gt;When I was trying to connect to emulators from a &lt;strong&gt;Real Device&lt;/strong&gt; (aka not an android emulator), I was unable to connect to them using only &lt;code&gt;localhost&lt;/code&gt;. If you’re using Android or iOS emulators, you may stick with the localhost version.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future _connectToFirebaseEmulator() async {
FirebaseFirestore.instance.settings = Settings(
host: 'localhost:8080',
sslEnabled: false,
persistenceEnabled: false,
);
await FirebaseStorage.instance
.useStorageEmulator('localhost', 9199);
await FirebaseAuth.instance.useAuthEmulator('localhost', 9099);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we have to call the above function to be the runApp method in &lt;code&gt;main.dart&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void main() async {
WidgetsFlutterBinding.ensureInitialized();
await _connectToFirebaseEmulator();
runApp(
MyApp(),
);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Don’t leave just yet!&lt;/strong&gt; For my &lt;em&gt;hacked out&lt;/em&gt; version to work, we have to make changes to one more file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adjusting firebase.json file
&lt;/h3&gt;

&lt;p&gt;There is a file named firebase.json at the root of our Flutter project. Don’t worry, it was created during our Firebase CLI initialization.&lt;/p&gt;

&lt;p&gt;By default, it will look something like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
},
"emulators": {
"auth": {
"port": 9099
},
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"pubsub": {
"port": 8085
},
"storage": {
"port": 9199
},
"ui": {
"enabled": true
}
}
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a &lt;strong&gt;port&lt;/strong&gt; key in every emulator listed in the JSON. We need to add a &lt;strong&gt;host&lt;/strong&gt; key to them.&lt;/p&gt;

&lt;p&gt;We have to provide our system IP as the host. To get our IP address, we can run &lt;code&gt;ipconfig&lt;/code&gt; on windows and &lt;code&gt;ifconfig&lt;/code&gt; on Linux. In my case, It was &lt;code&gt;192.168.42.54&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So my &lt;code&gt;firebase.json&lt;/code&gt; looks like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
},
"storage": {
"rules": "storage.rules"
},
"emulators": {
"auth": {
"host": "192.168.42.54",
"port": 9099
},
"functions": {
"host": "192.168.42.54",
"port": 5001
},
"firestore": {
"host": "192.168.42.54",
"port": 8080
},
"storage": {
"host": "192.168.42.54",
"port": 9199
},
"ui": {
"host": "192.168.42.54",
"enabled": true
}
}
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Running the emulators
&lt;/h2&gt;

&lt;p&gt;Now is the time to run’em! 🎉&lt;/p&gt;

&lt;p&gt;run the below code in the terminal on the root of your Flutter Project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase emulators:start

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;wait some time and you’ll see the magic.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmukhtharcm.com%2Ffirebase-emulator-flutter%2Femulators-running_huc41e2f2752b60e95da5233cc50f078d5_31250_800x0_resize_box_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmukhtharcm.com%2Ffirebase-emulator-flutter%2Femulators-running_huc41e2f2752b60e95da5233cc50f078d5_31250_800x0_resize_box_2.png" alt="Description"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Firebase emulators running&lt;/p&gt;



&lt;h2&gt;
  
  
  Wrap
&lt;/h2&gt;

&lt;p&gt;You can find more articles related to Firebase &lt;a href="https://mukhtharcm.com/tags/firebase/" rel="noopener noreferrer"&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you found something useful here.&lt;/p&gt;

&lt;p&gt;I’m always open to suggestions!&lt;/p&gt;

&lt;p&gt;Let me know your suggestions and opinions on &lt;a href="https://twitter.com/mukhtharcm" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; DM or drop a mail a &lt;a href="//mailto:mukhtharcm@gmail.com"&gt;mukhtharcm@gmail.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you’re feeling too generous, you can support me through &lt;a href="https://buymeacoffee.com/mukhtharcm" rel="noopener noreferrer"&gt;Buy Me a Coffee&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally, if you found this helpful, please share this within your reach so that more people can benefit from this. And Follow me on &lt;a href="https://twitter.com/mukhtharcm" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; for getting more posts like these 😉.&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>firebase</category>
    </item>
    <item>
      <title>Easy Dialogs using GetX</title>
      <dc:creator>mukhtharcm</dc:creator>
      <pubDate>Sun, 02 May 2021 22:30:00 +0000</pubDate>
      <link>https://dev.to/mukhtharcm/easy-dialogs-using-getx-13e2</link>
      <guid>https://dev.to/mukhtharcm/easy-dialogs-using-getx-13e2</guid>
      <description>&lt;h3&gt;
  
  
  Intro
&lt;/h3&gt;

&lt;p&gt;I you have read my &lt;a href="https://dev.to/mukhtharcm/flutter-snackbar-without-context-using-getx-58al-temp-slug-1995154"&gt;post&lt;/a&gt; about snackBars using GetX, You already know how easy is it to work with GetX in Flutter.&lt;/p&gt;

&lt;p&gt;Dialogs are an essential part of mobile Apps. They help to convey alerts and important messages as well as to do certain actions.&lt;/p&gt;

&lt;p&gt;Normally in Flutter, shown below is a sample code for showing and Alert Dialog.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;showDialog(
context: context,
builder: (context) =&amp;gt; AlertDialog(
title: Text(
"Alert",
),
content: Text(
"This is sample Content",
),
),
);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s too many Lines of code for a Simple Dialog like this. But, thankfully GetX makes this easier. In GetX, we only have to use the following code,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Get.defaultDialog(
title: "Alert",
content: Text(
"This is a sample Content",
),
);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I think this makes a big difference.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add Package
&lt;/h3&gt;

&lt;p&gt;First of all, we have to add the get package into our pubspec.yaml file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies:
flutter:
sdk: flutter
get: ^4.1.4 # Get the latest version from https://pub.dev/packages/get

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Change to GetMaterialApp
&lt;/h3&gt;

&lt;p&gt;To all navigation and routing things work with GetX, we have to change our MaterialApp to a GetMaterialApp. For this, we have to import the library first&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:get/get.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp( // Changed from MaterialApp to GetMaterialApp
 home: HomePage(),
);
}
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If this step is not completed, it will throw an error when we try to use something like &lt;code&gt;Get.dialog()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We’re good to go now.&lt;/p&gt;

&lt;h3&gt;
  
  
  GetX default Dialog
&lt;/h3&gt;

&lt;p&gt;This is the type of dialog which I have shown as an Example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Get.defaultDialog(
title: "Alert!",
content: Text("This is a sample Content"),
)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Put the above code inside any onPressed or onTap method and see the magic.&lt;/p&gt;

&lt;h3&gt;
  
  
  GetX Dialog
&lt;/h3&gt;

&lt;p&gt;This is also a simple way to show a dialog. But in this, we don’t have parameters like title and content, But we have to construct them manually. It accepts a widget and we have to build our Dialog from Scratch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Get.dialog(
Text("This is a simple Dialog"),
)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the above code will show a simple dialog with the text, &lt;strong&gt;This is a simple Dialog.&lt;/strong&gt; But it is not cool looking.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H3Z00PeY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/getx-dialogs/get-dialog-text.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H3Z00PeY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/getx-dialogs/get-dialog-text.png" alt="Get Dialog With Just Text"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Get Dialog With Just Text. Sure It’s not something we wanna do!&lt;/p&gt;



&lt;p&gt;So we should always return a Dialog widget from Get.dialog and put anything we want to show the user as the child of the Dialog Widget.&lt;/p&gt;

&lt;h3&gt;
  
  
  End
&lt;/h3&gt;

&lt;p&gt;You can find more articles related to GetX &lt;a href="https://mukhtharcm.com/tags/getx/"&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you found something useful here.&lt;/p&gt;

&lt;p&gt;I’m always open to suggestions!&lt;/p&gt;

&lt;p&gt;Let me know your suggestions and opinions in &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; DM or drop a mail a &lt;a href="//mailto:mukhtharcm@gmail.com"&gt;mukhtharcm@gmail.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you’re feeling too generous, you can support me through &lt;a href="https://buymeacoffee.com/mukhtharcm"&gt;Buy Me a Coffee&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally, if you found this helpful, please share this within your reach so that more people can benefit from this. And Follow me on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; for getting more posts like these 😉.&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>getx</category>
    </item>
    <item>
      <title>Check App on Different Screen Sizes and Orientations</title>
      <dc:creator>mukhtharcm</dc:creator>
      <pubDate>Fri, 30 Apr 2021 22:30:00 +0000</pubDate>
      <link>https://dev.to/mukhtharcm/check-app-on-different-screen-sizes-and-orientations-5g29</link>
      <guid>https://dev.to/mukhtharcm/check-app-on-different-screen-sizes-and-orientations-5g29</guid>
      <description>&lt;p&gt;You have successfully created a mobile app. And now you have to see how it may work on another device with different screen size. Grab your friend’s phone and Install the App on it. Right?&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://pub.dev"&gt;flutter package ecosystem&lt;/a&gt; has an amazing package named &lt;code&gt;device_preview&lt;/code&gt;which can help you with that. It allows us to view our App on Different form factors (phone, laptop, tablet, desktop) and different Operating Systems.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NbDl0zHC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/check-app-on-different-screen-sizes-and-orientations/device_preview_hu88a4be017f4f141e6f280c78d631a896_32498_800x0_resize_box_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NbDl0zHC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/check-app-on-different-screen-sizes-and-orientations/device_preview_hu88a4be017f4f141e6f280c78d631a896_32498_800x0_resize_box_2.png" alt="App running with Device Preview"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;App running with Device Preview&lt;/p&gt;



&lt;h3&gt;
  
  
  Adding packages
&lt;/h3&gt;

&lt;p&gt;For this tutorial, we just have to import the &lt;a href="https://pub.dev/packages/device_preview"&gt;device_preview&lt;/a&gt;to our pubspec.yaml file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies:
flutter:
sdk: flutter
device_preview: ^0.7.1

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setup
&lt;/h3&gt;

&lt;p&gt;Next, we have to import the package to our main.dart file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:device_preview/device_preview.dart';

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we have to wrap our root widget in DevicePreview. ie, we have to put DevicePreview inside runApp and provide our Root widget at the builder parameter of it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void main() {
runApp(
DevicePreview(
builder: (context) =&amp;gt; MyApp(),
),
);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we have to change the locale and builder parameter of MaterialApp to one provided with DevicePreview.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
locale: DevicePreview.locale(context),// Add locale
 builder: DevicePreview.appBuilder, // Add builder
 title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we run the app now, we can see the DevicePreview package in its glory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TASJ6zVi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/check-app-on-different-screen-sizes-and-orientations/device_preview_macbook_huf33aba6499f370a5ff0a0b0ea093749c_36962_800x0_resize_box_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TASJ6zVi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/check-app-on-different-screen-sizes-and-orientations/device_preview_macbook_huf33aba6499f370a5ff0a0b0ea093749c_36962_800x0_resize_box_2.png" alt="Device Preview Showing app running on a MacBook"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Device Preview Showing app running on a MacBook&lt;/p&gt;



&lt;p&gt;The bottom bar provided with the package has a couple of options. The first toggle allows us to completely turn off the Device Preview.&lt;/p&gt;

&lt;p&gt;The second option is to change the Device. Here we have the option to choose between multiple iPhones, Android Devices, an iMac Pro as well as MacBook and Linux, and windows systems. We also have an option to select a free-form Device.&lt;/p&gt;

&lt;p&gt;The third one is locale. If we change the locales here, the app will change it as it was changed on the real Device.&lt;/p&gt;

&lt;p&gt;And the next is Orientation. With this option, we can see how our App will look in Another Orientation, ie, landscape.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mnuI917T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/check-app-on-different-screen-sizes-and-orientations/device_preview_ipad_landscape_hu8fa5fa16ed0ec243c8cfbe456dd24f96_41843_800x0_resize_box_2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mnuI917T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://mukhtharcm.com/check-app-on-different-screen-sizes-and-orientations/device_preview_ipad_landscape_hu8fa5fa16ed0ec243c8cfbe456dd24f96_41843_800x0_resize_box_2.png" alt="The Device Preview showing an iPad in Landscape Mode"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The Device Preview showing an iPad in Landscape Mode&lt;/p&gt;



&lt;p&gt;And then there is an option to Hide device frames, show Keyboard, etc. I think they’re self-explanatory.&lt;/p&gt;

&lt;p&gt;The Next option is to change the Device Theme. Toggling it will simulate the Same effect on a Real Device.&lt;/p&gt;

&lt;h3&gt;
  
  
  Plugins
&lt;/h3&gt;

&lt;p&gt;The Device preview package has a real nice Plugin System. It has a Screenshot Plugin, File Explorer plugin, SharedPreferences Viewer, etc. And there is an option to build your own. You can find How to do that &lt;a href="https://aloisdeniel.github.io/flutter_device_preview/#/content/plugins/custom"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For Adding Plugins, we have to add the plugins array of Device Preview.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void main() {
runApp(
DevicePreview(
plugins: [
ScreenshotPlugin(),
],
builder: (context) =&amp;gt; MyApp(),
enabled: !kReleaseMode,
),
);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code will add Screenshot functionality to our App. If we click on the Screenshot button provided now on the bottom bar, A screenshot will be taken and we’ll be given a URL to view it.&lt;/p&gt;

&lt;p&gt;With all these, we can test how may our App look on Different Devices&lt;/p&gt;

&lt;p&gt;Hope you found something useful here.&lt;/p&gt;

&lt;p&gt;I’m always open to suggestions!&lt;/p&gt;

&lt;p&gt;Let me know your suggestions and opinions in &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; DM or drop a mail a &lt;a href="//mailto:mukhtharcm@gmail.com"&gt;mukhtharcm@gmail.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you’re feeling too generous, you can support me through &lt;a href="https://buymeacoffee.com/mukhtharcm"&gt;Buy Me a Coffee&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally, if you found this helpful, please share this within your reach so that more people can benefit from this. And Follow me on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; for getting more posts like these 😉.&lt;/p&gt;

</description>
      <category>flutter</category>
    </item>
    <item>
      <title>Sharing Files in Flutter</title>
      <dc:creator>mukhtharcm</dc:creator>
      <pubDate>Tue, 27 Apr 2021 22:30:00 +0000</pubDate>
      <link>https://dev.to/mukhtharcm/sharing-files-in-flutter-56b2</link>
      <guid>https://dev.to/mukhtharcm/sharing-files-in-flutter-56b2</guid>
      <description>&lt;p&gt;Sharing is an integral part of mobile apps. Millions of digital content are produced and consumed every minute. Because of this, we can’t avoid a feature like this on our mobile apps.&lt;/p&gt;

&lt;p&gt;There is a package named &lt;code&gt;share&lt;/code&gt; in Flutter to do just this. it can be used to share just text or even Files.&lt;/p&gt;

&lt;p&gt;First, let’s add the package to our pubspec.yaml file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies:
flutter:
sdk: flutter
share: ^2.0.1 # add the latest version from pub.dev

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To share a simple text, use &lt;code&gt;Share.share()&lt;/code&gt; anywhere on our App.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Share.share("Your Text to Share");

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will bring up the share dialog of respective platform, whether if you’re using Android or iOs.&lt;/p&gt;

&lt;p&gt;If we have to share Files, we can use &lt;code&gt;Share.shareFiles()&lt;/code&gt;it accepts a list of File Paths to share.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;File mycoolImage;
Share.share([mycoolImage.path,]);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;below is the same example from &lt;a href="https://dev.to/mukhtharcm/create-an-image-from-widget-in-flutter-1j4p-temp-slug-7132686"&gt;Generate Image from Widget Tutorial&lt;/a&gt;, but with the added function of sharing the generated Image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;void&amp;gt; takePicture() async {
RenderRepaintBoundary boundary = genKey.currentContext.findRenderObject();
ui.Image image = await boundary.toImage();
final directory = (await getApplicationDocumentsDirectory()).path;
ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();
File imgFile = new File('$directory/photo.png');
await imgFile.writeAsBytes(pngBytes);
await Share.shareFiles([imgFile.path]);//Sharing the generated Image
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hope you found something useful here.&lt;/p&gt;

&lt;p&gt;I’m always open to suggestions!&lt;/p&gt;

&lt;p&gt;Let me know your suggestions and opinions in &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; DM or drop a mail a &lt;a href="//mailto:mukhtharcm@gmail.com"&gt;mukhtharcm@gmail.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you’re feeling too generous, you can support me through &lt;a href="https://buymeacoffee.com/mukhtharcm"&gt;Buy Me a Coffee&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally, if you found this helpful, please share this within your reach so that more people can benefit from this. And Follow me on &lt;a href="https://twitter.com/mukhtharcm"&gt;Twitter&lt;/a&gt; for getting more posts like these 😉.&lt;/p&gt;

</description>
      <category>flutter</category>
    </item>
  </channel>
</rss>
