flutter_suggestion_searchbar 1.0.0 flutter_suggestion_searchbar: ^1.0.0 copied to clipboard
A Flutter Package for a SearchBar-Widget with suggestions. It is a full customizable SearchBar with a SuggestionsBar for mainly iOS and Android Apps.
import 'package:example/src/search_bar.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final firstController = TextEditingController();
final secondController = TextEditingController();
final firstSugList = [
"Dart",
"Flutter",
"Navigator",
];
final secondSugList = [
"Android",
"Apple",
"Windows",
"Linux",
];
@override
Widget build(BuildContext context) {
//Responsive Design Vars
const mockupWidth = 375;
//const mockupHeight = 812;
final width = MediaQuery.of(context).size.width;
final height = MediaQuery.of(context).size.height;
//final scale = mockupWidth / width;
final textScaleFactor = width / mockupWidth;
return Scaffold(
appBar: AppBar(
title: const Text("Suggestion Searchbar Example"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Spacer(),
SearchBar(
itemHeight: 60,
enableSuggestions: true,
textScaleFactor: textScaleFactor,
textFieldController: firstController,
cursorColor: Colors.white,
enabledBorderColor: Colors.blue,
focusedBorderColor: Colors.blue.withAlpha(100),
labelColor: Colors.white.withAlpha(180),
textColor: Colors.white,
prefixIconColor: Colors.white,
suffixIconColor: Colors.white.withAlpha(100),
suggestionsList: firstSugList,
gap: 12,
itemTextSize: 18,
itemBGColor: const Color(0xFF252525),
itemTextColor: Colors.white,
itemBorderRadius: 25,
itemPadding: const EdgeInsets.only(bottom: 2.0),
enableSuggestionsFieldBorder: true,
suggestionsFieldHeigth: height / 6,
suggestionsFieldBGColor: const Color(0xFF181818),
suggestionsFieldBorderRadius: 25,
suggestionsFieldBorderWidth: 1,
suggestionsFieldBorderColor: Colors.blue,
onSelected: () {
setState(() => firstController.value.text);
},
),
const Spacer(),
SearchBar(
itemHeight: 60,
maximumCharacters: 20,
enableSuggestions: true,
textScaleFactor: textScaleFactor,
textFieldController: secondController,
cursorColor: Colors.white,
enabledBorderColor: Colors.blue,
focusedBorderColor: Colors.blue.withAlpha(100),
labelColor: Colors.white.withAlpha(180),
textColor: Colors.white,
prefixIconColor: Colors.white,
suffixIconColor: Colors.white.withAlpha(100),
suggestionsList: secondSugList,
optionalLabel: "OS",
gap: 12,
itemTextSize: 18,
itemBGColor: const Color(0xFF252525),
itemTextColor: Colors.white,
itemBorderRadius: 25,
itemPadding: const EdgeInsets.only(bottom: 2.0),
enableSuggestionsFieldBorder: true,
suggestionsFieldHeigth: height / 6,
suggestionsFieldBGColor: const Color(0xFF181818),
suggestionsFieldBorderRadius: 25,
suggestionsFieldBorderWidth: 1,
suggestionsFieldBorderColor: Colors.blue,
onSelected: () {
//Do something
},
onSubmitted: () {
//Do something
},
clearAfterSelected: true,
clearAfterSubmission: true,
),
const Spacer(),
],
),
),
);
}
}