Skip to content

Instantly share code, notes, and snippets.

View mhadaily's full-sized avatar
🎯
Let's Flutter

Majid Hajian mhadaily

🎯
Let's Flutter
View GitHub Profile
@mhadaily
mhadaily / disable-tab.dart
Created March 7, 2022 16:17
Disable tab index in Flutter
import 'package:flutter/material.dart';
void main() {
runApp(const TabBarDemo());
}
class TabBarDemo extends StatefulWidget {
const TabBarDemo();
@override
@mhadaily
mhadaily / index.html
Last active January 18, 2022 00:48
Adding custom DOM elements using HTML slots to render platform views in the Flutter web
<script>
document.querySelector('#username').addEventListener('input', console.log);
document.querySelector('#password').addEventListener('input', console.log);
</script>
@mhadaily
mhadaily / Update website if there is new servicer worker update found.md
Created November 14, 2020 14:14
Use it in your index.html file in Flutter Web.
function invokeServiceWorkerUpdateFlow() {
  // you have a better UI here, reloading is not a great user experince here.
  const confirmed = confirm('New version of the app is available. Refresh now');
  if (confirmed) {
    window.location.reload();
  }
}
async function handleServiceWorker() {
// myTextWIdget my_text_widget.dart
import 'package:flutter/material.dart';
class MyTextWidget extends StatelessWidget {
MyTextWidget({
this.title,
this.fontWeight,
this.fontSize,
this.color,
});
import 'dart:convert';
import 'package:http/http.dart' as http;
abstract class PhotosRepository {
Future<List<Photo>> getPhotosList();
}
class Photo {
Photo({

RepaintBoundary artificially pretends that the child needs its own composited layer which means the effects in sub-tree are then contained. This is a great tip to improve performance in Flutter boosting to 60 FPS.

check in action: https://codepen.io/mhadaily/pen/ZEWWEKp

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
@mhadaily
mhadaily / Get Function name in Dart + Example.md
Created August 14, 2020 07:49
Get Function or Library Name in Dart Language!

reflect Returns an [InstanceMirror] reflecting reflectee. If reflecteeis a function or an instance of a class that has acallmethod, the returned instance mirror will be aClosureMirror`.Note that since one cannot obtain an object from another isolate, this function can only be used to obtain mirrors on objects of the current isolate.

A MirrorSystem is the main interface used to reflect on a set of associated libraries. At runtime each running isolate has a distinct MirrorSystem. It is also possible to have a MirrorSystem which represents a set of libraries which are not running -- perhaps at compile-time. In this case, all available reflective functionality would be supported, but runtime functionality (such as invoking a function or inspecting the contents of a variable) would fail dynamically.

simpleName getter is for Dart language entity. The simple name is in most cases the identifier name of the entity, such as 'myMethod' for a method, void myMethod() {...} or 'mylibrary' for a

@mhadaily
mhadaily / stack-in-dart.md
Last active August 11, 2020 05:58
What is Stack and implementing Stack in Dart

A stack implements LIFO (last-in first-out) ordering.

It uses the operations:

  • push(item): push an item to the top of the stack
  • pop(): Remove the top item in the stack
  • peek(): Return the top of the stack
  • isEmpty(): Return true if and on if the stack is empty

There are several places that we can use Stack but it may appear in recursive operations the most. For example, when part of the recursive function fails and you want to roll back everything, Stack sounds like a good plan for that.

@mhadaily
mhadaily / queue-in-dart.md
Last active August 10, 2020 07:02
What is Queue and Implementing Queue in Dart

A queue implements FIFO (first-in first-out) ordering.

It uses the operations:

  • add(item): Add an item to the end of the list
  • remove(): Remove the first item in the list
  • peek(): Return the top of the queue
  • isEmpty(): Return true if and on if the queue is empty

There are several places that we can use Queue but it may appear in Cache or Breadth-first search the most.