Skip to content

AhmedYousefDev/Important-in-Flutter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 

Repository files navigation

🌟 Flutter Essentials Guide 🌟

Introduction

Flutter is a powerful framework for building cross-platform applications. This guide provides essential commands, important packages, common issues, and their solutions to help you master Flutter development.


🔧 1. Important Commands

📝 General Commands

flutter doctor           # Checks Flutter installation and dependencies
flutter doctor --android-licenses # Command: Accept Android Licenses
flutter create my_app    # Creates a new Flutter project
flutter run              # Runs the app on a connected device or emulator
flutter build apk        # Builds an APK for Android
flutter build ios        # Builds an iOS app
flutter clean            # Clears the build cache
flutter pub get          # Fetches dependencies from pubspec.yaml
flutter pub upgrade      # Updates dependencies to the latest versions
flutter analyze          # Analyzes the project for potential issues
flutter format .         # Formats all Dart files in the project
flutter test             # Runs tests in the project

🔠 Dart Commands

dart --version         # Checks Dart version
dart run file.dart     # Runs a specific Dart file
dart analyze          # Analyzes Dart code for errors and warnings
dart fix --apply      # Removes unused imports and cleans code

🌐 Build APK for Different Architectures

flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi

Explanation:

  • Builds separate APKs for different architectures (arm, arm64, x64).
  • --split-per-abi ensures optimized APKs for specific CPU architectures, reducing APK size.
  • Useful for Play Store deployment to ensure users download only the compatible APK.

Gradle Issues Commands

cd android && ./gradlew clean        # Cleans the Gradle build cache
cd android && ./gradlew build         # Builds the Android project
cd android && ./gradlew dependencies  # Lists dependencies and resolves conflicts
cd android && ./gradlew --stop        # Stops all Gradle daemons
cd android && ./gradlew --refresh-dependencies  # Forces dependency refresh
cd android && ./gradlew clean assembleDebug  # Compiles the app in debug mode

🔍 Basic Git Commands

git init # Initializes a new Git repository
git clone <repo_url> # Clones an existing Git repository
git status # Shows the current status of your working directory
git add . # Adds all changes to the staging area
git commit -m "message" # Commits the staged changes with a message
git push origin <branch> # Pushes committed changes to the remote repository
git pull origin <branch> # Fetches and merges changes from the remote repository
git branch # Lists all branches in the repository
git checkout <branch> # Switches to a different branch
git merge <branch> # Merges the specified branch into the current branch

🎮 Windows Platform Commands

flutter pub global activate msix
flutter build windows --release
dart pub global run msix:create

💡 2. Important Packages

🔄 State Management

  • provider - Recommended approach for state management.
  • riverpod - A powerful alternative to provider.
  • bloc - Business logic component for structured state management.
  • get - Simple and efficient state management solution.

📞 Networking

  • http - Simple package for REST API requests.
  • dio - Advanced HTTP client with interceptors and error handling.
  • graphql_flutter - For integrating GraphQL in Flutter.

📚 Database and Storage

  • sqflite - SQLite plugin for local database storage.
  • hive - Lightweight and fast key-value database.
  • shared_preferences - Store small amounts of persistent data.
  • firebase_core & cloud_firestore - Firebase Firestore for cloud storage.

🎨 UI & Design

  • flutter_svg - SVG image support.
  • cached_network_image - Caches images for performance.
  • lottie - Adds Lottie animations.
  • flutter_screenutil - Helps with responsive UI design.

🔑 Authentication

  • firebase_auth - Firebase authentication support.
  • google_sign_in - Google login integration.
  • flutter_facebook_auth - Facebook login integration.
  • sign_in_with_apple - Apple login support.

Others

  • flutter_local_notifications - Local push notifications.
  • geolocator - Fetch device location.
  • url_launcher - Open URLs, emails, or phone calls.
  • flutter_native_splash - Custom splash screens.

🔧 3. Common Issues & Solutions

Issue: App Stuck on White Screen

Solution: Ensure main() calls WidgetsFlutterBinding.ensureInitialized().

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(MyApp());
}

Issue: Dependencies Not Found

Solution: Run flutter pub get.

Issue: Emulator Not Detecting Changes

Solution: Run flutter clean followed by flutter run.

Issue: Gradle Build Failing in Android

Solution:

  • Ensure android/gradle/wrapper/gradle-wrapper.properties has a compatible Gradle version.
  • Run flutter doctor and resolve missing dependencies.

❌ Issue: iOS Build Failing

Solution:

  • Ensure Xcode is installed and updated.
  • Run pod install inside ios/ directory.

❌ Issue: Firebase Not Working on iOS

Solution:

  • Make sure GoogleService-Info.plist is correctly placed in ios/Runner/.
  • Add use_frameworks! in the Podfile and run pod install.

❌ Issue: PlatformException in Camera or Location Plugins

Solution:

  • Add required permissions in AndroidManifest.xml (for Android) and Info.plist (for iOS).

Common Signing Issues & Solutions

❌ Issue: Keystore Not Found

Solution: Ensure that the keystore.jks file exists and the path is correct in key.properties.

❌ Issue: Incorrect Keystore Password

Solution: Double-check the storePassword and keyPassword in key.properties and ensure they match the actual keystore.

❌ Issue: Missing Signing Config in build.gradle

Solution:

android {
    signingConfigs {
        release {
            storeFile file("../keystore.jks")
            storePassword "your_password"
            keyAlias "your_key_alias"
            keyPassword "your_key_password"
        }
    }
}

❌ Issue: Invalid Key Alias

Solution: Run the following command to list key aliases in your keystore:

keytool -list -v -keystore your_keystore.jks

❌ Issue: SHA1 or SHA256 Mismatch

Solution: Get the correct fingerprint using:

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

❌ Issue: Play Store Rejecting APK Due to Signing

Solution: Ensure your app is signed with the correct upload key and matches the Play Console key.

❌ Issue: jarsigner Verification Failed

Solution: Run the following command to verify the signature:

jarsigner -verify -verbose -certs your_app.apk
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<key>NSCameraUsageDescription</key>
<string>We need camera access</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We need your location</string>

🌟 How to Change Package Name in Flutter 🌟

Changing the package name in a Flutter project is a crucial step when customizing your application. You can easily achieve this using the change_app_package_name package or by manually updating the necessary files.


🛠️ Method 1: Using change_app_package_name

This is the simplest and fastest method.

🔄 Step 1: Add Dependency

Run the following command in your terminal:

flutter pub add change_app_package_name

🔄 Step 2: Change the Package Name

Run the command below, replacing com.new.package.name with your desired package name:

flutter pub run change_app_package_name:main com.new.package.name

This command will automatically update all necessary files.

🔄 Step 3: Verify the Changes

After running the command, check that the following files have been updated:

  • android/app/src/main/AndroidManifest.xml
  • android/app/build.gradle
  • android/app/src/main/kotlin/com/new/package/name/MainActivity.kt (if using Kotlin)
  • android/app/src/main/java/com/new/package/name/MainActivity.java (if using Java)
  • ios/Runner.xcodeproj/project.pbxproj
  • ios/Runner/Info.plist

🔄 Step 4: Clean and Rebuild the Project

Run the following commands to apply the changes:

flutter clean
flutter pub get
flutter run

🛠️ Method 2: Manual Package Name Change

For greater control, you can manually update the package name by modifying key project files.

🌟 Step 1: Update the Android Package Name

  1. Open android/app/src/main/AndroidManifest.xml and change the package attribute:
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.new.package.name">
  2. Update android/app/build.gradle:
    android {
        defaultConfig {
            applicationId "com.new.package.name"
        }
    }
  3. Rename the folder structure inside android/app/src/main/kotlin/ (or java/) to match the new package name.

🌟 Step 2: Update the iOS Bundle Identifier

  1. Open ios/Runner.xcodeproj in Xcode.
  2. Go to Runner > General > Identity and change the Bundle Identifier.
  3. Update ios/Runner/Info.plist:
    <key>CFBundleIdentifier</key>
    <string>com.new.package.name</string>

🌟 Step 3: Clean and Rebuild the Project

After making these changes, run:

flutter clean
flutter pub get
flutter run

This ensures that the new package name is applied successfully and your Flutter project is configured correctly.


🌟 How to Build a Windows App Using Flutter 🌟

Flutter allows developers to build high-performance applications for Windows. This guide provides a detailed step-by-step approach to setting up, building, and optimizing a Windows app using Flutter.


🔧 1. System Requirements

Before you start, ensure your system meets the following requirements:

  • ✔ Windows 10 or later (64-bit)
  • ✔ PowerShell 5.0 or later
  • ✔ Git for Windows
  • ✔ Visual Studio 2022 (with C++ development tools)
  • ✔ Flutter SDK (latest stable version)

🔄 Install Flutter SDK

Download and extract Flutter from the official site:

https://flutter.dev/docs/get-started/install/windows

Add Flutter to the system path and verify the installation with:

flutter doctor

Ensure there are no missing dependencies.


🛠️ 2. Enable Windows Desktop Support

Run the following command to enable Windows development in Flutter:

flutter config --enable-windows-desktop

Check if Windows support is enabled by running:

flutter doctor

If everything is correctly set up, you should see Windows (desktop) listed as a supported platform.


📝 3. Create a New Windows Flutter Project

Create a new Flutter project with:

flutter create my_windows_app
cd my_windows_app

To confirm Windows support, list available devices:

flutter devices

🎮 4. Run the Windows App

To run your Windows Flutter app:

flutter run -d windows

If you encounter issues, try:

flutter clean
flutter pub get
flutter run -d windows

🔧 5. Configure Windows-Specific Settings

🏷 Modify windows/runner/main.cpp

This is the entry point for the Windows app. You can modify it to adjust behavior or add native functionality.

🌟 Change the Application Icon

Replace windows/runner/resources/app_icon.ico with your own icon. Then, modify windows/CMakeLists.txt to reference the new icon.

🏠 Customize the Window Size

Edit windows/runner/main.cpp and modify the CreateAndShowWindow function:

window.CreateAndShow(L"My Windows App", {100, 100, 800, 600});

💻 6. Build the Windows App for Release

Once development is complete, build the Windows executable:

flutter build windows

This creates an executable in build/windows/runner/Release/.


📁 7. Distribute the Windows App

💼 Package the App

You can package the app into an installer using NSIS or Inno Setup:

💾 Zip and Share

Alternatively, zip the build/windows/runner/Release/ folder and share it directly.


8. Common Issues & Solutions

Issue: Windows app fails to launch

Solution:

  • Ensure all dependencies are installed (flutter doctor)
  • Try running flutter clean followed by flutter build windows

Issue: flutter run -d windows does not detect Windows

Solution:

  • Run flutter doctor to check if Windows support is enabled.
  • If missing, enable it using flutter config --enable-windows-desktop.

Issue: Slow performance on Windows

Solution:

  • Ensure you are using release mode for better performance:
    flutter build windows --release
  • Optimize UI rendering using const widgets where possible.

🎭 9. Best Practices for Windows Flutter Apps

  • ✨ Use Platform Channels to interact with Windows-specific APIs.
  • ✨ Optimize state management with provider or riverpod.
  • ✨ Implement error logging with sentry_flutter.
  • ✨ Ensure the UI is responsive for different window sizes.

Best Practices in Flutter Development

  • Use const for widgets that don’t change to improve performance.
  • Organize code into separate files for readability.
  • Optimize app size by using WebP images instead of PNGs.
  • Write unit and widget tests using flutter_test package.

Conclusion

Flutter is an ever-evolving framework, and mastering its commands, packages, and debugging techniques will help you build efficient, scalable applications. Keep experimenting and stay updated with new features! 🚀

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published