Code Monkey home page Code Monkey logo

flutter-tips-and-tricks's Introduction

Table of Contents

Usage

Click on any of the tips/tricks above to get to their source-code/infographic and demo videos (if applicable)

License

Copyright 2022 @ Vandad Nahavandipoor

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

flutter-tips-and-tricks's People

Contributors

vandadnp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flutter-tips-and-tricks's Issues

Tip 196: Error Handling Value Passing

About https://github.com/vandadnp/flutter-tips-and-tricks/tree/main#future-error-handling-in-dart

Maybe a note would be helpful, to use that with caution. The creation of the error-value could be expensive and with your approach, I would create that object all the time, even if I don't need it. That is the reason, as far as I know, to pass a creation function into it. Just my thought to avoid bad designs for newcomers to dart.

Thanks for all your tips, I like it a lot.

Add the update to the release description

Hey! Thanks for a very cool repo โœŒ๏ธ

Would be nice if the release message contained the tip itself or at least a link to the new section. So if I see the release in the feed, I could just read it by entering the release page.

Can't access the tips and tricks anymore using the normal url

Hello Vandad, that's for creating such a useful project. I've been playing around with loading the tips and trick in the terminal for a while now using this method Flutter Tips and Tricks in Terminal but just now the link doesn't show all the images and dart code just the .md files. Is there a new method to get each tip with its image and source code now? I'm creating an open source app using this repo and would really like it to work out.

I also can't get the dart files now, https://raw.githubusercontent.com/vandadnp/flutter-tips-and-tricks/main/tipsandtricks/implementing-zip-and-tuples-in-dart/implementing-zip-and-tuples-in-dart.dart This like gives me a 404 error. But I can access the .jpg freely.

extension OrDefault<T> on T does not work

As suggested at https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/default-value-for-optionals-in-dart/default-value-for-optionals-in-dart.md

I declared:

extension OrDefault<T> on T {
  T get orDefault {
    final value = this;
    if (value == null) {
      return {
        int: 0,
        String: '',
        double: 0.0,
        num: 0,
        bool: false,
        Map: {},
        List: [],
        Set: {},
      }[T] as T;
    } else {
      return value;
    }
  }
}

  test('Test ObjectExtension.orDefault()', () async {
    const int? nullInt = null;
    expect(nullInt.orDefault, 0); // fails since T is int? and returns null instead of 0.
  });

Integer range optimization

Hi. The extension method to could be made more optimized or idiomatic (since its return type is declared as Iterable) by avoiding unnecessary array creation. The code won't be as pretty though ๐Ÿ˜ƒ

extension To on int {
Iterable<int> to(int other, [bool inclusive = true]) => other > this
? [for (int i = this; i < other; i++) i, if (inclusive) other]
: [for (int i = this; i > other; i--) i, if (inclusive) other];
}

vs

extension To on int {
  Iterable<int> to(int other, [bool inclusive = true]) sync* {
    if (other > this) {
      for (int i = this; i < other; i++) yield i;
    } else {
      for (int i = this; i > other; i--) yield i;
    }

    if (inclusive) yield other;
  }
}

Null-Aware Infix Operators in Dart - likely unneeded code on line "return shadow + (other ?? 0) as T"

RE: https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/null-aware-infix-operators-in-dart/null-aware-infix-operators-in-dart.md

Having:

T? operator +(final T? other) {
  final shadow = this;
  if (shadow != null) {
    return shadow + (other ?? 0) as T;
  } else {
    return null;
  }
}

and the test:

test('Test null + operator', () {
    int? var1;
    var1++;
    var1 += 1;
    var1 = var1 + 1;
    var1 = 2;
    var1++;
    var1 += 1;
    var1 = var1 + 1;
    expect(var1, 5);
}

The test runs successfully but with code coverage we can see that the line

return shadow + (other ?? 0) as T;

never gets called which leads me to the speculation that shadow always equals to NULL when the extension is called and the extension is not "attached" if T is not null.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.