Flutter UI #39: Fun with Animated search bar in Flutter


Flutter UI #39: Fun with Animated search bar in Flutter

Tutorial and code of Animated search bar in Flutter. Copy and paste the below code as per your requirements.

anim_search_bar: ^2.0.2

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

void main() async {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Animated search bar',
      home: App(),
    );
  }
}

class App extends StatefulWidget {
  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  TextEditingController textController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Center(child: Text("Animated search bar"),),
      ),
      body: Padding(
        padding: const EdgeInsets.only(top: 58.0, right: 10, left: 10),
        child: AnimSearchBar(
          width: 400,
          textController: textController,
          onSuffixTap: () {
            setState(() {
              textController.clear();
            });
          },
        ),
      ),
    );
  }
}

Leave a Reply

Your email address will not be published.