Flutter OutlinedButton Tutorial (2022)

Flutter OutlinedButton Tutorial

An OutlinedButton is a button with text child and a border outline. It is also a form of TextButton with an outline. They are used in the places where the button needs medium importance. Unlike the other two button types (TextButton and ElevatedButton), these buttons have the outline style set by default.

OutlinedButton Usage

There are two constructors available for the OutlinedButton, one with option to specify icon and one without icon. First, let’s try the simple outlined button that does not have any icon.

There are two mandatory fields in the constructor, onPressed and child.

const OutlinedButton({
    Key? key,
    required VoidCallback? onPressed,
    VoidCallback? onLongPress,
    ValueChanged<bool>? onHover,
    ValueChanged<bool>? onFocusChange,
    ButtonStyle? style,
    FocusNode? focusNode,
    bool autofocus = false,
    Clip clipBehavior = Clip.none,
    required Widget child,
});

Now, let’s see how we can make use of the OutlinedButton in a sample application. In the following example, when the button is pressed, a snackbar message will be shown.

import 'package:flutter/material.dart';

void main() {
  runApp(const OutlinedButtonExample());
}

class OutlinedButtonExample extends StatelessWidget {
  const OutlinedButtonExample({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(title: const Text('OutlinedButton Example')),
          body: const OutlinedButtonWidget()),
    );
  }
}

class OutlinedButtonWidget extends StatelessWidget {
  const OutlinedButtonWidget({Key? key}) : super(key: key);

  //Button click handler: Show snackbar
  handleButtonClick(BuildContext context) {
    const snackBar = SnackBar(
      content: Text("Outlined Button Clicked!"),
    );
    ScaffoldMessenger.of(context).showSnackBar(snackBar);
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      //Create Text Button
      child: OutlinedButton(
          //Handle button press event
          onPressed: () {
            handleButtonClick(context);
          },
          //Contents of the button
          child: const Text("Click Outlined Button!")),
    );
  }
}

This code generates the following output.
Flutter OutlinedButton Example

Customize style and add an Icon

Now, let’s see how we can customize the OutlinedButton with the styling options available and add an icon into the button.

There’s a factory constructor available for making the button with an Icon. As you can see from the constructor signature below, 3 fields are mandatory. onPressed, icon and the label.

factory OutlinedButton.icon({
  Key? key,
  required VoidCallback? onPressed,
  VoidCallback? onLongPress,
  ButtonStyle? style,
  FocusNode? focusNode,
  bool? autofocus,
  Clip? clipBehavior,
  required Widget icon,
  required Widget label,
})

For the button style customization, we will do the following.

  • Set font size to 20dp
  • Set font size to 20dp
  • Add 20px padding on all sides
  • Set the border color GREEN
  • Set the border width to 2px
  • Set the text color GREEN
OutlinedButton With Icon
OutlinedButton With Icon and customized style

Now, let’s see we can do it with an example code.

class OutlinedButtonWidget extends StatelessWidget {
  const OutlinedButtonWidget({Key? key}) : super(key: key);

  handleButtonClick(BuildContext context) {
    ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("Outlined Button Clicked!")));
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      //Create Elevated Button
      child: OutlinedButton.icon(
          //Handle button press event
          onPressed: () {
            handleButtonClick(context);
          },
          //Contents of the button
          style: ElevatedButton.styleFrom(
            //Style the text
            textStyle: const TextStyle(
              fontSize: 20, //Set font size
            ),
            //Style the border
            side: const BorderSide(
              color: Colors.green, //Set border color
              width: 2, //Set border width
            ),
            onPrimary: Colors.green, //Set the foreground (text + icon) color
            padding: const EdgeInsets.all(20.0), //Set the padding on all sides to 20px
          ),
          icon: const Icon(Icons.download), //Button icon
          label: const Text("Click OutlinedButton!")), //Button label
    );
  }
}

Customizing flutter buttons further

You can customize even more to the minute details of the buttons, thanks to the flutter SDK. We have discussed this in detail in the ElevatedButton article. If you are interested, please refer the article.

Conclusion

In this tutorial, we have learned how to make use of the Flutter OutlinedButton widget in flutter. This button is useful for non-primary actions in the GUI because it doesn’t attract too much attention for the user. We have seen how to customize it with icons and custom style. If you liked this article, you might be interested in the other Flutter tutorials I have written.

Comments

56 responses to “Flutter OutlinedButton Tutorial (2022)”

  1. cialis buy philippines

    cialis buy philippines

  2. … [Trackback]

    […] Find More Info here to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  3. … [Trackback]

    […] There you will find 16316 additional Information to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  4. … [Trackback]

    […] Read More on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  5. … [Trackback]

    […] Find More here on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  6. … [Trackback]

    […] Read More to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  7. … [Trackback]

    […] Info to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  8. … [Trackback]

    […] There you can find 38375 more Info to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  9. … [Trackback]

    […] Find More to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  10. … [Trackback]

    […] Read More on to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  11. … [Trackback]

    […] Read More to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  12. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  13. … [Trackback]

    […] Find More on on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  14. … [Trackback]

    […] Find More here to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  15. … [Trackback]

    […] Read More Info here to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  16. … [Trackback]

    […] Read More on to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  17. … [Trackback]

    […] Find More here to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  18. … [Trackback]

    […] Find More Information here on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  19. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  20. … [Trackback]

    […] Here you will find 36318 more Information to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  21. … [Trackback]

    […] There you will find 48282 additional Info to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  22. … [Trackback]

    […] Here you can find 23657 more Info on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  23. … [Trackback]

    […] Find More here to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  24. … [Trackback]

    […] Find More here on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  25. … [Trackback]

    […] Read More on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  26. … [Trackback]

    […] Read More here to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  27. … [Trackback]

    […] Info to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  28. … [Trackback]

    […] Information to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  29. … [Trackback]

    […] Read More Info here on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  30. … [Trackback]

    […] Information on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  31. … [Trackback]

    […] Info to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  32. … [Trackback]

    […] Read More on to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  33. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  34. … [Trackback]

    […] Here you can find 84507 more Information on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  35. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  36. … [Trackback]

    […] Info on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  37. … [Trackback]

    […] Read More here to that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  38. … [Trackback]

    […] Information on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  39. … [Trackback]

    […] Find More here on that Topic: genuinecoder.com/flutter-outlinedbutton-tutorial/ […]

  40. how to order androxal cheap prices

    get androxal generic compare

  41. buy cheap enclomiphene price at walmart

    purchase enclomiphene no rx

  42. get rifaximin uk generic

    online order rifaximin generic pharmacy canada

  43. get xifaxan generic sale

    purchase xifaxan generic sale

  44. discount staxyn cheap trusted

    cheap staxyn price by pharmacy

  45. discount avodart cheap canada

    purchase avodart cheap uk

  46. how to buy dutasteride how to purchase viagra

    how to buy dutasteride cheap in canada

  47. cheap flexeril cyclobenzaprine canada price

    cheap meds flexeril cyclobenzaprine

  48. cheapest buy gabapentin buy uk no prescription

    online order gabapentin canada discount

  49. online order fildena generic fildenas

    how to order fildena cost usa

  50. discount itraconazole cheap melbourne

    purchase itraconazole cost tablet

  51. levnテゥ kamagra bez lテゥkaナ冱kテゥho pナ册dpisu dalナ。テュ den doruト稿nテュ

    noト肱テュ dodテ。nテュ kamagra bez lテゥkaナ冱kテゥho pナ册dpisu

  52. kamagra prescription en ligne

    générique kamagra à dubaï

  53. atorvastatin calcium 80 mg

    atorvastatin calcium 80 mg

  54. doxycycline hyclate 100 mg tab

    doxycycline hyclate 100 mg tab

  55. fluconazole 200 mg tablet

    fluconazole 200 mg tablet

  56. metoprolol tartrate 25 mg price

    metoprolol tartrate 25 mg price

Leave a Reply