Advertisement
Guest User

Untitled

a guest
Oct 29th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.19 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() => runApp(MyApp());
  4.  
  5. class MyApp extends StatelessWidget {
  6.   @override
  7.   Widget build(BuildContext context) {
  8.     return MaterialApp(
  9.       title: 'SliverAppBar Demo',
  10.       theme: ThemeData(
  11.         primarySwatch: Colors.blue,
  12.       ),
  13.       home: MyHomePage(title: 'SliverAppBar Demo'),
  14.     );
  15.   }
  16. }
  17.  
  18. class MyHomePage extends StatefulWidget {
  19.   MyHomePage({Key key, this.title}) : super(key: key);
  20.  
  21.   final String title;
  22.  
  23.   @override
  24.   _MyHomePageState createState() => _MyHomePageState();
  25. }
  26.  
  27. class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
  28.   ScrollController _scrollController;
  29.   bool _IsSearching;
  30.   Icon actionIcon = new Icon(Icons.search);
  31.   Widget appBarTitle = new Text("Produtores");
  32.   final TextEditingController _searchQuery = new TextEditingController();
  33.   List<String> _searchList = List();
  34.  
  35.   @override
  36.   void initState() {
  37.     _scrollController = ScrollController(initialScrollOffset: 200.0);
  38.     _IsSearching = false;
  39.     super.initState();
  40.   }
  41.  
  42.   void _handleSearchStart() {
  43.     setState(() {
  44.       _IsSearching = true;
  45.     });
  46.   }
  47.  
  48.   void _handleSearchEnd() {
  49.     setState(() {
  50.       this.actionIcon = new Icon(
  51.         Icons.search,
  52.         color: Colors.white,
  53.       );
  54.       this.appBarTitle = new Text(
  55.         "Produtores",
  56.         style: TextStyle(color: Colors.white),
  57.       );
  58.       _IsSearching = false;
  59.       _searchQuery.clear();
  60.     });
  61.   }
  62.  
  63.   void searchOperation(String searchText) {
  64.     String name = "";
  65.     if (_IsSearching) {}
  66.   }
  67.  
  68.   @override
  69.   Widget build(BuildContext context) {
  70.     return Scaffold(
  71.       appBar: AppBar(
  72.         title: appBarTitle,
  73.         centerTitle: true,
  74.         actions: <Widget>[
  75.           IconButton(
  76.             icon: actionIcon,
  77.             onPressed: () {
  78.               setState(() {
  79.                 if (this.actionIcon.icon == Icons.search) {
  80.                   this.actionIcon = new Icon(Icons.close);
  81.                   this.appBarTitle = new TextField(
  82.                     controller: _searchQuery,
  83.                     style: TextStyle(color: Colors.white),
  84.                     decoration: InputDecoration(
  85.                         prefixIcon: Icon(
  86.                           Icons.search,
  87.                           color: Colors.white,
  88.                         ),
  89.                         hintText: "Pesquisar...",
  90.                         hintStyle: TextStyle(color: Colors.white)),
  91.                     onChanged: searchOperation,
  92.                   );
  93.                   _handleSearchStart();
  94.                 } else {
  95.                   _handleSearchEnd();
  96.                 }
  97.               });
  98.             },
  99.           )
  100.         ],
  101.       ),
  102.       body: Container(
  103.         child: _searchList.length != 0 || _searchQuery.text.isNotEmpty
  104.             ? AnimatedContainer
  105.             : ListView(
  106.                 children: List<String>.generate(50, (i) => "Item $i")
  107.                     .map((f) => ListTile(
  108.                           title: Text(f),
  109.                         ))
  110.                     .toList(),
  111.               ),
  112.       ),
  113.       floatingActionButton: FloatingActionButton(
  114.         child: Icon(Icons.clear),
  115.       ),
  116.       /*CustomScrollView(
  117.         controller: _scrollController,
  118.         slivers: <Widget>[
  119.           SliverAppBar(
  120.             pinned: true,
  121.             title: Text(
  122.               widget.title,
  123.             ),
  124.             centerTitle: false,
  125.             flexibleSpace: FlexibleSpaceBar(
  126.               collapseMode: CollapseMode.parallax,
  127.               background: Image.network(
  128.                 "https://images.pexels.com/photos/169573/pexels-photo-169573.jpeg?cs=srgb&dl=apple-black-and-white-black-and-white-169573.jpg&fm=jpg",
  129.                 fit: BoxFit.fill,
  130.               ),
  131.             ),
  132.             expandedHeight: 256.0,
  133.           ),
  134.           SliverList(
  135.             delegate: SliverChildListDelegate(
  136.               List<String>.generate(50, (i) => "Item $i")
  137.                   .map((f) => ListTile(
  138.                         title: Text(f),
  139.                       ))
  140.                   .toList(),
  141.             ),
  142.           ),
  143.         ],
  144.       ),*/
  145.     );
  146.   }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement