App6 v1 : My Books - Learning New Widgets



  1. IconButton
  2. An icon button is a picture printed on a Material widget that reacts to touches by filling with color (ink).
    Icon buttons are commonly used in the AppBar.actions field, but they can be used in many other places as well.

    Some properties of IconButton Class:

    1. icon : Widget
    2. The icon to display inside the button.

    3. color : Color
    4. The color to use for the icon inside the button, if the icon is enabled. Defaults to leaving this up to the icon widget.

    5. iconSize : double
    6. The size of the icon inside the button.

    7. onPressed :
    8. The callback that is called when the button is tapped or otherwise activated.

    9. padding : EdgeInsetsGeometry
    10. The padding around the button's icon. The entire padded icon will react to input gestures.

    Example :


            appBarAppBar(

              titleconst Text("Test"),

              actions: [

                IconButton(

                  iconconst Icon(Icons.add_circle_rounded),

                  colorColors.white,

                  iconSize35,

                  onPressed: () {

                    //adding

                  },

                  paddingconst EdgeInsets.all(2),

                )

              ],

            ),



    IconButton example

  3. TextField
  4. A text field lets the user enter text, either with hardware keyboard or with an onscreen keyboard.

    The text field calls the onChanged callback whenever the user changes the text in the field. If the user indicates that they are done typing in the field (e.g., by pressing a button on the soft keyboard), the text field calls the onSubmitted callback.

    To control the text that is displayed in the text field, use the controller. For example, to set the initial value of the text field, use a controller that already contains some text. The controller can also control the selection and composing region (and to observe changes to the text, selection, and composing region).

    Remember to call TextEditingController.dispose of the TextEditingController when it is no longer needed. This will ensure we discard any resources used by the object.

    Some properties of TextField Class:

    1. controller : TextEditingController
    2. Controls the text being edited.

    3. decoration : InputDecoration
    4. The decoration to show around the text field.

    5. expands : bool
    6. Whether this widget's height will be sized to fill its parent.

    7. keyboardType : TextInputType
    8. The type of keyboard to use for editing the text.

    9. obscureText : bool
    10. Whether to hide the text being edited (e.g., for passwords).

    11. readOnly : bool
    12. Whether the text can be changed.

    Example :


    class _MyHomePageState extends State<MyHomePage> {

      late TextEditingController _textEditingController;

     

      @override

      void initState() {

        _textEditingController = TextEditingController();

        super.initState();

      }

     

      @override

      void dispose() {

        _textEditingController.dispose();

        super.dispose();

      }

     

      @override

      Widget build(BuildContext context) {

        return Scaffold(

            appBarAppBar(

              titleconst Text("Test"),

            ),

            bodyContainer(

              padding:const EdgeInsets.all(20),

              alignmentAlignment.center,

              childTextField(

                controller_textEditingController,

                decorationconst InputDecoration(labelText"Age"),

                keyboardTypeTextInputType.number,

              ),

            ));

      }

    }

     



    TextField flutter

    TextField flutter

  5. CircleAvatar
  6. Typically used with a user's profile image, or, in the absence of such an image, the user's initials. A given user's initials should always be paired with the same background color, for consistency.

    Some properties of CircleAvatar Class:

    1. child : Widget
    2. The widget below this widget in the tree.

    3. backgroundImage : ImageProvider<Object>
    4. The background image of the circle. Changing the background image will cause the avatar to animate to the new image.

    5. backgroundColor : Color
    6. The color with which to fill the circle. Changing the background color will cause the avatar to animate to the new color.

    7. foregroundColor : Color
    8. The default text color for text in the circle.

    9. radius : double
    10. The size of the avatar, expressed as the radius (half the diameter).

    Example :


                Column(

                  mainAxisAlignmentMainAxisAlignment.spaceBetween,

                  childrenconst [

                    CircleAvatar(

                      backgroundImageNetworkImage(

                          "https://www.hotfootdesign.co.uk/wp-content/uploads/2016/05/d5jA8OZv.jpg"),

                      radius35,

                    ),

                    CircleAvatar(

                      childText("User"),

                      backgroundColorColors.blue,

                      foregroundColorColors.white,

                      radius35,

                    ),

                    CircleAvatar(

                      childIcon(Icons.print),

                      backgroundColorColors.red,

                      foregroundColorColors.amberAccent,

                      radius20,

                    )

                  ],

                )



    CircleAvatar Flutter

  7. ListTile
  8. A single fixed-height row that typically contains some text as well as a leading or trailing icon.
    A list tile contains one to three lines of text optionally flanked by icons or other widgets, such as check boxes. The icons (or other widgets) for the tile are defined with the leading and trailing parameters. The first line of text is not optional and is specified with title. The value of subtitle, which is optional, will occupy the space allocated for an additional line of text, or two lines if isThreeLine is true.

    Some properties of ListTile Class:

    1. leading : Widget
    2. A widget to display before the title.

    3. title : Widget
    4. The primary content of the list tile.

    5. subtitle : Widget
    6. Additional content displayed below the title.

    7. trailing : Widget
    8. A widget to display after the title.

    9. isThreeLine : bool
    10. Whether this list tile is intended to display three lines of text.

    Example :


                Column(children: [

                  ListTile(

                    leadingconst CircleAvatar(

                      childIcon(Icons.headphones),

                    ),

                    titleconst Text("Headphones"),

                    trailingIconButton(

                      iconconst Icon(Icons.music_note),

                      onPressed: () {},

                    ),

                  ),

                  ListTile(

                    leadingconst CircleAvatar(

                      childIcon(Icons.headphones_outlined),

                    ),

                    titleconst Text("Headphones"),

                    subtitleconst Text("Easy and comfortable to wear!"),

                    trailingIconButton(

                      iconconst Icon(Icons.my_library_music),

                      onPressed: () {},

                    ),

                  ),

                  ListTile(

                    leadingconst CircleAvatar(

                      childIcon(Icons.headset_mic),

                    ),

                    titleconst Text("Headphones"),

                    subtitleconst Text(

                        "They are easy and comfortable to wear, they don’t fall out of your ears!"),

                    isThreeLinetrue,

                    trailingIconButton(

                      iconconst Icon(Icons.queue_music),

                      onPressed: () {},

                    ),

                  ),

                ])



    ListTile flutter

  9. Card
  10. A material design card: a panel with slightly rounded corners and an elevation shadow.

    Some properties of Card Class:

    1. child : Widget
    2. The widget below this widget in the tree.

    3. elevation : double
    4. The z-coordinate at which to place this card. This controls the size of the shadow below the card.

    5. shadowColor : Color
    6. The color to paint the shadow below the card.

    7. shape : ShapeBorder
    8. The shape of the card's Material.

    9. margin : EdgeInsetsGeometry
    10. The empty space that surrounds the card.

    Example :


            Card(

              marginEdgeInsets.all(10),

              elevation10,

              shapeRoundedRectangleBorder(

                sideBorderSide(colorColors.greywidth1),

                borderRadiusBorderRadius.circular(10),

              ),

              shadowColorColors.black,

              childListTile(

                leadingconst CircleAvatar(

                  childIcon(Icons.headset_mic),

                ),

                titleconst Text("Headphones"),

                subtitleconst Text(

                    "They are easy and comfortable to wear, they don’t fall out of your ears!"),

                isThreeLinetrue,

                trailingIconButton(

                  iconconst Icon(Icons.queue_music),

                  onPressed: () {},

                ),

              ),

            )



    flutter Card

  11. Flexible
  12. A widget that controls how a child of a Row, Column, or Flex flexes.

    Using a Flexible widget gives a child of a Row, Column, or Flex the flexibility to expand to fill the available space in the main axis (e.g., horizontally for a Row or vertically for a Column), but, unlike Expanded, Flexible does not require the child to fill the available space.

    A Flexible widget must be a descendant of a Row, Column, or Flex, and the path from the Flexible widget to its enclosing Row, Column, or Flex must contain only StatelessWidgets or StatefulWidgets.

    Some properties of Flexible Class:

    1. child : Widget
    2. The widget below this widget in the tree.

    3. fit : FlexFit
    4. How a flexible child is inscribed into the available space.

    5. flex : int
    6. The flex factor to use for this child.

    Example :


            Column(

              children: [

                Flexible(

                  childContainer(

                    colorColors.red,

                  ),

                  flex2,

                ),

                Flexible(

                  childRow(

                    children: [

                      Flexible(

                        childContainer(

                          colorColors.pink,

                        ),

                        flex1,

                      ),

                      Flexible(

                        childContainer(

                          colorColors.blue,

                        ),

                        flex2,

                      ),

                      Flexible(

                        childContainer(

                          colorColors.purple,

                        ),

                        flex6,

                      )

                    ],

                  ),

                  flex4,

                ),

                Flexible(

                  childContainer(

                    colorColors.yellowAccent,

                  ),

                  flex1,

                ),

              ],

            )



    flutter Flexible
  13. ListView
  14. A scrollable list of widgets arranged linearly.

    ListView is the most commonly used scrolling widget. It displays its children one after another in the scroll direction. In the cross axis, the children are required to fill the ListView.

    There are four options for constructing a ListView:

    1. The default constructor takes an explicit List <Widget> of children. This constructor is appropriate for list views with a small number of children because constructing the List requires doing work for every child that could possibly be displayed in the list view instead of just those children that are actually visible.

    2. The ListView.builder constructor takes an IndexedWidgetBuilder, which builds the children on demand. This constructor is appropriate for list views with a large (or infinite) number of children because the builder is called only for those children that are actually visible.

    3. The ListView.separated constructor takes two IndexedWidgetBuilders: itemBuilder builds child items on demand, and separatorBuilder similarly builds separator children which appear in between the child items. This constructor is appropriate for list views with a fixed number of children.

    4. The ListView.custom constructor takes a SliverChildDelegate, which provides the ability to customize additional aspects of the child model. For example, a SliverChildDelegate can control the algorithm used to estimate the size of children that are not actually visible.

    Example 1:


    ListView(

              paddingconst EdgeInsets.all(8),

              children: <Widget>[

                Container(

                  height50,

                  marginconst EdgeInsets.symmetric(vertical30),

                  colorColors.pink,

                  childconst Center(childText('Entry A')),

                ),

                Container(

                  height50,

                  marginconst EdgeInsets.symmetric(vertical30),

                  colorColors.red,

                  childconst Center(childText('Entry B')),

                ),

                Container(

                  height50,

                  marginconst EdgeInsets.symmetric(vertical30),

                  colorColors.orange,

                  childconst Center(childText('Entry C')),

                ),

              ],

            )



    flutter ListView

    Example 2:


    class _MyHomePageState extends State<MyHomePage> {

      final List<Stringentries = <String>['A''B''C'];

      final List<Colorcolors = <Color>[Colors.pink,Colors.redColors.orange];

      @override

      Widget build(BuildContext context) {

        return Scaffold(

            appBarAppBar(

              titleconst Text("Test"),

            ),

            bodyListView.builder(

                paddingconst EdgeInsets.all(8),

                itemCountentries.length,

                itemBuilder: (BuildContext contextint index) {

                  return Container(

                    height50,

                    marginconst EdgeInsets.symmetric(vertical30),

                    colorcolors[index],

                    childCenter(childText('Entry ${entries[index]}')),

                  );

                }));

      }

    }


    flutter ListView

    Example 3:


    class _MyHomePageState extends State<MyHomePage> {

      final List<Stringentries = <String>['A''B''C'];

      final List<Colorcolors = <Color>[Colors.pinkColors.redColors.orange];

      @override

      Widget build(BuildContext context) {

        return Scaffold(

            appBarAppBar(

              titleconst Text("Test"),

            ),

            bodyListView.separated(

              paddingconst EdgeInsets.all(8),

              itemCountentries.length,

              itemBuilder: (BuildContext contextint index) {

                return Container(

                  height50,

                  colorcolors[index],

                  marginconst EdgeInsets.symmetric(vertical20),

                  childCenter(childText('Entry ${entries[index]}')),

                );

              },

              separatorBuilder: (BuildContext contextint index) =>

                  const Divider(),

            ));

      }

    }

     


    flutter ListView

  15. BottomNavigationBar
  16. A material widget that's displayed at the bottom of an app for selecting among a small number of views, typically between three and five.

    The bottom navigation bar consists of multiple items in the form of text labels, icons, or both, laid out on top of a piece of material. It provides quick navigation between the top-level views of an app. For larger screens, side navigation may be a better fit.

    A bottom navigation bar is usually used in conjunction with a Scaffold, where it is provided as the Scaffold.bottomNavigationBar argument.

    Some properties of BottomNavigationBar Class:

    1. items : List<BottomNavigationBarItem>
    2. Defines the appearance of the button items that are arrayed within the bottom navigation bar.

    3. currentIndex : int
    4. The index into items for the current active BottomNavigationBarItem.

    5. selectedItemColor : Color
    6. The color of the selected BottomNavigationBarItem.icon.

    7. onTap :
    8. Called when one of the items is tapped.

    9. selectedLabelStyle : TextStyle
    10. The TextStyle of the BottomNavigationBarItem labels when they are selected.

    Example :


    class _MyHomePageState extends State<MyHomePage> {

      final List<Stringtexts = <String>['Home''Phone''TV''Headphone'];

      final List<Colorcolors = <Color>[

        Colors.pink,

        Colors.red,

        Colors.orange,

        Colors.purple

      ];

      int _index = 0;

     

      @override

      Widget build(BuildContext context) {

        return Scaffold(

          appBarAppBar(

            titleconst Text("Test"),

          ),

          bodyCenter(

            childContainer(

              colorcolors[_index],

              childText(

                texts[_index],

                styleconst TextStyle(colorColors.whitefontSize35),

              ),

            ),

          ),

          bottomNavigationBarBottomNavigationBar(

            items: [

              BottomNavigationBarItem(

                  iconconst Icon(Icons.home),

                  labeltexts[0],

                  backgroundColorcolors[0]),

              BottomNavigationBarItem(

                  iconconst Icon(Icons.phone),

                  labeltexts[1],

                  backgroundColorcolors[1]),

              BottomNavigationBarItem(

                  iconconst Icon(Icons.tv),

                  labeltexts[2],

                  backgroundColorcolors[2]),

              BottomNavigationBarItem(

                  iconconst Icon(Icons.headphones),

                  labeltexts[3],

                  backgroundColorcolors[3]),

            ],

            currentIndex_index,

            selectedItemColorColors.yellow,

            onTap: (int idx) {

              setState(() {

                _index = idx;

              });

            },

          ),

        );

      }

    }



    BottomNavigationBar Card

    BottomNavigationBar Card

    BottomNavigationBar Card

    BottomNavigationBar Card