The original

Medium.flutterdevs.com/convex-bott…

code

Github.com/flutter-dev…

reference

  • Pub. Dev/packages/co…

The body of the

The Convex Bottom bar is an application Sketch diagram, and its shape is convex Bottom. It can make the user interface look great and improve the way the user interacts with the interface. In this article, we will set up a simple application with one of the simplest forms, in the folders Bottom bar

Directory:

The introduction

Add dependencies

How to use

function

attribute

The implementation of

conclusion

Making a link

Brief introduction:

Hello everyone, today we are going to discuss a very important topic about Flutter UI. This topic is the underlying navigation bar. In this article, we learned about the Convex Bottom Bar. The Convex Bottom Bar is a kind of Flutter packaging. The Convex Bottom bar is an application bar sketch in such a way that there is a Convex Bottom shaped it. It can make the user interface look great and improve the way the user interacts with the interface. In this article, we will build a simple application with one of the simplest forms of the Convex Bottom Bar.

View the list TabItems widget, where you can explain the ICONS displayed in the AppBar and their titles. The list should contain only odd TabItems to run the widget without causing errors. If you want to display images or ICONS, you can provide images for the icon variable in each TabItem widget. If you want to generate an icon at the bottom of the Appbar, you can use the convexButton. fab widget. It generates fewer parameters and has a quick and nice single icon appBar.

Add dependencies:

Go to PubSpec in your project. Add dependencies: Add pub.dev/packages/co… The latest version of the.

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.02.
  convex_bottom_bar: ^3.0. 0
Copy the code

We use convax_bottom_bar to create a better BOOtobar UI.

How to use:

Normally, a ConvexAppBar can work with the scaffold by setting its bottomNavigationBar. ConvexAppBar has two constructors, and convexAppBar () will use levant style to simplify TAB creation. Add it to the package’s pubspec.yaml file, using the latest version.

Scaffold( body: bottomNavigationBar: ConvexAppBar(); ) ;Copy the code

Features:

  • Various interior styles are available
  • You can change the theme of the AppBar.
  • Provides a builder API for modifying new styles.
  • Add badges to the TAB menu.
  • Beautiful transition animation
  • Provides a hook API to override some of the internal styles.
  • RTL reinforcing

Properties:

Here are some properties of Convex_Bottom_Bar:

  • Fixed (subtitle icon stays in center)
  • FixedCircle (same, but with a white circle on all sides of the fixed icon)
  • React (Top label instead of clicking another icon)
  • ReactCircle (same as the white circle in the top label)
  • TextIn (the selected ion appears with the corresponding title)
  • Titled (the unselected icon is a single icon showing its title)
  • Flip (Click on the icon to display a Flip animation)
  • Custom (customize predefined parameters using the ConvexBottomAppBar builder)
  • height (grabbing the appbar)
  • top (grabbing the superscripted icon)
  • CurveSize (stretch the curve of the top label)
  • Color (Sets the color of the icon)
  • BackgroundColor (set appbar backgroundColor)
  • Gradient (Use the Gradient widget to set the appBar background color)
  • ActiveColor (Set the circle color)

Implementation plan:

In the Convex_Bottom_Bar demonstration, first we create a stateful class in this class called MyHomePage (), and we create an integer pass of type SelectedPage for a variable with a value of 0. Define a list called pageNo in which we pass all the pages to add to the BooTom navigation bar.

int selectedpage =0;
final _pageNo = [Home() , Favorite() , CartPage() , ProfilePage()];
Copy the code

In BuildContext (), we define the Scaffold.

appBar: AppBar(
  centerTitle: true,
  title: Text('Convex Bottom Bar'),),Copy the code

Start by passing _pageno in the body with a value of selectedPage. With the scaffold property, we use the bottomNavigationBar. Here we create ConvexAppBar () and pass Items, initialActiveIndex, and onTap. In the entry, we go through all the screens that we want to display in our application. In initialActiveIndexwe, we pass the defined variable SelectedPage, in onTap, we pass index and define setState () in setState, We pass selectedPage as index.

bottomNavigationBar: ConvexAppBar(
  items: [
    TabItem(icon: Icons._home_, title: 'Home'),
    TabItem(icon: Icons._favorite_, title: 'Favorite'),
    TabItem(icon: Icons._shopping_cart_, title: 'Cart'),
    TabItem(icon: Icons._person_, title: 'Profile'),
  ],
  initialActiveIndex: selectedpage,
  onTap: (intindex){ setState(() { selectedpage = index; }); },),Copy the code

If we create different pages, Home(), Favorite(), CartPage(), ProfilePage(). In the Home class, we define a text with a background color.

Home Home screen:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class Home extends StatefulWidget {
  const Home({Key? key}) : super(key: key);

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Text('Home Page',
          style: TextStyle(
              fontSize: 20, fontWeight: FontWeight.bold ),), ), ); }}Copy the code

Favorite 最喜欢的屏幕:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class Favorite extends StatefulWidget {
  const Favorite({Key? key}) : super(key: key);

  @override
  _FavoriteState createState() => _FavoriteState();
}

class _FavoriteState extends State<Favorite> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors._greenAccent_,
     body: Center(
          child: Text('Favorite Page',
          style: TextStyle(
            fontSize: 20, fontWeight: FontWeight._bold_ ), )), ); }}Copy the code

CartPage screen:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class CartPage extends StatefulWidget {
  const CartPage({Key? key}) : super(key: key);

  @override
  _CartPageState createState() => _CartPageState();
}

class _CartPageState extends State<CartPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors._pink_.shade100,
      body: Center(
          child: Text('Cart Page',
            style: TextStyle(
                fontSize: 20, fontWeight: FontWeight._bold_ ),)), ); }}Copy the code

_ProfilePage profile page:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class ProfilePage extends StatefulWidget {
  const ProfilePage({Key? key}) : super(key: key);

  @override
  _ProfilePageState createState() => _ProfilePageState();
}

class _ProfilePageState extends State<ProfilePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors._yellow_,
      body: Center(
          child: Text('Profile Page',
            style: TextStyle(
                fontSize: 20, fontWeight: FontWeight._bold_ ),)), ); }}Copy the code

When we run the application, we should get screen output like the screen video below.

Conclusion:

This article describes what a Convex Bottom Bar is and how to implement it in the Flutter method. You can use this package according to your needs.

If I’m doing something wrong, let me know in the comments and I’m happy to improve.

Clap your hands if this article helps you.

GitHub Link:

Github.com/flutter-dev…


The elder brother of the © cat

  • WeChat ducafecat

  • Blog ducafecat. Tech

  • github

  • bilibili