Posts

How to Create and Customize Radio Buttons in Flutter: A Beginner’s Guide

Image
  Introduction In this blog post, we will explore how to create a simple Radio Button example in Flutter. Radio buttons are a great way to present a set of options where only one option can be selected at a time. This is commonly used for gender selection, preferences, or any binary choices. We will walk through the Flutter code required to implement a basic gender selection form using Radio Buttons . By the end of this tutorial, you will have a clear understanding of how to use Radio Buttons in Flutter and how to handle user input. What is a Radio Button? A Radio Button is a type of input control that allows users to select one option from a set of mutually exclusive options. In Flutter, you can use the Radio widget to create radio buttons, and the RadioListTile widget to combine a radio button with a text label. Example Overview In this example, we will create a simple application with two Radio Buttons for selecting Gender : Male and Female . We will also include a Submit bu

Step-by-Step Guide to Using StreamBuilder in Flutter

Image
  The  StreamBuilder is a widget that builds itself based on the latest snapshot of interaction with a stream. This is mainly used in applications like chat application clock applications where the widget needs to rebuild itself to show the current snapshot of data. But today we will use this to make an app for increment and decrement of the counter value. (Yeah, It boring to see the same example, but this is a perfect example to show the usage of Streams). Let’s first understand the  StreamController, streams,  and  sink  using a simple diagram. Types of Streams Single-subscription streams : Can only be listened to once. They are ideal for handling events that are intended to be consumed only once, like file I/O operations. Broadcast streams : Allow multiple listeners and are useful for distributing the same data events to multiple listeners simultaneously.   Common Use Cases File Operations : Reading or writing data to and from files in a non-blocking way. Network Communications : Ha

Firebase Authentication in Flutter: Email and Password Login Guide

  firebase_core : any firebase_auth : anyimport 'package:flutter/material.dart' ; import 'package:firebase_core/firebase_core.dart' ; import 'package:firebase_auth/firebase_auth.dart' ; void main () async { WidgetsFlutterBinding . ensureInitialized () ; await Firebase . initializeApp () ; runApp ( MyApp () ) ; } class MyApp extends StatelessWidget { @override Widget build ( BuildContext context ) { return MaterialApp ( home : LoginPage () , ) ; } } class LoginPage extends StatefulWidget { @override _LoginPageState createState () => _LoginPageState () ; } class _LoginPageState extends State < LoginPage > { final FirebaseAuth _auth = FirebaseAuth .instance; final TextEditingController _emailController = TextEditingController () ; final TextEditingController _passwordController = TextEditingController () ; Future < void > _login () async { try { UserCredential userCredential = await _auth.signInWithEma

API Data Fetching and Display in Flutter

  import 'dart:convert' ; import 'package:flutter/material.dart' ; import 'package:http/http.dart' as http; void main (){ runApp ( MyApp () ) ; } class MyApp extends StatelessWidget { const MyApp ( { super . key } ) ; @override Widget build ( BuildContext context ) { return MaterialApp ( theme : ThemeData ( primarySwatch : Colors .red ) , home : Api () , ) ; } } class Api extends StatefulWidget { const Api ( { super . key } ) ; @override State < Api > createState () => _ApiState () ; } class _ApiState extends State < Api > { User ? userData; var userId; var id; var title; Future < void > getData () async { final url = "https://jsonplaceholder.typicode.com/albums/1" ; final response = await http.get ( Uri . parse ( url ) ) ; print ( response .body ) ; if ( response .statusCode == 200 ) { var responseData = json.decode ( response .body ) ; userId