import 'package:feelverapp/ui/shop/shop.dart';
import 'package:feelverapp/ui/shop/shop_Nearby_places.dart';
import 'package:feelverapp/ui/shop/shop_reviews.dart';
import 'package:feelverapp/ui/shop/shop_service.dart';
import 'package:feelverapp/util/SizeConfig.dart';
import 'package:flutter/material.dart';

import 'dart:math';




class MainShop extends StatefulWidget {
  MainShop({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MainShopState createState() => _MainShopState();
}

class _MainShopState extends State<MainShop>  with SingleTickerProviderStateMixin /*<-- This is for the controllers*/ {
  TabController _controller; // To control switching tabs
  ScrollController _scrollViewController; // To control scrolling

  List<String> items = [];
  List<Color> colors = [Colors.red, Colors.green, Colors.yellow, Colors.purple, Colors.blue, Colors.amber, Colors.cyan, Colors.pink];
  Random random = new Random();

  Color getRandomColor() {
    return colors.elementAt(random.nextInt(colors.length));
  }

  @override
  void initState() {
    super.initState();
    _controller = new TabController(length: 4, vsync: this);
     _controller.addListener(_handleTabSelection);
    _scrollViewController =ScrollController();
  }
 void _handleTabSelection() {
    setState(() {});
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
    _scrollViewController.dispose();
  }

  @override
  
  Widget build(BuildContext context) {
 SizeConfig(context);
 // Init the items
 

    return Scaffold(
    //  backgroundColor: Colors.transparent,
      
      body: NestedScrollView(
        controller: _scrollViewController,
        headerSliverBuilder: (BuildContext context, bool boxIsScrolled) {
          return <Widget>[
            SliverAppBar(
                backgroundColor: Color.fromRGBO(106, 179, 170, 1),
                 
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios, color: Colors.white),
          onPressed: () => Navigator.of(context).pop(),
        ),
              title: Center(child:Text("Thai Body Balance",style:TextStyle(
                        color:Colors.white,
                        fontSize: 25)),),
              floating: true,
              pinned: false,
              snap: true,
              bottom: new TabBar(
              
              indicatorColor:Colors.transparent,
              controller: _controller,
              tabs: [
                new Tab(
                  icon: Icon(Icons.assignment,
                      color: _controller.index == 0
                          ? Colors.yellowAccent
                          : Colors.white),
                  child: Text(
                    'ข้อมูลร้าน',
                    style: TextStyle(
                        color: _controller.index == 0
                            ? Colors.yellowAccent
                            : Colors.white,
                        fontSize: 11),
                  ),
                ),
                new Tab(
                  icon: Icon(Icons.loyalty,
                      color: _controller.index == 1
                          ? Colors.yellowAccent
                          : Colors.white),
                  child: Text(
                    'บริการ',
                    style: TextStyle(
                        color: _controller.index == 1
                            ? Colors.yellowAccent
                            : Colors.white,
                        fontSize: 11),
                  ),
                ),
                new Tab(
                  icon: Icon(Icons.star,
                      color: _controller.index == 2
                          ? Colors.yellowAccent
                          : Colors.white),
                  child: Text(
                    'รีวิว',
                    style: TextStyle(
                        color: _controller.index == 2
                            ? Colors.yellowAccent
                            : Colors.white,
                        fontSize: 11),
                  ),
                ),
                Container(
                    width: 200,
                    child: Tab(
                      icon: Icon(Icons.pin_drop,
                          color: _controller.index == 3
                              ? Colors.yellowAccent
                              : Colors.white),
                      child: Text(
                        'สถานที่ใกล้เคียง',
                        maxLines: 1,
                        style: TextStyle(
                            color: _controller.index == 3
                                ? Colors.yellowAccent
                                : Colors.white,
                            fontSize: 9),
                      ),
                    ))
              ],
            ),
            ),
          ];
        },
        body: new Container(
            height: double.maxFinite,
            child: new TabBarView(
              controller: _controller,
              children: <Widget>[
                Container(
                  child:Shop()
                  // child: getlist(),
                  //width: 20,
                ),

                Column(
                  children: <Widget>[
                    Container(
                      color: Colors.white,
                      height: 120,
                      child: Wrap(
                        alignment: WrapAlignment.start,
                        spacing: 10.0, // gap between adjacent chips
                        runSpacing: 5.0, // gap between lines
                        children: <Widget>[
                          FilterChip(
                            label: Text(
                              "ทั้งหมด (10)",
                              style: TextStyle(
                                  color: Colors.white,
                                  fontSize: SizeConfig.getFontSize(15),
                                  fontFamily: "SF_Pro_Text",
                                  fontWeight: FontWeight.w500),
                            ),
                            backgroundColor: Color.fromRGBO(106, 179, 170, 1),
                            shape: StadiumBorder(
                              side: BorderSide(color: Colors.white),
                            ),
                            onSelected: (bool value) {
                              print("selected");
                              setState(() {});
                            },
                          ),
                          FilterChip(
                            label: Text(
                              "ที่เที่ยว (5)",
                              style: TextStyle(
                                  color: Colors.white,
                                  fontSize: SizeConfig.getFontSize(15),
                                  fontFamily: "SF_Pro_Text",
                                  fontWeight: FontWeight.w500),
                            ),
                            backgroundColor: Color.fromRGBO(106, 179, 170, 1),
                            shape: StadiumBorder(
                              side: BorderSide(color: Colors.white),
                            ),
                            onSelected: (bool value) {
                              print("selected");
                            },
                          ),
                          FilterChip(
                            label: Text(
                              "ที่กิน (3)",
                              style: TextStyle(
                                  color: Colors.white,
                                  fontSize: SizeConfig.getFontSize(15),
                                  fontFamily: "SF_Pro_Text",
                                  fontWeight: FontWeight.w500),
                            ),
                            backgroundColor: Color.fromRGBO(106, 179, 170, 1),
                            shape: StadiumBorder(
                              side: BorderSide(color: Colors.white),
                            ),
                            onSelected: (bool value) {
                              print("selected");
                            },
                          ),
                          FilterChip(
                            label: Text(
                              "ที่พัก (1)",
                              style: TextStyle(
                                  color: Colors.white,
                                  fontFamily: "SF_Pro_Text",
                                  fontWeight: FontWeight.w500),
                            ),
                            backgroundColor: Color.fromRGBO(106, 179, 170, 1),
                            shape: StadiumBorder(
                              side: BorderSide(color: Colors.white),
                            ),
                            onSelected: (bool value) {
                              print("selected");
                            },
                          ),
                          FilterChip(
                            label: Text(
                              "กิจกรรม (1)",
                              style: TextStyle(
                                  color: Colors.white,
                                  fontSize: SizeConfig.getFontSize(15),
                                  fontFamily: "SF_Pro_Text",
                                  fontWeight: FontWeight.w500),
                            ),
                            backgroundColor: Color.fromRGBO(106, 179, 170, 1),
                            shape: StadiumBorder(
                              side: BorderSide(color: Colors.white),
                            ),
                            onSelected: (bool value) {
                              print("selected");
                            },
                          ),
                        ],
                      ),
                    ),
                Expanded(
                                  child: Container(
                    //  color: Colors.blue,
                      //  height: double.maxFinite,
                        child:  ShopServicePage(),
                      ),
                ),
                  ],
                ),
                // child: getlist(),
                //width: 20,

                Container(
//                  color: Colors.red,
                  child: ShopReviewsPage(),
                  // child: getlist(),
                  //width: 20,
                ),
//
                Container(
//                width: double.maxFinite,
//                color: Colors.yellow,
//              child: setupView(),
                  child: ShopNearbyPlacesPage(),
                ),
              ],
            ),
          ),
      ),
    );

  }
}