"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/dev/integration_tests/flutter_gallery/lib/demo/contacts_demo.dart" (13 Nov 2020, 12736 Bytes) of package /linux/misc/flutter-1.22.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright 2014 The Flutter Authors. All rights reserved.
    2 // Use of this source code is governed by a BSD-style license that can be
    3 // found in the LICENSE file.
    4 
    5 import 'package:flutter/material.dart';
    6 import 'package:flutter/services.dart';
    7 
    8 class _ContactCategory extends StatelessWidget {
    9   const _ContactCategory({ Key key, this.icon, this.children }) : super(key: key);
   10 
   11   final IconData icon;
   12   final List<Widget> children;
   13 
   14   @override
   15   Widget build(BuildContext context) {
   16     final ThemeData themeData = Theme.of(context);
   17     return Container(
   18       padding: const EdgeInsets.symmetric(vertical: 16.0),
   19       decoration: BoxDecoration(
   20         border: Border(bottom: BorderSide(color: themeData.dividerColor))
   21       ),
   22       child: DefaultTextStyle(
   23         style: Theme.of(context).textTheme.subtitle1,
   24         child: SafeArea(
   25           top: false,
   26           bottom: false,
   27           child: Row(
   28             crossAxisAlignment: CrossAxisAlignment.start,
   29             children: <Widget>[
   30               Container(
   31                 padding: const EdgeInsets.symmetric(vertical: 24.0),
   32                 width: 72.0,
   33                 child: Icon(icon, color: themeData.primaryColor),
   34               ),
   35               Expanded(child: Column(children: children)),
   36             ],
   37           ),
   38         ),
   39       ),
   40     );
   41   }
   42 }
   43 
   44 class _ContactItem extends StatelessWidget {
   45   const _ContactItem({ Key key, this.icon, this.lines, this.tooltip, this.onPressed })
   46     : assert(lines.length > 1),
   47       super(key: key);
   48 
   49   final IconData icon;
   50   final List<String> lines;
   51   final String tooltip;
   52   final VoidCallback onPressed;
   53 
   54   @override
   55   Widget build(BuildContext context) {
   56     final ThemeData themeData = Theme.of(context);
   57     return MergeSemantics(
   58       child: Padding(
   59         padding: const EdgeInsets.symmetric(vertical: 16.0),
   60         child: Row(
   61           mainAxisAlignment: MainAxisAlignment.spaceBetween,
   62           children: <Widget>[
   63             Expanded(
   64               child: Column(
   65                 crossAxisAlignment: CrossAxisAlignment.start,
   66                 children: <Widget>[
   67                   ...lines.sublist(0, lines.length - 1).map<Widget>((String line) => Text(line)),
   68                   Text(lines.last, style: themeData.textTheme.caption),
   69                 ],
   70               ),
   71             ),
   72             if (icon != null)
   73               SizedBox(
   74                 width: 72.0,
   75                 child: IconButton(
   76                   icon: Icon(icon),
   77                   color: themeData.primaryColor,
   78                   onPressed: onPressed,
   79                 ),
   80               ),
   81           ],
   82         ),
   83       ),
   84     );
   85   }
   86 }
   87 
   88 class ContactsDemo extends StatefulWidget {
   89   static const String routeName = '/contacts';
   90 
   91   @override
   92   ContactsDemoState createState() => ContactsDemoState();
   93 }
   94 
   95 enum AppBarBehavior { normal, pinned, floating, snapping }
   96 
   97 class ContactsDemoState extends State<ContactsDemo> {
   98   static final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
   99   final double _appBarHeight = 256.0;
  100 
  101   AppBarBehavior _appBarBehavior = AppBarBehavior.pinned;
  102 
  103   @override
  104   Widget build(BuildContext context) {
  105     return Theme(
  106       data: ThemeData(
  107         brightness: Brightness.light,
  108         primarySwatch: Colors.indigo,
  109         platform: Theme.of(context).platform,
  110       ),
  111       child: Scaffold(
  112         key: _scaffoldKey,
  113         body: CustomScrollView(
  114           slivers: <Widget>[
  115             SliverAppBar(
  116               expandedHeight: _appBarHeight,
  117               pinned: _appBarBehavior == AppBarBehavior.pinned,
  118               floating: _appBarBehavior == AppBarBehavior.floating || _appBarBehavior == AppBarBehavior.snapping,
  119               snap: _appBarBehavior == AppBarBehavior.snapping,
  120               actions: <Widget>[
  121                 IconButton(
  122                   icon: const Icon(Icons.create),
  123                   tooltip: 'Edit',
  124                   onPressed: () {
  125                     _scaffoldKey.currentState.showSnackBar(const SnackBar(
  126                       content: Text("Editing isn't supported in this screen."),
  127                     ));
  128                   },
  129                 ),
  130                 PopupMenuButton<AppBarBehavior>(
  131                   onSelected: (AppBarBehavior value) {
  132                     setState(() {
  133                       _appBarBehavior = value;
  134                     });
  135                   },
  136                   itemBuilder: (BuildContext context) => <PopupMenuItem<AppBarBehavior>>[
  137                     const PopupMenuItem<AppBarBehavior>(
  138                       value: AppBarBehavior.normal,
  139                       child: Text('App bar scrolls away'),
  140                     ),
  141                     const PopupMenuItem<AppBarBehavior>(
  142                       value: AppBarBehavior.pinned,
  143                       child: Text('App bar stays put'),
  144                     ),
  145                     const PopupMenuItem<AppBarBehavior>(
  146                       value: AppBarBehavior.floating,
  147                       child: Text('App bar floats'),
  148                     ),
  149                     const PopupMenuItem<AppBarBehavior>(
  150                       value: AppBarBehavior.snapping,
  151                       child: Text('App bar snaps'),
  152                     ),
  153                   ],
  154                 ),
  155               ],
  156               flexibleSpace: FlexibleSpaceBar(
  157                 title: const Text('Ali Connors'),
  158                 background: Stack(
  159                   fit: StackFit.expand,
  160                   children: <Widget>[
  161                     Image.asset(
  162                       'people/ali_landscape.png',
  163                       package: 'flutter_gallery_assets',
  164                       fit: BoxFit.cover,
  165                       height: _appBarHeight,
  166                     ),
  167                     // This gradient ensures that the toolbar icons are distinct
  168                     // against the background image.
  169                     const DecoratedBox(
  170                       decoration: BoxDecoration(
  171                         gradient: LinearGradient(
  172                           begin: Alignment.topCenter,
  173                           end: Alignment(0, .35),
  174                           colors: <Color>[Color(0xC0000000), Color(0x00000000)],
  175                         ),
  176                       ),
  177                     ),
  178                   ],
  179                 ),
  180               ),
  181             ),
  182             SliverList(
  183               delegate: SliverChildListDelegate(<Widget>[
  184                 AnnotatedRegion<SystemUiOverlayStyle>(
  185                   value: SystemUiOverlayStyle.dark,
  186                   child: _ContactCategory(
  187                     icon: Icons.call,
  188                     children: <Widget>[
  189                       _ContactItem(
  190                         icon: Icons.message,
  191                         tooltip: 'Send message',
  192                         onPressed: () {
  193                           _scaffoldKey.currentState.showSnackBar(const SnackBar(
  194                             content: Text('Pretend that this opened your SMS application.'),
  195                           ));
  196                         },
  197                         lines: const <String>[
  198                           '(650) 555-1234',
  199                           'Mobile',
  200                         ],
  201                       ),
  202                       _ContactItem(
  203                         icon: Icons.message,
  204                         tooltip: 'Send message',
  205                         onPressed: () {
  206                           _scaffoldKey.currentState.showSnackBar(const SnackBar(
  207                             content: Text('A messaging app appears.'),
  208                           ));
  209                         },
  210                         lines: const <String>[
  211                           '(323) 555-6789',
  212                           'Work',
  213                         ],
  214                       ),
  215                       _ContactItem(
  216                         icon: Icons.message,
  217                         tooltip: 'Send message',
  218                         onPressed: () {
  219                           _scaffoldKey.currentState.showSnackBar(const SnackBar(
  220                             content: Text('Imagine if you will, a messaging application.'),
  221                           ));
  222                         },
  223                         lines: const <String>[
  224                           '(650) 555-6789',
  225                           'Home',
  226                         ],
  227                       ),
  228                     ],
  229                   ),
  230                 ),
  231                 _ContactCategory(
  232                   icon: Icons.contact_mail,
  233                   children: <Widget>[
  234                     _ContactItem(
  235                       icon: Icons.email,
  236                       tooltip: 'Send personal e-mail',
  237                       onPressed: () {
  238                         _scaffoldKey.currentState.showSnackBar(const SnackBar(
  239                           content: Text('Here, your e-mail application would open.'),
  240                         ));
  241                       },
  242                       lines: const <String>[
  243                         'ali_connors@example.com',
  244                         'Personal',
  245                       ],
  246                     ),
  247                     _ContactItem(
  248                       icon: Icons.email,
  249                       tooltip: 'Send work e-mail',
  250                       onPressed: () {
  251                         _scaffoldKey.currentState.showSnackBar(const SnackBar(
  252                           content: Text('Summon your favorite e-mail application here.'),
  253                         ));
  254                       },
  255                       lines: const <String>[
  256                         'aliconnors@example.com',
  257                         'Work',
  258                       ],
  259                     ),
  260                   ],
  261                 ),
  262                 _ContactCategory(
  263                   icon: Icons.location_on,
  264                   children: <Widget>[
  265                     _ContactItem(
  266                       icon: Icons.map,
  267                       tooltip: 'Open map',
  268                       onPressed: () {
  269                         _scaffoldKey.currentState.showSnackBar(const SnackBar(
  270                           content: Text('This would show a map of San Francisco.'),
  271                         ));
  272                       },
  273                       lines: const <String>[
  274                         '2000 Main Street',
  275                         'San Francisco, CA',
  276                         'Home',
  277                       ],
  278                     ),
  279                     _ContactItem(
  280                       icon: Icons.map,
  281                       tooltip: 'Open map',
  282                       onPressed: () {
  283                         _scaffoldKey.currentState.showSnackBar(const SnackBar(
  284                           content: Text('This would show a map of Mountain View.'),
  285                         ));
  286                       },
  287                       lines: const <String>[
  288                         '1600 Amphitheater Parkway',
  289                         'Mountain View, CA',
  290                         'Work',
  291                       ],
  292                     ),
  293                     _ContactItem(
  294                       icon: Icons.map,
  295                       tooltip: 'Open map',
  296                       onPressed: () {
  297                         _scaffoldKey.currentState.showSnackBar(const SnackBar(
  298                           content: Text('This would also show a map, if this was not a demo.'),
  299                         ));
  300                       },
  301                       lines: const <String>[
  302                         '126 Severyns Ave',
  303                         'Mountain View, CA',
  304                         'Jet Travel',
  305                       ],
  306                     ),
  307                   ],
  308                 ),
  309                 _ContactCategory(
  310                   icon: Icons.today,
  311                   children: <Widget>[
  312                     _ContactItem(
  313                       lines: const <String>[
  314                         'Birthday',
  315                         'January 9th, 1989',
  316                       ],
  317                     ),
  318                     _ContactItem(
  319                       lines: const <String>[
  320                         'Wedding anniversary',
  321                         'June 21st, 2014',
  322                       ],
  323                     ),
  324                     _ContactItem(
  325                       lines: const <String>[
  326                         'First day in office',
  327                         'January 20th, 2015',
  328                       ],
  329                     ),
  330                     _ContactItem(
  331                       lines: const <String>[
  332                         'Last day in office',
  333                         'August 9th, 2018',
  334                       ],
  335                     ),
  336                   ],
  337                 ),
  338               ]),
  339             ),
  340           ],
  341         ),
  342       ),
  343     );
  344   }
  345 }