mirror of
https://github.com/flutter/samples.git
synced 2025-11-12 15:58:32 +00:00
Update web/ samples to work with Flutter SDK (#134)
* add package:http dependency in dad_jokes * add package:http dependency in filipino_cuisine * don't build package:http demos until flutter/flutter#34858 is resolved * update gallery * update github_dataviz * update particle_background * don't build github_dataviz (uses package:http) * update slide_puzzle * update spinning_square * update timeflow * update vision_challenge * update charts * update dad_jokes * update filipino cuisine * ignore build output * update timeflow and vision_challenge * update slide_puzzle * don't commit build/ directory * move preview.png images to assets * fix path url join * update readme * update web/readme.md
This commit is contained in:
109
web/gallery/lib/demo/material/banner_demo.dart
Normal file
109
web/gallery/lib/demo/material/banner_demo.dart
Normal file
@@ -0,0 +1,109 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../gallery/demo.dart';
|
||||
|
||||
enum BannerDemoAction {
|
||||
reset,
|
||||
showMultipleActions,
|
||||
showLeading,
|
||||
}
|
||||
|
||||
class BannerDemo extends StatefulWidget {
|
||||
const BannerDemo({ Key key }) : super(key: key);
|
||||
|
||||
static const String routeName = '/material/banner';
|
||||
|
||||
@override
|
||||
_BannerDemoState createState() => _BannerDemoState();
|
||||
}
|
||||
|
||||
class _BannerDemoState extends State<BannerDemo> {
|
||||
static const int _numItems = 20;
|
||||
bool _displayBanner = true;
|
||||
bool _showMultipleActions = true;
|
||||
bool _showLeading = true;
|
||||
|
||||
void handleDemoAction(BannerDemoAction action) {
|
||||
setState(() {
|
||||
switch (action) {
|
||||
case BannerDemoAction.reset:
|
||||
_displayBanner = true;
|
||||
_showMultipleActions = true;
|
||||
_showLeading = true;
|
||||
break;
|
||||
case BannerDemoAction.showMultipleActions:
|
||||
_showMultipleActions = !_showMultipleActions;
|
||||
break;
|
||||
case BannerDemoAction.showLeading:
|
||||
_showLeading = !_showLeading;
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Widget banner = MaterialBanner(
|
||||
content: const Text('Your password was updated on your other device. Please sign in again.'),
|
||||
leading: _showLeading ? const CircleAvatar(child: Icon(Icons.access_alarm)) : null,
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: const Text('SIGN IN'),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_displayBanner = false;
|
||||
});
|
||||
}
|
||||
),
|
||||
if (_showMultipleActions)
|
||||
FlatButton(
|
||||
child: const Text('DISMISS'),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_displayBanner = false;
|
||||
});
|
||||
}
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Banner'),
|
||||
actions: <Widget>[
|
||||
MaterialDemoDocumentationButton(BannerDemo.routeName),
|
||||
PopupMenuButton<BannerDemoAction>(
|
||||
onSelected: handleDemoAction,
|
||||
itemBuilder: (BuildContext context) => <PopupMenuEntry<BannerDemoAction>>[
|
||||
const PopupMenuItem<BannerDemoAction>(
|
||||
value: BannerDemoAction.reset,
|
||||
child: Text('Reset the banner'),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
CheckedPopupMenuItem<BannerDemoAction>(
|
||||
value: BannerDemoAction.showMultipleActions,
|
||||
checked: _showMultipleActions,
|
||||
child: const Text('Multiple actions'),
|
||||
),
|
||||
CheckedPopupMenuItem<BannerDemoAction>(
|
||||
value: BannerDemoAction.showLeading,
|
||||
checked: _showLeading,
|
||||
child: const Text('Leading icon'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView.builder(itemCount: _displayBanner ? _numItems + 1 : _numItems, itemBuilder: (BuildContext context, int index) {
|
||||
if (index == 0 && _displayBanner) {
|
||||
return banner;
|
||||
}
|
||||
return ListTile(title: Text('Item ${_displayBanner ? index : index + 1}'),);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user