YayoCode Tutorials and Courses

website·Indexed 32 days ago

https://yayocode.com

A collection of programming guides, codelabs, and courses focusing on Dart and Flutter development. Content includes architecture patterns using Cubit and Bloc, unit testing, Firebase integration, Flame game development, and LibGDX. It also features Dart 3 updates, coding interview solutions, and Android development tutorials.

Tokens
39.4K
Snippets
189
Records
256
Agent score
60%

What's inside YayoCode

  1. Overview of the Flame Game Engine

    Flame is a modular game engine built for Flutter. It provides a game loop implementation and a set of core functionalities required for game development. Because it is built on Flutter, games developed with Flame are multiplatform and can run on Windows, Linux, macOS, Android, iOS, and the Web from a single codebase without modification.
  2. Overview of the libGDX framework

    libGDX is a cross-platform game development framework that allows developers to write code once and execute it across multiple platforms without modification. Supported platforms include Windows, Linux, MacOS, Android, iOS, and JavaScript/WebGL. A key advantage is the ability to perform rapid testing on a desktop computer before deploying to mobile devices, avoiding the overhead of emulators during the primary development cycle.
  3. Overview of Map types in Dart

    A Map is a collection that stores items in key-value pairs. Dart provides three primary Map implementations:

    • HashMap: Unordered; no specific iteration order is guaranteed.
    • LinkedHashMap: Iterates in the order that keys were inserted.
    • SplayTreeMap: Iterates keys in sorted order.
  4. Understand Canvas and Viewport in Flame

    In Flame, the Canvas represents the total available area on the device screen where shapes and images are painted. The Viewport is used to unify multiple screen sizes and aspect ratios by translating and resizing the canvas.

    FixedResolutionViewport allows the game to operate with a virtual screen size (virtualWidth x virtualHeight). It maintains the aspect ratio by adding black bars (letterboxing) if the device screen size differs from the virtual resolution.

  5. Implement a Flutter CRUD architecture with Firebase and Cubit

    To build a scalable CRUD application in Flutter, use a three-layer architecture:

    1. Data Layer: Manages raw data interactions. It is split into:
      • Data Sources: Generic providers that interact directly with external APIs or databases (e.g., FirebaseDataSource).
      • Repositories: Wrappers around data sources that provide a clean API for the business logic layer.
    2. Business Logic Layer: Uses Cubits to respond to presentation layer inputs and emit new states. It acts as the bridge between the UI and the Data Layer.
    3. Presentation Layer: Renders the UI based on the current state and handles user input/lifecycle events.

    Recommended Tech Stack:

    • State Management: flutter_bloc (Cubit)
    • Dependency Injection: get_it
    • Authentication UI: firebase_ui_auth
    • Database: cloud_firestore
    • File Storage: firebase_storage
  6. Implement the Main Loop in libGDX

    Unlike traditional applications that only respond to user input, games require a continuous loop to handle AI, movement, collisions, and rendering even when the user is idle. In libGDX, there is no explicit while loop for the main loop; instead, the render() method serves as the body of the main loop, executing repeatedly until the application exits.
    while( user doesn't exit )
            check for user input
            run AI
            move enemies
            resolve collisions
            draw graphics
            play sounds
    end while
  7. Understand 100% Sound Null Safety in Dart 3

    Starting with Dart 3, the language is 100% sound null safety. This means the compiler enforces stronger null checks at compile-time; attempting to assign a null value to a non-nullable variable results in a compile-time error, reducing runtime null-related crashes.
  8. Implement a layered architecture for Flutter apps with Cubit

    To create a scalable Flutter application that supports unit and widget testing, use a three-layer architecture based on the Flutter Bloc pattern:

    1. Data Layer: Divided into two parts:
      • Data Sources: Handles direct connections to external sources (e.g., REST APIs via the http package or local databases).
      • Repositories: Orchestrates data from multiple sources and provides a clean API to the business logic layer.
    2. Business Logic Layer (Bloc/Cubit): Manages the application state and contains the business logic that drives the UI.
    3. Presentation Layer: Contains the UI widgets that the end-user interacts with.
  9. Implement Flutter Bloc architecture layers

    To implement a scalable architecture using the flutter_bloc package, separate the application into three distinct layers:

    1. User Interface (UI): Responsible for rendering the view and sending events to the Bloc.
    2. Business Logic (Blocs): Manages the state of the application and processes events.
    3. Data Layer:
      • Data Provider: Handles raw API calls and external data sources.
      • Repository: Acts as a mediator that reorganizes, mixes, or modifies data from providers before sending it to the Bloc.
  10. Understand default object equality in Dart

    In Dart, the == operator checks for referential equality (memory address) rather than value equality for class instances. If two different objects are created with the same property values, == will return false because they reside at different memory addresses.
    class Car {
      final String brand;
      Car(this.brand);
    }
    
    final car1 = Car('Toyota');
    final car2 = Car('Toyota');
    print(car1 == car2); // false
  11. Implement basic game architecture for Flappy Bird

    The game is structured using the following class responsibilities:

    • MainFlappyBird: The entry point of the game (inherits from Game). Responsible for loading assets and initializing the game screen.
    • Assets: A utility class containing static references to TextureRegion and Animation objects to manage resource loading.
    • Screens: An abstract Screen class used to reduce boilerplate code across different game states/screens.
    • Game Objects (Bird, Pipe, Counter): Classes that track position, current state, and accumulated time. Each includes an update() method for behavior logic and state-change methods (e.g., hurt() for collisions).
    • Counter: A specific object used to trigger a score increment when it collides with the Bird.
  12. Implement REST API endpoints with Ktor Routing

    Use Ktor's Route extension to define API endpoints. Use call.receive<T>() to parse request bodies and call.respond() to send JSON responses. In this architecture, a UserService is injected via Koin to handle business logic.
    fun Route.userController() {
        val userService by inject<UserService>()
    
        get("/user") {
            call.respond(ResponseBase(data = userService.userList()))
        }
    
        post("/user") {
            val person = call.receive<User>()
            call.respond(ResponseBase(data = userService.addUser(person)))
        }
    
        delete("/user/{id}") {
            val id = call.parameters["id"]?.toInt()!!
            call.respond(ResponseBase(data = userService.removeUser(id)))
        }
    }