Created
November 14, 2020 16:48
-
-
Save imaNNeo/bfe285c8812179d1771f3f78e7d92e4c to your computer and use it in GitHub Desktop.
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 HeroModel { | |
final String name; | |
final String image; | |
final double speed, health, attack; | |
HeroModel({ | |
@required this.name, | |
@required this.image, | |
@required this.speed, | |
@required this.health, | |
@required this.attack, | |
}); | |
} | |
final List<HeroModel> heroes = [ | |
HeroModel( | |
name: 'Bombardier', | |
image: 'https://flutter4fun.com/wp-content/uploads/2020/11/Player-1.png', | |
speed: 16.0, | |
health: 40.0, | |
attack: 65.0, | |
), | |
HeroModel( | |
name: 'Bombardier', | |
image: 'https://flutter4fun.com/wp-content/uploads/2020/11/Player-2.png', | |
speed: 25.0, | |
health: 50.0, | |
attack: 75.0, | |
), | |
HeroModel( | |
name: 'Bombardier', | |
image: 'https://flutter4fun.com/wp-content/uploads/2020/11/Player-3.png', | |
speed: 10.0, | |
health: 80.0, | |
attack: 80.0, | |
), | |
]; | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter 4 Fun', | |
home: HeroDetailsPage(heroes[2]), | |
); | |
} | |
} | |
class HeroDetailsPage extends StatelessWidget { | |
final HeroModel hero; | |
const HeroDetailsPage(this.hero); | |
@override | |
Widget build(BuildContext context) { | |
final appBarHeight = 80.0; | |
return Scaffold( | |
body: Container( | |
width: double.infinity, | |
height: double.infinity, | |
child: Stack( | |
children: [ | |
SafeArea( | |
child: Row( | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: [ | |
SizedBox( | |
width: 18, | |
), | |
IconButton( | |
icon: Icon( | |
Icons.arrow_back_ios, | |
color: Colors.white, | |
size: 20, | |
), | |
onPressed: () { | |
Navigator.of(context).pop(); | |
}, | |
), | |
Text( | |
'Overview', | |
style: TextStyle( | |
color: Colors.white, | |
fontSize: 20, | |
fontWeight: FontWeight.bold, | |
), | |
), | |
Expanded( | |
child: Container( | |
height: appBarHeight, | |
)), | |
Container( | |
width: appBarHeight, | |
height: appBarHeight, | |
child: Icon( | |
Icons.menu, | |
color: Colors.white, | |
), | |
) | |
], | |
), | |
), | |
ListView( | |
padding: EdgeInsets.only(top: appBarHeight), | |
children: [ | |
_HeroDetailsImage(hero.image), | |
_HeroDetailsName(hero.name), | |
], | |
) | |
], | |
), | |
decoration: BoxDecoration( | |
gradient: LinearGradient( | |
colors: [ | |
Color(0xFFF4E342), | |
Color(0xFFEE3474), | |
], | |
begin: Alignment(0.3, -1), | |
end: Alignment(-0.8, 1), | |
), | |
), | |
), | |
); | |
} | |
} | |
class _HeroDetailsImage extends StatelessWidget { | |
final String url; | |
const _HeroDetailsImage(this.url); | |
@override | |
Widget build(BuildContext context) { | |
return Padding( | |
padding: const EdgeInsets.only(top: 28.0, left: 28.0, right: 28.0), | |
child: AspectRatio( | |
aspectRatio: 1, | |
child: Container( | |
child: Stack( | |
children: [ | |
Align( | |
child: Container( | |
margin: EdgeInsets.only( | |
left: 16, | |
right: 16, | |
top: 16, | |
), | |
decoration: BoxDecoration( | |
color: Colors.white.withOpacity(0.1), | |
borderRadius: BorderRadius.all(Radius.circular(28)), | |
), | |
), | |
alignment: Alignment.bottomCenter, | |
), | |
Align( | |
child: Container( | |
margin: EdgeInsets.all(8.0), | |
decoration: BoxDecoration( | |
color: Colors.white.withOpacity(0.1), | |
borderRadius: BorderRadius.all(Radius.circular(28)), | |
), | |
), | |
alignment: Alignment.bottomCenter, | |
), | |
Align( | |
child: Container( | |
margin: EdgeInsets.only( | |
bottom: 16, | |
), | |
decoration: BoxDecoration( | |
color: Colors.white.withOpacity(0.4), | |
borderRadius: BorderRadius.all(Radius.circular(28)), | |
), | |
child: Padding( | |
padding: EdgeInsets.all(8), | |
child: Center( | |
child: Image.network(url), | |
), | |
), | |
), | |
alignment: Alignment.bottomCenter, | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} | |
class _HeroDetailsName extends StatelessWidget { | |
final String heroName; | |
const _HeroDetailsName(this.heroName); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
width: double.infinity, | |
margin: EdgeInsets.only(top: 8), | |
height: 86, | |
child: Stack( | |
children: [ | |
Align( | |
alignment: Alignment.bottomCenter, | |
child: Text( | |
heroName, | |
style: TextStyle( | |
color: Colors.white, | |
fontWeight: FontWeight.bold, | |
fontSize: 42, | |
), | |
), | |
), | |
Align( | |
alignment: Alignment.bottomCenter, | |
child: Padding( | |
padding: const EdgeInsets.only(bottom: 18.0), | |
child: Text( | |
heroName, | |
style: TextStyle( | |
color: Colors.white.withOpacity(0.1), | |
fontWeight: FontWeight.bold, | |
fontSize: 56, | |
), | |
), | |
), | |
) | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment