appbar flutterr code example

Example 1: flutter appbar widget

Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('AppBar Title', textAlign: TextAlign.center),
      ),

Example 2: flutter create custom appbar

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

class CustomAppBar extends StatelessWidget with PreferredSizeWidget {
  final String _title;

  
  final Size preferredSize;

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

  
  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 {
  
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppBar('Your title here'),
    );
  }
}

Tags:

Dart Example