Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

flutter create custom appbar

// ./components/appBar.dart
import 'package:flutter/material.dart';

class CustomAppBar extends StatelessWidget with PreferredSizeWidget {
  final String _title;

  @override
  final Size preferredSize;

  CustomAppBar(this._title, { Key key}) : preferredSize = Size.fromHeight(50.0),
        super(key: key);

  @override
  Widget build(BuildContext context) {
    return AppBar( // your customization here
      title: Text('$_title'),
      centerTitle: true,
      backgroundColor: Colors.black54,
    );
  }
}

// on the file using the appBar just: 

import 'package:flutter/material.dart';
import 'package:photo_app/components/appBar.dart';

class Albums extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppBar('Your title here'),
    );
  }
}
Comment

Custom AppBar Flutter

Scaffold(
  appBar: PreferredSize(
    preferredSize: Size.fromHeight(120), // Set this height
    child: Container(
      color: Colors.orange,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text('One'),
          Text('Two'),
          Text('Three'),
          Text('Four'),
        ],
      ),
    ),
  ),
)
Comment

flutter component: custom appbar

import 'package:flutter/material.dart';

class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
  final String? title;
  final Color? titleColor;
  final Color? backgroundColor;
  final Icon? leftIcon;
  final bool? isShowLeftIcon;
  final bool? isShowActionIcon1;
  final bool? isShowActionIcon2;
  final bool? isShowActionIcon3;
  final Icon? actionIcon1;
  final Icon? actionIcon2;
  final Icon? actionIcon3;
  final VoidCallback? pressedLeftIcon;
  final VoidCallback? pressedActionIcon1;
  final VoidCallback? pressedActionIcon2;
  final VoidCallback? pressedActionIcon3;

  const CustomAppBar({
    Key? key,
    this.title = "",
    this.titleColor,
    this.backgroundColor,
    this.leftIcon,
    this.isShowLeftIcon = false,
    this.isShowActionIcon1 = false,
    this.isShowActionIcon2 = false,
    this.isShowActionIcon3 = false,
    this.actionIcon1 = const Icon(Icons.search),
    this.actionIcon2 = const Icon(Icons.alarm),
    this.actionIcon3 = const Icon(Icons.airline_seat_flat),
    this.pressedLeftIcon,
    this.pressedActionIcon1,
    this.pressedActionIcon2,
    this.pressedActionIcon3,
  }) : super(key: key);

  @override
  Size get preferredSize => const Size.fromHeight(kToolbarHeight);

  @override
  Widget build(BuildContext context) {
    return AppBar(
      // centerTitle: true,
      title: Text(
        title!,
        style: TextStyle(
          color: titleColor,
        ),
      ),
      backgroundColor: backgroundColor,
      elevation: 0,
      leading: isShowLeftIcon!
          ? IconButton(
              icon: leftIcon!,
              onPressed: pressedLeftIcon,
            )
          : const Offstage(),
      actions: [
        Visibility(
          visible: isShowActionIcon1!,
          child: IconButton(
            icon: actionIcon1!,
            onPressed: pressedActionIcon1,
          ),
        ),
        Visibility(
          visible: isShowActionIcon2!,
          child: IconButton(
            icon: actionIcon2!,
            onPressed: pressedActionIcon2,
          ),
        ),
        Visibility(
          visible: isShowActionIcon3!,
          child: IconButton(
            icon: actionIcon3!,
            onPressed: pressedActionIcon3,
          ),
        )
      ],
    );
  }
}


// Widget : use this class in :::  appBar: ...

class CAB extends StatelessWidget implements PreferredSizeWidget {
  const CAB({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const CustomAppBar(
      title: "Flutter Demo",
      isShowLeftIcon: true,
      leftIcon: Icon(
        Icons.chevron_left_outlined,
        color: Colors.white,
      ),
      isShowActionIcon1: true,
      actionIcon1: Icon(
        Icons.category,
        color: Colors.white,
      ),
      isShowActionIcon2: true,
      actionIcon2: Icon(Icons.air_rounded, color: Colors.white,),
      isShowActionIcon3: true,
      actionIcon3: Icon(Icons.search, color: Colors.white,),
    );
  }
  
  @override
  Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}
Comment

flutter custom appbar

class Sample1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        drawer: Drawer(),
        appBar: MyCustomAppBar(
          height: 150,
        ),
        body: Center(
          child: FlutterLogo(
            size: MediaQuery.of(context).size.width / 2,
          ),
        ),
      ),
    );
  }
}

class MyCustomAppBar extends StatelessWidget implements PreferredSizeWidget {
  final double height;

  const MyCustomAppBar({
    Key key,
    @required this.height,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
          color: Colors.grey[300],
          child: Padding(
            padding: EdgeInsets.all(30),
            child: AppBar(
                    title: Container(
                      color: Colors.white,
                      child: TextField(
                        decoration: InputDecoration(
                          hintText: "Search",
                          contentPadding: EdgeInsets.all(10),
                        ),
                      ),
                    ),
                    actions: [
                      IconButton(
                        icon: Icon(Icons.verified_user),
                        onPressed: () => null,
                      ),
                    ],
                  ) ,
          ),
        ),
      ],
    );
  }
  
 @override
  Size get preferredSize => Size.fromHeight(height);
}
Comment

PREVIOUS NEXT
Code Example
Ruby :: how to match email in regex in ruby 
Ruby :: kill rails 
Ruby :: how to I change the name of a column in rails 
Ruby :: rails undo scaffold 
Ruby :: ruby sort an object 
Ruby :: ruby remove duplicates from array 
Ruby :: check current route rails 
Ruby :: devise add trackable 
Ruby :: getting wanked off by ruby 
Ruby :: ruby get line from a file 
Ruby :: ruby get file extension 
Ruby :: ruby/rails file get line number 
Ruby :: rails logger color 
Ruby :: ruby each char with index 
Ruby :: rails naming conventions controller 
Ruby :: httparty SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate) (OpenSSL::SSL::SSLError) 
Ruby :: rails array sort 
Ruby :: ruby not include 
Ruby :: times ruby 
Ruby :: ruby latest version 
Ruby :: ruby array randomly display 
Ruby :: ruby open file and append 
Ruby :: remove order by from query in rails 
Ruby :: ruby string to boolean 
Ruby :: how to display the has_many in the api serializer rails 
Ruby :: rails generate model with options 
Ruby :: important topic on ruby 
Ruby :: input type checkbox checked with condition rails 
Ruby :: ruby zip rows and columns 
Ruby :: rails migration error 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =