DEV Community

Cover image for Flutter & Dart Tips - Week In Review #4
Offline Programmer
Offline Programmer

Posted on

Flutter & Dart Tips - Week In Review #4

Hello Reader,

This is the 4th post in the "Week In Review" series, where I share the Flutter\Dart tips I tweeted last week.

1- You can use the Timer class to execute a piece of code after some time


    Timer.periodic(
        Duration(seconds: 1),
        (Timer time) {
                print("time: ${time.tick}");
                if (time.tick == 10) {
                    time.cancel();
                    print('Timer Cancelled');
                }
        },
    );

Enter fullscreen mode Exit fullscreen mode

2- Use the ClipOval widget to clip the child widget in oval or circle shape. If width and height are equal, the shape will be circular. If the width and height are different, then the shape will be oval.


    ClipOval(
        child: Image.network(
            imgUrl,
            fit: BoxFit.fill,
            width: 200.0,
            height: 200.0,
        ),
    );

Enter fullscreen mode Exit fullscreen mode

3- Use padLeft and padRight to add character padding on the left and right side, respectively.


  String s = "fun";
  print(s.padLeft(10, ',.*')); // ',.*,.*,.*,.*fun'
  print(s.padRight(10, ',.*')); // 'fun,.*,.*,.*,.*'

Enter fullscreen mode Exit fullscreen mode

4- Use the List class method join() can to join a List of any type to a String.


    List<String> values = ['dart', 'flutter', 'fun'];
    print(values.join()); //  dart,flutter,fun

Enter fullscreen mode Exit fullscreen mode

5- Set debugShowCheckedModeBanner to false to remove the Debug Banner Tag


    MaterialApp(
        debugShowCheckedModeBanner: false,
        // other arguments
    )

Enter fullscreen mode Exit fullscreen mode

6- To get access to the index on an Item in a list, you need to convert the list to a map using the asMap


    myList.asMap().entries.map((entry) {
        int idx = entry.key; // index
        String val = entry.value;
        return something;
    }

Enter fullscreen mode Exit fullscreen mode

See you next week. 👋🏻

Follow me on Twitter for more tips about #coding, #learning, #technology...etc.

Check my Apps on Google Play

Cover image Justin Lim on Unsplash

Latest comments (0)