title: Flutter : how to hide and show button on last and first index in listView
body: <p>i set two buttons(left and right Button) on top of ListView. buttons work for scrolling on click. now i want to hide the left button when index is 0 and the right button when index is last. more explain to clear, the left button will be hidden in first index and the right button will be hidden in last index. please help me.</p>
  <pre><code>class ScrollingLeftAndRightButtonHide extends StatefulWidget {
  @override
  _ScrolllingOnClickButtonState createState() =&gt;
    _ScrolllingOnClickButtonState();}
  
  class _ScrolllingOnClickButtonState
  extends State&lt;ScrollingLeftAndRightButtonHide&gt; {
  
  final _controller = ScrollController();
  var _width = 100.0;
  
  @override
  Widget build(BuildContext context) {
  
  var sizeDevice = MediaQuery.of(context).size;
  this._width = sizeDevice.width;
  
  var recentIndexIncrease = 0;
  var recentIndexDecrease = 0;
  
  return MaterialApp(
    debugShowCheckedModeBanner: false,
    home: Scaffold(
      body: Column(
        children: &lt;Widget&gt;[
          Expanded(
              flex: 1,
              child: Container(
                color: Colors.green,
              )),
          Expanded(
              flex: 2,
              child: Row(
                children: &lt;Widget&gt;[
                  Padding(
                    padding: const EdgeInsets.only(left: 8.0),
                    child: ClipOval(
                      child: Material(
                        color: Colors.blue, // button color
                        child: InkWell(
                          splashColor: Colors.red, // inkwell color
                          child: SizedBox(
                              width: 56,
                              height: 56,
                              child: Icon(Icons.arrow_back)),
  
                          onTap: () {
                            var recentIndexDecreaseMinus =
                                recentIndexDecrease--;
  
                            _animateToIndex(recentIndexDecrease);
                          },
                        ),
                      ),
                    ),
                  ),
                  Expanded(
                      flex: 2,
                      child: Container(
                        color: Colors.transparent,
                      )),
                  Padding(
                    padding: const EdgeInsets.only(right: 8),
                    child: ClipOval(
                      child: Material(
                        color: Colors.blue, // button color
                        child: InkWell(
                          splashColor: Colors.red, // inkwell color
                          child: SizedBox(
                              width: 56,
                              height: 56,
                              child: Icon(Icons.arrow_forward)),
                          onTap: () {
                            _animateToIndex(recentIndexIncrease);
                          },
                        ),
                      ),
                    ),
                  ),
                ],
              )),
          Expanded(
            flex: 16,
            child: Container(
              // height: 400,
              child: ListView.builder(
                  controller: _controller,
                  scrollDirection: Axis.horizontal,
                  physics: PageScrollPhysics(),
                  itemCount: word_data.drink.length,
                  itemBuilder: (BuildContext context, int index) {
                    recentIndexIncrease = index;
                    recentIndexDecrease = index;
                    var wordDataReplace = word_data.drink[index]
                        .replaceAll(&quot; &quot;, &quot;_&quot;)
                        .toLowerCase();
  
                    return Container(
                      child: Column(
                        children: &lt;Widget&gt;[
                          Expanded(
                              flex: 6,
                              child: GestureDetector(
                                child: Container(
                                  color: Colors.purple,
                                  child: Padding(
                                    padding: const EdgeInsets.all(10.0),
                                    child: Image.asset(
                                      &quot;asset/drink_images/&quot; +
                                          wordDataReplace +
                                          &quot;.png&quot;,
                                      fit: BoxFit.contain,
                                    ),
                                  ),
                                ),
                              )),
                        ],
                      ),
                      width: sizeDevice.width,
                    );
                  }),
              color: Colors.yellow,
            ),
          ),
        ],
      ),
    ),
  );
  }
  
   _animateToIndex(i) =&gt; _controller.animateTo(_width * i,
    duration: Duration(seconds: 1), curve: Curves.fastOutSlowIn);
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/VqH2n.png" rel="nofollow noreferrer">this image of (ListView with top two Button)</a></p>