Step By Step Implementations
Step 1: Create a New Project in Android Studio
To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter.
Step 2: Import the Package
First of all import material.dart file.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
Step 3: Execute the main Method
Here the execution of our app starts.
Dart
void main() { runApp(MyApp()); } |
Step 4: Create MyApp Class
In this class we are going to implement the MaterialApp , here we are also set the Theme of our App.
Dart
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return CupertinoApp( debugShowCheckedModeBanner: false , title: 'CupertinoNavigationBar Example' , home: CupertinoNavigationBarExample(), ); } } |
Step 5: Create CupertinoNavigationBarExample Class
In this class we are going to Implement the CupertinoNavigationBar widget that help to display a IOS styled navigation window. Comments are added for better understanding.
Dart
class CupertinoNavigationBarExample extends StatelessWidget { @override Widget build(BuildContext context) { return CupertinoPageScaffold( navigationBar: CupertinoNavigationBar( middle: Text( 'Cupertino Navigation Bar' ), // Title in the middle leading: CupertinoButton( child: Text( 'Back' , style: TextStyle(fontSize: 13), ), onPressed: () { // Add your back button action here Navigator.of(context).pop(); }, ), trailing: CupertinoButton( child: Text( 'Save' , style: TextStyle(fontSize: 13), ), onPressed: () { // Add your save button action here }, ), ), child: Center( child: Text( 'Your content goes here.' ), ), ); } } |
Here is the full Code of main.dart file
Dart
import 'package:flutter/cupertino.dart' ; import 'package:flutter/material.dart' ; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return CupertinoApp( debugShowCheckedModeBanner: false , title: 'CupertinoNavigationBar Example' , home: CupertinoNavigationBarExample(), ); } } class CupertinoNavigationBarExample extends StatelessWidget { @override Widget build(BuildContext context) { return CupertinoPageScaffold( navigationBar: CupertinoNavigationBar( middle: Text( 'Cupertino Navigation Bar' ), // Title in the middle leading: CupertinoButton( child: Text( 'Back' , style: TextStyle(fontSize: 13), ), onPressed: () { // Add your back button action here Navigator.of(context).pop(); }, ), trailing: CupertinoButton( child: Text( 'Save' , style: TextStyle(fontSize: 13), ), onPressed: () { // Add your save button action here }, ), ), child: Center( child: Text( 'Your content goes here.' ), ), ); } } |
Output:
Flutter – CupertinoNavigationBar Widget
The CupertinoNavigationBar widget in Flutter is a part of the Cupertino package, which is designed to provide an iOS-style look and feel to your Flutter app. This widget represents the navigation bar that is typically found at the top of an iOS app’s screen. In this article, we are going to implement the CupertinoNavigationBar widget and explore some properties of it.