Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() => runApp(MyApp());
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'SliverAppBar Demo',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- ),
- home: MyHomePage(title: 'SliverAppBar Demo'),
- );
- }
- }
- class MyHomePage extends StatefulWidget {
- MyHomePage({Key key, this.title}) : super(key: key);
- final String title;
- @override
- _MyHomePageState createState() => _MyHomePageState();
- }
- class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
- ScrollController _scrollController;
- bool _IsSearching;
- Icon actionIcon = new Icon(Icons.search);
- Widget appBarTitle = new Text("Produtores");
- final TextEditingController _searchQuery = new TextEditingController();
- List<String> _searchList = List();
- @override
- void initState() {
- _scrollController = ScrollController(initialScrollOffset: 200.0);
- _IsSearching = false;
- super.initState();
- }
- void _handleSearchStart() {
- setState(() {
- _IsSearching = true;
- });
- }
- void _handleSearchEnd() {
- setState(() {
- this.actionIcon = new Icon(
- Icons.search,
- color: Colors.white,
- );
- this.appBarTitle = new Text(
- "Produtores",
- style: TextStyle(color: Colors.white),
- );
- _IsSearching = false;
- _searchQuery.clear();
- });
- }
- void searchOperation(String searchText) {
- String name = "";
- if (_IsSearching) {}
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: appBarTitle,
- centerTitle: true,
- actions: <Widget>[
- IconButton(
- icon: actionIcon,
- onPressed: () {
- setState(() {
- if (this.actionIcon.icon == Icons.search) {
- this.actionIcon = new Icon(Icons.close);
- this.appBarTitle = new TextField(
- controller: _searchQuery,
- style: TextStyle(color: Colors.white),
- decoration: InputDecoration(
- prefixIcon: Icon(
- Icons.search,
- color: Colors.white,
- ),
- hintText: "Pesquisar...",
- hintStyle: TextStyle(color: Colors.white)),
- onChanged: searchOperation,
- );
- _handleSearchStart();
- } else {
- _handleSearchEnd();
- }
- });
- },
- )
- ],
- ),
- body: Container(
- child: _searchList.length != 0 || _searchQuery.text.isNotEmpty
- ? AnimatedContainer
- : ListView(
- children: List<String>.generate(50, (i) => "Item $i")
- .map((f) => ListTile(
- title: Text(f),
- ))
- .toList(),
- ),
- ),
- floatingActionButton: FloatingActionButton(
- child: Icon(Icons.clear),
- ),
- /*CustomScrollView(
- controller: _scrollController,
- slivers: <Widget>[
- SliverAppBar(
- pinned: true,
- title: Text(
- widget.title,
- ),
- centerTitle: false,
- flexibleSpace: FlexibleSpaceBar(
- collapseMode: CollapseMode.parallax,
- background: Image.network(
- "https://images.pexels.com/photos/169573/pexels-photo-169573.jpeg?cs=srgb&dl=apple-black-and-white-black-and-white-169573.jpg&fm=jpg",
- fit: BoxFit.fill,
- ),
- ),
- expandedHeight: 256.0,
- ),
- SliverList(
- delegate: SliverChildListDelegate(
- List<String>.generate(50, (i) => "Item $i")
- .map((f) => ListTile(
- title: Text(f),
- ))
- .toList(),
- ),
- ),
- ],
- ),*/
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement