Material and Cupertino components of Flutter in “Dart in simple terms”

Click to read online for a better experience link
Modern JavaScript Advanced Booklet link
Dart in simple terms link
Modern TypeScript Advanced Booklet Link

Material and Cupertino components

In this article, we will use the official latest Dart syntax and new knowledge to introduce Material Design and Cupertino style components in Flutter in detail. Flutter provides two theme styles, Material Design and Cupertino, for creating beautiful and consistent user interfaces. We’ll dive into both styles of components and provide links to official documentation so you can learn further.

Flutter Material Design Components

Material Design is a modern, beautiful design style proposed by Google for creating consistent user interfaces. Flutter provides many Material Design-style components for building beautiful, responsive apps.

Here are some commonly used Flutter Material Design components:

1. AppBar component

AppBar is a Material Design-style application bar, usually located at the top of the page, used to display titles, operation buttons, etc.

Here is a simple AppBar example:

AppBar(
  title: Text('My App'),
  actions: [
    IconButton(
      icon: Icon(Icons. settings),
      onPressed: () {
        // open the settings page
      },
    ),
  ],
)

Learn more: AppBar component documentation

2. FloatingActionButton component

FloatingActionButton is a floating circular button, often used to trigger the main action in the application.

Here is a simple FloatingActionButton example:

FloatingActionButton(
  onPressed: () {<!-- -->// Perform operation
  },
  child: Icon(Icons.add),
)

Learn more: FloatingActionButton component documentation

3. Card component

Card is a card-like container with a shadow effect, often used to display related content, such as pictures, titles and descriptions.

Here is a simple Card example:

Card(
  child: Column(
    children: [
      Image.network('https://example.com/image.jpg'),
      ListTile(
        title: Text('Title'),
        subtitle: Text('Description'),
      ),
    ],
  ),
)

Learn more: [Card component documentation](api.flutter.dev

/flutter/material/Card-class.html)

The above are just some examples of commonly used Material Design components. Flutter provides more rich components and functions. You can choose appropriate components according to your needs to build a beautiful user interface.

Flutter Cupertino style components

Cupertino is an iOS-style design language. Flutter provides a series of Cupertino-style components that allow applications to have native appearance and behavior on iOS devices.

The following are some commonly used Flutter Cupertino style components:

1. CupertinoNavigationBar component

CupertinoNavigationBar is a Cupertino-style navigation bar, usually located at the top of the page, used to display titles, operation buttons, etc.

Here is a simple CupertinoNavigationBar example:

CupertinoNavigationBar(
  middle: Text('My App'),
  trailing: CupertinoButton(
    child: Icon(CupertinoIcons.settings),
    onPressed: () {
      // open the settings page
    },
  ),
)

Learn more: CupertinoNavigationBar component documentation

2. CupertinoButton component

CupertinoButton is a Cupertino-style button with iOS-style appearance and touch feedback.

Here is a simple CupertinoButton example:

CupertinoButton(
  onPressed: () {<!-- -->// Perform operation
  },
  child: Text('Click Me'),
)

Learn more: CupertinoButton component documentation

3. CupertinoAlertDialog component

CupertinoAlertDialog is a Cupertino-style dialog box used to display alerts, confirmations, or other relevant information.

Here is a simple CupertinoAlertDialog example:

showDialog(
  context: context,
  builder: (BuildContext context) {<!-- -->return CupertinoAlertDialog(
      title: Text('Alert'),
      content: Text('This is an alert dialog.'),
      actions: [
        CupertinoDialogAction(
          child: Text('OK'),
          onPressed: () {
            // handle button click event
            Navigator.of(context).pop();
          },
        ),
      ],
    );
  },
)

Learn more: CupertinoAlertDialog component documentation

These are just some examples of commonly used Cupertino-style components. Flutter provides more rich components and functions, and you can choose appropriate components according to your needs to build an iOS-style user interface.

References

To learn more about Material Design and Cupertino style components in Flutter, you can refer to the following official resources and documents:

  • Flutter Official Documentation
  • Material Design Component Documentation
  • Cupertino Style Components Documentation
  • Flutter Cookbook