text stringlengths 1 474 |
|---|
<code_start>import 'package:flutter/material.dart'; |
import 'package:flutter/rendering.dart'; |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); |
void main() { |
runApp(const MyApp()); |
} |
class MyApp extends StatelessWidget { |
const MyApp({super.key}); |
@override |
Widget build(BuildContext context) { |
return MaterialApp( |
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue), |
debugShowCheckedModeBanner: false, |
home: const Scaffold( |
body: Center( |
child: ExampleParallax(), |
), |
), |
); |
} |
} |
class ExampleParallax extends StatelessWidget { |
const ExampleParallax({ |
super.key, |
}); |
@override |
Widget build(BuildContext context) { |
return SingleChildScrollView( |
child: Column( |
children: [ |
for (final location in locations) |
LocationListItem( |
imageUrl: location.imageUrl, |
name: location.name, |
country: location.place, |
), |
], |
), |
); |
} |
} |
class LocationListItem extends StatelessWidget { |
LocationListItem({ |
super.key, |
required this.imageUrl, |
required this.name, |
required this.country, |
}); |
final String imageUrl; |
final String name; |
final String country; |
final GlobalKey _backgroundImageKey = GlobalKey(); |
@override |
Widget build(BuildContext context) { |
return Padding( |
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16), |
child: AspectRatio( |
aspectRatio: 16 / 9, |
child: ClipRRect( |
borderRadius: BorderRadius.circular(16), |
child: Stack( |
children: [ |
_buildParallaxBackground(context), |
_buildGradient(), |
_buildTitleAndSubtitle(), |
], |
), |
), |
), |
); |
} |
Widget _buildParallaxBackground(BuildContext context) { |
return Flow( |
delegate: ParallaxFlowDelegate( |
scrollable: Scrollable.of(context), |
listItemContext: context, |
backgroundImageKey: _backgroundImageKey, |
), |
children: [ |
Image.network( |
imageUrl, |
key: _backgroundImageKey, |
fit: BoxFit.cover, |
), |
], |
); |
} |
Widget _buildGradient() { |
return Positioned.fill( |
child: DecoratedBox( |
decoration: BoxDecoration( |
gradient: LinearGradient( |
colors: [Colors.transparent, Colors.black.withOpacity(0.7)], |
begin: Alignment.topCenter, |
end: Alignment.bottomCenter, |
stops: const [0.6, 0.95], |
), |
), |
), |
); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.