Created
October 17, 2020 05:41
-
-
Save ponnamkarthik/f47e5277db1f2a173370f9d2d2e58814 to your computer and use it in GitHub Desktop.
ListView with shadow at bottom if overflows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
brightness: Brightness.dark, | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key}) : super(key: key); | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
ScrollController _controller = ScrollController(); | |
bool showShadow = false; | |
@override | |
void initState() { | |
super.initState(); | |
Future.delayed(Duration(milliseconds: 500), () { | |
setState(() { | |
showShadow = _controller.position.extentAfter > 0; | |
}); | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: Colors.black, | |
body: Stack( | |
children: [ | |
Positioned.fill( | |
child: ListView.builder( | |
padding: const EdgeInsets.only(bottom: 50.0), | |
controller: _controller, | |
itemBuilder: (context, index) { | |
return Text("Item $index"); | |
}, | |
itemCount: 100, | |
) | |
), | |
if(showShadow) | |
Positioned( | |
bottom: 0, | |
left: 0, | |
right: 0, | |
child: Container(height: 60,decoration: BoxDecoration( | |
gradient: LinearGradient( | |
colors: [Colors.transparent, Colors.black], | |
begin: Alignment.topCenter, | |
end:Alignment.bottomCenter, | |
) | |
),), | |
) | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment