Skip to content

Instantly share code, notes, and snippets.

@rubgithub
Created October 17, 2020 21:08
Show Gist options
  • Save rubgithub/29d762f6f4f751b8d323748f93026dc3 to your computer and use it in GitHub Desktop.
Save rubgithub/29d762f6f4f751b8d323748f93026dc3 to your computer and use it in GitHub Desktop.
Search change state
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String _pesquisa = '';
bool _isLoading = false;
_pesquisarPor(String textoPesquisa) {
setState(() {
_pesquisa = textoPesquisa;
});
}
_setIsLoading(){
setState(() {
_isLoading = !_isLoading;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
_isLoading
? CircularProgressIndicator()
: Text('Lista Carregada!'),
Container(
child: TextField(
onChanged: (value) {
_setIsLoading();
_pesquisarPor(value);
Future.delayed(Duration(seconds: 2), () {
_setIsLoading();
});
},
decoration: InputDecoration(
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
hintText: "Search...",
prefixIcon: Icon(Icons.search),
),
),
),
Text(
'Pesquisando por:',
),
Text(
'$_pesquisa',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment