Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() {
- runApp(App());
- }
- class App extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'ShowSearch bug',
- home: Home(),
- );
- }
- }
- class Home extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text("HAPPY NEW YEAR WOOO"),
- actions: <Widget>[
- IconButton(
- icon: Icon(Icons.search),
- tooltip: "Search",
- onPressed: () async {
- final result = await showSearch<String>(
- context: context,
- delegate: _MySearchDelegate(),
- );
- },
- )
- ],
- ),
- body: Container(
- child: Center(
- child: Text(
- "Press the search icon in the top right corner to call showSearch()",
- textAlign: TextAlign.center,
- style: TextStyle(fontSize: 24.0),
- ),
- ),
- ),
- );
- }
- }
- class _MySearchDelegate extends SearchDelegate<String> {
- @override
- List<Widget> buildActions(BuildContext context) {
- return <Widget>[
- query.isEmpty
- ? Placeholder(
- fallbackHeight: 0.0,
- fallbackWidth: 0.0,
- )
- : IconButton(
- tooltip: 'Clear',
- icon: const Icon(Icons.clear),
- onPressed: () {
- query = '';
- },
- )
- ];
- }
- @override
- Widget buildLeading(BuildContext context) {
- return IconButton(
- tooltip: 'Back',
- icon: AnimatedIcon(
- icon: AnimatedIcons.menu_arrow,
- progress: transitionAnimation,
- ),
- onPressed: () {
- close(context, null);
- },
- );
- }
- @override
- Widget buildResults(BuildContext context) {
- return Center(
- child: Text("Results"),
- );
- }
- @override
- Widget buildSuggestions(BuildContext context) {
- return Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Text(
- "Now press this button to push a new MaterialPageRoute on top of this one.\nTry searching for something after you're back from that page.",
- style: TextStyle(fontSize: 20.0),
- textAlign: TextAlign.center,
- ),
- IconButton(
- icon: Icon(
- Icons.bug_report,
- size: 64.0,
- color: Colors.red,
- ),
- tooltip: "Push new route",
- onPressed: () {
- Navigator.of(context).push(
- MaterialPageRoute(
- builder: (context) => _MyRoute(),
- ),
- );
- },
- )
- ],
- ),
- );
- }
- }
- class _MyRoute extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text("Title"),
- ),
- body: Center(
- child: Text("Make sure to party hard on New Year's Eve!"),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement