Skip to main content

Posts

BLoC (Business Logic Component) state management in Flutter

  Let’s go step by step — you’ll understand BLoC (Business Logic Component) state management in Flutter clearly and practically with a real example . 🧠 What is BLoC? BLoC helps separate your UI (presentation) from your business logic . It follows the principle: UI sends events → BLoC processes them → emits new states → UI rebuilds. So instead of writing logic inside your setState() , you handle logic inside the BLoC , and the UI just listens. ⚙️ Core Concepts Concept Role Example Event Represents what happened (user actions) IncrementEvent , FetchUserEvent State Represents the UI condition CounterInitial , CounterUpdated(5) Bloc Handles logic, maps Events → States CounterBloc BlocProvider Makes a Bloc available to widgets BlocProvider(create: (_) => CounterBloc()) BlocBuilder Rebuilds UI when state changes Updates counter display automatically 🧩 Example: Counter App using BLoC Let’s build a simple counter app using flutter_bloc package. 🪜 Step 1: Add Dependency In pu...
Recent posts

Set up Node.js

  Set up Node.js . On Apple Silicon, the setup is almost the same as Intel, but some tools need ARM64 builds. I'll give you the main methods step by step: ✅ Method 1: Install Node.js with Homebrew (simple & recommended) Install Homebrew (if not already installed): /bin/bash -c " $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh) " Install Node.js (includes npm): brew install node Verify installation : node -v npm -v You should see versions (e.g., v22.x.x for Node and 10.x.x for npm). ✅ Method 2: Install Node.js using Node Version Manager (nvm) (best for multiple versions) 👉 Recommended if you work on different projects needing different Node versions. Install nvm : curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash Load nvm (add this to your ~/.zshrc or ~/.bashrc ): export NVM_DIR= " $HOME /.nvm" [ -s " $NVM_DIR /nvm.sh" ] && \. " $NVM_DIR...

Set up MySQL on your MacBook Pro with the M1 (Apple Silicon)

Set up MySQL on your MacBook Pro with the M1 (Apple Silicon). I'll give you the step-by-step installation methods . You can choose whichever suits you best: ✅ Method 1: Install MySQL using Homebrew (Recommended) This is the easiest and cleanest way. Install Homebrew (if not already installed): Open Terminal and run:      Terminal Command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" Install MySQL : brew install mysql Start MySQL service : brew services start mysql Check MySQL status : brew services list Login to MySQL : mysql -u root (Optional) Set root password : ALTER USER 'root' @ 'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password' ; FLUSH PRIVILEGES; ✅ Method 2: Install MySQL using the official DMG installer If you prefer GUI setup: Go to MySQL Community Downloads . Select macOS (ARM64) for M1. Download the DMG Archive and install it...

The background and foreground state of the app itself in Flutter

About the  background and foreground state of the app itself in Flutter . This is different from widget state — this is about the lifecycle of the entire app . 🔹 Foreground vs Background in Flutter Foreground state → your app is visible on screen (user is actively using it). Background state → user pressed Home , switched to another app, or screen is off (your app is running but not visible). Terminated → user killed the app or system closed it. 🔹 Detecting App Lifecycle in Flutter Flutter provides WidgetsBindingObserver or the AppLifecycleState enum. Example:  import 'package:flutter/material.dart'; class AppLifecycleExample extends StatefulWidget {   @override   _AppLifecycleExampleState createState() => _AppLifecycleExampleState(); } class _AppLifecycleExampleState extends State<AppLifecycleExample>     with WidgetsBindingObserver {   AppLifecycleState? _lastState;   @override   void initState() {     ...

About of Microservices

  Microservices architecture is  a software development approach where an application is structured as a collection of small, independent, and loosely coupled services .  These services are designed to handle specific business functionalities and can be developed, deployed, and scaled independently.  This approach contrasts with monolithic architectures, where the entire application is built as a single, large codebase.   Key Characteristics of Microservices: Independent Deployability: Each microservice can be deployed independently without affecting other services.   Loosely Coupled: Services interact with each other through well-defined APIs, minimizing dependencies between them.   Bounded Context: Each service focuses on a specific business capability within a defined context.   Decentralized Governance: Teams can choose different technologies and tools for different services.   Resilience: Failure of one service does not necessarily bring...

SQL All Commands

 SQL All Commands Here is a list of common MySQL commands, categorized by their usage. This covers creating, managing, and interacting with databases and tables. 1. Database Commands Create a new database : sql Copy code CREATE DATABASE database_name; Select a database to use : sql Copy code USE database_name; Show all databases : sql Copy code SHOW DATABASES; Delete a database : sql Copy code DROP DATABASE database_name; 2. Table Commands Create a new table : sql Copy code CREATE TABLE table_name ( column1 datatype, column2 datatype, ... ); Show all tables in the selected database : sql Copy code SHOW TABLES; Show table structure (schema) : sql Copy code DESCRIBE table_name; Rename a table : sql Copy code RENAME TABLE old_table_name TO new_table_name; Drop a table : sql Copy code DROP TABLE table_name; Add a column to a table : sql Copy code ALTER TABLE table_name ADD column_name datatype; Modify a column in a table : sql Copy code ALTER TABLE table_name MODI...