YayoCode Tutorials and Courses
website·Indexed 32 days ago
https://yayocode.comA 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.
What's inside YayoCode
- 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.
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.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.
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.
FixedResolutionViewportallows the game to operate with a virtual screen size (virtualWidthxvirtualHeight). It maintains the aspect ratio by adding black bars (letterboxing) if the device screen size differs from the virtual resolution.Implement a Flutter CRUD architecture with Firebase and Cubit
To build a scalable CRUD application in Flutter, use a three-layer architecture:
- 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.
- Data Sources: Generic providers that interact directly with external APIs or databases (e.g.,
- 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.
- 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
- Data Layer: Manages raw data interactions. It is split into:
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 explicitwhileloop for the main loop; instead, therender()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 whileUnderstand 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.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:
- Data Layer: Divided into two parts:
- Data Sources: Handles direct connections to external sources (e.g., REST APIs via the
httppackage or local databases). - Repositories: Orchestrates data from multiple sources and provides a clean API to the business logic layer.
- Data Sources: Handles direct connections to external sources (e.g., REST APIs via the
- Business Logic Layer (Bloc/Cubit): Manages the application state and contains the business logic that drives the UI.
- Presentation Layer: Contains the UI widgets that the end-user interacts with.
- Data Layer: Divided into two parts:
Implement Flutter Bloc architecture layers
To implement a scalable architecture using the
flutter_blocpackage, separate the application into three distinct layers:- User Interface (UI): Responsible for rendering the view and sending events to the Bloc.
- Business Logic (Blocs): Manages the state of the application and processes events.
- 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.
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 returnfalsebecause 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); // falseImplement 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
TextureRegionandAnimationobjects to manage resource loading. - Screens: An abstract
Screenclass 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.
- MainFlappyBird: The entry point of the game (inherits from
Implement REST API endpoints with Ktor Routing
Use Ktor'sRouteextension to define API endpoints. Usecall.receive<T>()to parse request bodies andcall.respond()to send JSON responses. In this architecture, aUserServiceis 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))) } }