Flutter UI #56: Fun with Gradient AppBar in Flutter


Flutter UI #56: Fun with Gradient AppBar in Flutter

Tutorial and code of Gradient AppBar in Flutter. Copy and paste the below code as per your requirements.

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

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Gradient AppBar'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: NewGradientAppBar(
          title: Center(child:Text(widget.title)),
          gradient: const LinearGradient(colors: [Colors.red, Colors.purple]),
          bottom: const TabBar(tabs: <Widget>[
             Tab(
              icon: Icon(Icons.home),
              text: 'Home',
            ),
             Tab(
              icon: Icon(Icons.store),
              text: 'Store',
            )
          ]),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: const[
                Text(
                'Hey There',
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Leave a Reply

Your email address will not be published.