Sei sulla pagina 1di 5

1714004 – Assgn1 – IT-A

SnackBar class
A lightweight message with an optional action which briefly displays at the bottom of the screen.

To display a snack bar, call Scaffold.of(context).showSnackBar(), passing an instance of SnackBar that


describes the message.

To control how long the SnackBar remains visible, specify a duration.

A SnackBar with an action will not time out when TalkBack or VoiceOver are enabled. This is controlled
by AccessibilityFeatures.accessibleNavigation.

Constructors
SnackBar({Key key, @required Widget content, Color backgroundColor, double elevation, ShapeBorder s
hape, SnackBarBehavior behavior, SnackBarAction action, Duration duration: _snackBarDisplayDuration,
Animation<double> animation })

Creates a snack bar. [...]

Const

Card class
A material design card. A card has slightly rounded corners and a shadow.

A card is a sheet of Material used to represent some related information, for example an album, a
geographical location, a meal, contact details, etc.

Constructors
Card({Key key, Color color, double elevation, ShapeBorder shape, bool borderOnForeground: true, EdgeI
nsetsGeometry margin, Clip clipBehavior, Widget child, bool semanticContainer: true })

Creates a material design card. [...]

const

/// Card Code Example

import 'package:flutter/material.dart';
void main() => runApp(MyApp());

/// This Widget is the main application widget.


class MyApp extends StatelessWidget {
static const String _title = 'Flutter Exxample Using Cards';

@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: MyStatelessWidget(),
),
);
}
}

/// This is the stateless widget that the main application instantiates.
class MyStatelessWidget extends StatelessWidget {
MyStatelessWidget({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Center(
child: Card(
color: Color.fromRGBO(10, 10, 100, 0.6),
elevation: 10.2,
margin: EdgeInsets.all(7),

child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const ListTile(
leading: Icon(Icons.business),
title: Text('The Jodn Doe Show'),
subtitle: Text('Presented by One and Only John Doe'),
),
ButtonTheme.bar(
// make buttons use the appropriate styles for cards
child: ButtonBar(
children: <Widget>[
RaisedButton(
child: const Text('BUY TICKETS'),
onPressed: () {/* ... */},
color: Colors.green,
textColor: Colors.white,
),
RaisedButton(
child: const Text('Show me Anohter Show'),
onPressed: () {/* ... */},
color: Colors.red,
textColor: Colors.white,
),
],
),
),
],
),
),
);
}
}
/// SnackBar Code Example
import 'package:flutter/material.dart';
void main() => runApp(SnackBarDemo());
var ctr=0;
class SnackBarDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SnackBar Demo',
home: Scaffold(
appBar: AppBar(
title: Text('SnackBar Demo Pressed Times : $ctr'),
),
body: SnackBarPage(),
),
);
}
}

class SnackBarPage extends StatelessWidget {


@override
Widget build(BuildContext context) {
return Center(
child:
RaisedButton(
onPressed: () {
final snackBar = SnackBar(
content: Text('ERROR This a SnackBar!'),
backgroundColor: Colors.red[100],
elevation: 10,
action: SnackBarAction(
label: 'Press',
onPressed: () {
ctr++;
// Some code to undo the change.
},
),
);

// Find the Scaffold in the widget tree and use


// it to show a SnackBar.
Scaffold.of(context).showSnackBar(snackBar);
},
child: Text('Show SnackBar'),
),
);
}
}
References:
https://api.flutter.dev/flutter/material/Card-class.html

https://api.flutter.dev/flutter/material/SnackBar-class.html

Potrebbero piacerti anche