Skip to content

Instantly share code, notes, and snippets.

@slamdon
slamdon / product_item.dart
Created February 23, 2020 13:01
onPressed
onPressed: () {
final _cart = Provider.of<CartProvider>(context);
_cart.addProduct(this.product);
},
@slamdon
slamdon / home_page.dart
Created February 23, 2020 12:59
Provider
final _cart = Provider.of<CartProvider>(context);
...
FlatButton(
child: Text(
"${_cart.products.length}",
style: TextStyle(color: Colors.white, fontSize: 20),
),
onPressed: () {
@slamdon
slamdon / main.dart
Created February 23, 2020 12:56
MyApp
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: ChangeNotifierProvider.value(
value: CartProvider(),
@slamdon
slamdon / cart_provider.dart
Created February 23, 2020 12:21
CartProvider
class CartProvider with ChangeNotifier {
List<Product> products = [];
addProduct(Product product) {
products.add(product);
notifyListeners();
}
}
@slamdon
slamdon / product_item.dart
Created February 23, 2020 12:05
Product Description
Widget _buildInformationMiddleContainer(BuildContext context) {
return Padding(
padding: EdgeInsets.fromLTRB(0, 4, 0, 4),
child: Text(
this.product.description,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: Colors.grey, fontSize: 12),
),
);
@slamdon
slamdon / product_item.dart
Created February 23, 2020 11:57
InformationContainer
Widget _buildInformationTopContainer(BuildContext context) {
return Container(
child: Row(
children: <Widget>[
Expanded(
child: Text(this.product.title),
flex: 1,
),
Expanded(
child: ListView.builder(
Column(
children: <Widget>[
_buildInformationTopContainer(context),
_buildInformationMiddleContainer(context),
_buildInformationBottomContainer(context),
],
),
@slamdon
slamdon / product_item.dart
Created February 23, 2020 11:39
ImageContainer
Widget _buildImageContainer(BuildContext context) {
return ClipRRect(
child: SizedBox(
child: Image.asset(
this.product.imagePath,
fit: BoxFit.cover,
),
),
borderRadius: BorderRadius.circular(10),
);
@slamdon
slamdon / home_page.dart
Created February 17, 2020 02:24
HomePage
@override
Widget build(BuildContext context) {
return Center(
child: SizedBox.fromSize(
size: Size.fromHeight(550),
child: TripPageTransformer(
pageViewBuilder: (context, visibilityResolver) {
return PageView.builder(
controller: PageController(viewportFraction: 0.85),
itemCount: trips.length,
@slamdon
slamdon / tripPageTransformer.dart
Last active February 17, 2020 02:20
tripPageTransformer
@override
Widget build(BuildContext context) {
final pageView = this.widget.pageViewBuilder(
context,
_visibilityResolver ?? TripPageVisibilityResolver(),
);
return NotificationListener<ScrollNotification>(
child: pageView,
onNotification: (ScrollNotification notification) {