Advertisement
Guest User

diegoveloper/flutter_stretchy_header issue repro code

a guest
Jan 2nd, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.43 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:stretchy_header/stretchy_header.dart';
  3.  
  4. class StretchyHeaderTest extends StatefulWidget {
  5.   @override
  6.   _StretchyHeaderTestState createState() => _StretchyHeaderTestState();
  7. }
  8.  
  9. class _StretchyHeaderTestState extends State<StretchyHeaderTest> {
  10.  
  11.   int selectedAmount = 0;
  12.  
  13.   void selectAmount(int amount) {
  14.     selectedAmount = amount;
  15.   }
  16.  
  17.   List<Widget> getAmountWidgetsList() {
  18.     List<Widget> list = new List();
  19.  
  20.     for (int i = 1; i < 8; i++) {
  21.       var selected = (selectedAmount == i);
  22.       var amountWidget = Padding(
  23.         padding: EdgeInsets.symmetric(horizontal: 15.0, vertical: 22.5),
  24.         child: Material(
  25.           color: selected ? Colors.grey[100] : Colors.white,
  26.           borderRadius: BorderRadius.circular(10.0),
  27.           elevation: selected ? 15.0 : 3.0,
  28.           child: new InkWell(
  29.             borderRadius: BorderRadius.circular(10.0),
  30.             onTap: () {
  31.               setState(() {
  32.                 selectAmount(i);
  33.               });
  34.             },
  35.             child: Padding(
  36.               padding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 20.0),
  37.               child: Column(
  38.                 children: <Widget>[
  39.                   Text("Size x$i",
  40.                       style: TextStyle(fontSize: 15.0)),
  41.                   SizedBox(height: 5.0),
  42.                   Text("really cute",
  43.                       style: TextStyle(
  44.                         fontSize: 12.5,
  45.                         color: Colors.grey,
  46.                         //fontStyle: FontStyle.italic
  47.                       )),
  48.                   SizedBox(height: 5.0),
  49.                   Text("${i * 75}\$",
  50.                       style: TextStyle(fontSize: 20.0)),
  51.                 ],
  52.               ),
  53.             ),
  54.           ),
  55.         ),
  56.       );
  57.  
  58.       list.add(amountWidget);
  59.     }
  60.  
  61.     return list;
  62.   }
  63.  
  64.   @override
  65.   Widget build(BuildContext context) {
  66.     return Scaffold(
  67.       appBar: AppBar(title: Text("Teddy Bear")),
  68.       body: Container(
  69.         child: StretchyHeader.singleChild(
  70.           headerData: HeaderData(
  71.               headerHeight: 250,
  72.               header: Image(
  73.                   image: NetworkImage("https://www.o2lifestyle.es/wp-content/uploads/2016/07/osito-ted.jpg"),
  74.                   fit: BoxFit.cover),
  75.               blurContent: false,
  76.               blurColor: Color.fromRGBO(255, 255, 255, 0.1)),
  77.           child: Column(
  78.             children: <Widget>[
  79.               SizedBox(
  80.                 height: 15,
  81.               ),
  82.               Text(
  83.                 "Teddy Bear",
  84.                 style: TextStyle(fontSize: 45),
  85.               ),
  86.               SingleChildScrollView(
  87.                 controller: ScrollController(keepScrollOffset: false),
  88.                 scrollDirection: Axis.horizontal,
  89.                 child: Padding(
  90.                   padding: const EdgeInsets.only(
  91.                       bottom: 15.0, left: 7.0, right: 7.0),
  92.                   child: Row(
  93.                     mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  94.                     children: getAmountWidgetsList(),
  95.                   ),
  96.                 ),
  97.               ),
  98.               SizedBox(height: 15),
  99.               RaisedButton(
  100.                 child: Text("Add to cart"),
  101.                 onPressed: () {},
  102.               ),
  103.               SizedBox(height: 15),
  104.             ],
  105.           ),
  106.         ),
  107.       )
  108.     );
  109.   }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement