Dart Basic Course
Dart Bangla Course π₯ Checkout playlist on youtube Coding in DartPad dartpad Main Method & Comments DataTypes Number in dart String Boolean List Map Condition & break If-Else For Loop Links: ...
Dart Bangla Course π₯ Checkout playlist on youtube Coding in DartPad dartpad Main Method & Comments DataTypes Number in dart String Boolean List Map Condition & break If-Else For Loop Links: ...
This is the very first question asked by many after they start their Flutter journey. Here I have included necessary stuff from my knowledge, not strictly limited to Flutter but including the related things as well. I can point to a single direction from where they can start their journey as a Flutter developer. Also, you can share to save your time as well. Suggestions are welcome, make an issue and then PR. Documentation Yes, there is no better option than official Flutter documentation. ...
Abstract class You went to your local restaurant for breakfast. When you got there, you saw a lump of raw dough sitting in front of the stove. Then a boy came over and asked, βRuti, paratha, or naan?β Whatever you say, they prepare it right on the spot and serve it to you. Here the dough on the counter is the abstract class. abstract class Dough{} It exits, but it has no final form. You can not eat it raw rough dough. In programming we would say, you can not initiate it. ...
Abstract class You went to your local restaurant for breakfast. When you got there, you saw a lump of raw dough sitting in front of the stove. Then a boy came over and asked, βRuti, paratha, or naan?β Whatever you say, they prepare it right on the spot and serve it to you. ...
I hope youβve already checked the Abstract & Generic . We already know what abstract class is and it can be extend from anywhere by importing the abstract class. It offered the benefits of restriction extending class outside the library. abstract class ApiState {} class Loading extends ApiState {} class Success extends ApiState {} class Error extends ApiState {} But we create a sealed class, it can not be only extend from that library/file. Note each file is a library, and you can use part/part of to combine multiple file. ...
I hope youβve already checked the Abstract & Generic. We already know what abstract class is, and it can be extend from anywhere. // api_state.dart abstract class ApiState {} class Loading extends ApiState {} class Success extends ApiState {} // api_provider.dart class Error extends ApiState {} Sealed class But Sealed class restrict extending class outside the library. You can only extends it within the same library/file. ...
Tip: I highly recommend checking out my first video, Vim for Absolute Beginners, before diving into the setup! We are going to config our Nvim for Flutter We are going to play with $~/.config/nvim. β― tree βββ init.lua βββ lazy-lock.json βββ lua βΒ βββ config βΒ βΒ βββ keymap.lua # gonna add a keymap βΒ βΒ βββ run_file.lua # will create to for hot-reload βΒ βΒ βββ lazy.lua βΒ βΒ βββ lsp βΒ βΒ βββ .... βΒ βΒ βββ init.lua βΒ βΒ βββ servers βΒ βΒ βββ ..... βΒ βΒ βββ flutter.lua # our flutter configs βΒ βΒ βββ lua_ls.lua βΒ βββ plugins βΒ βββ .... # rest stuff βΒ βββ flutter_tools.lua # flutter nvim plugins βΒ βββ pubspec_assist.lua # show out-dated pkg Custom keymap for hot-reload --- nvim/config/run_file.lua local M = {} -- Dart (Flutter Reload) function M.fileRunner() local ft = vim.bo.filetype if ft == "dart" then local terms = require("toggleterm.terminal").get_all() if #terms == 0 then vim.notify("β οΈ No terminal running", vim.log.levels.WARN) return end terms[1]:send("r\n") vim.notify("π₯ Sent hot reload to Flutter terminal") else vim.notify("β Unsupported filetype: " .. ft) end end return M Also make sure to have ...
Flutter == vs Value Equality code import 'package:equatable/equatable.dart'; class Contact extends Equatable { const Contact({required this.type, required this.value}); final String type; final String value; @override List<Object?> get props => [type, value]; } class Phone with Equatable { const Phone({this.isPrimary = false, this.contact}); final bool isPrimary; final Contact? contact; @override List<Object?> get props => [...contact?.props ?? [], isPrimary]; } void main() { Contact a = Contact(type: "phone", value: "0101"); Contact b = Contact(type: "phone", value: "0101"); if (a == b) { print("same same ...."); } else { print("a: ${a.toString()}"); print("b: ${b.toString()}"); } } equatable on pub.devβ
user.dart import 'package:example/models/contact.dart'; import 'package:json_annotation/json_annotation.dart'; part 'user.g.dart'; // the `user` is the fileName @JsonEnum(valueField: "value") enum Gender { male("m"), female("f"); const Gender(this.value); final String value; } @JsonSerializable(fieldRename: FieldRename.screamingSnake) class User { User({ required this.name, required this.dateOfBirth, required this.gender, required this.contact, required this.presentAddress, }); final String name; final Gender gender; @JsonKey(name: "dob") final DateTime? dateOfBirth; final Contact contact; final String presentAddress; factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json); Map<String, dynamic> toJson() => _$UserToJson(this); } Custom Converter class DateTimeConverter implements JsonConverter<DateTime?, Map<String, dynamic>?> { const DateTimeConverter(); @override DateTime? fromJson(Map<String, dynamic>? json) { if (json == null) return null; final second = json["seconds"]; return DateTime.fromMillisecondsSinceEpoch(second); } @override Map<String, dynamic>? toJson(DateTime? object) { if (object == null) return null; return {'seconds': (object.millisecondsSinceEpoch / 1000).round()}; } } Custom config build.yaml targets: $default: builders: json_serializable: options: # Options configure how source code is generated for every # `@JsonSerializable`-annotated class in the package. # # The default value for each is listed. any_map: false checked: false constructor: "" create_factory: true create_field_map: false create_json_keys: false create_json_schema: true create_per_field_to_json: false create_to_json: true date_time_utc: true disallow_unrecognized_keys: false explicit_to_json: false field_rename: snake generic_argument_factories: false ignore_unannotated: false include_if_null: true json_serializable on pub.devβ
Flutter Freezed | Models, copyWith, JSON Serialization, Generics & Union Types Make sure to watch json_seriliazble first. Freezed class address.dart { "success": true, "data": { "street": "123 Main Street", "district": "Dhaka", "country": "Bangladesh" }, "message": "Address fetched" } import 'package:freezed_annotation/freezed_annotation.dart'; part 'address.freezed.dart'; part 'address.g.dart'; @freezed abstract class Address with _$Address { const factory Address({ required String street, required String district, required String country, }) = _Address; factory Address.fromJson(Map<String, Object?> json) => _$AddressFromJson(json); static const Address present = Address( street: "present", district: "addr.dis", country: "BD", ); static const Address permanent = Address( street: "permanent", district: "addr.dis", country: "...", ); } person.dart { "success": true, "data": { "name": "John Doe", "age": 25, "address": "Earth", "skills": ["Dart", "Flutter"], "presentAddress": { "street": "123 Main Street", "district": "Dhaka", "country": "Bangladesh" }, "permanentAddress": { "street": "45 Lake Road", "district": "Chattogram", "country": "Bangladesh" } }, "message": "Person fetched" } import 'package:freezed_annotation/freezed_annotation.dart'; import 'address.dart'; part 'user.freezed.dart'; part 'user.g.dart'; @freezed abstract class Person with _$Person { const factory Person({ required String name, int? age, @Default("Eath") String? address, @Default([]) List<String> skills, required Address presentAddress, Address? permanentAddress, }) = _Person; factory Person.fromJson(Map<String, Object?> json) => _$PersonFromJson(json); static const Person ui = Person( name: "0", age: 0, skills: [], presentAddress: Address.present, permanentAddress: Address.permanent, ); } Generic api_response.dart import 'package:freezed_annotation/freezed_annotation.dart'; part 'api_response.freezed.dart'; part 'api_response.g.dart'; @Freezed(genericArgumentFactories: true) abstract class ApiResponse<T> with _$ApiResponse<T> { const factory ApiResponse({ required bool success, T? data, String? message, }) = _ApiResponse<T>; factory ApiResponse.fromJson( Map<String, dynamic> json, T Function(Object?) fromJsonT, ) => _$ApiResponseFromJson(json, fromJsonT); } Union code-snippet We are using type instead of runtimetype ...