Skip to content

Instantly share code, notes, and snippets.

@imaNNeo
Created November 14, 2020 17:19
Show Gist options
  • Save imaNNeo/4658cda6225bee4207f5ce05974e2e5c to your computer and use it in GitHub Desktop.
Save imaNNeo/4658cda6225bee4207f5ce05974e2e5c to your computer and use it in GitHub Desktop.
import 'dart:ui';
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 StatefulWidget {
final HeroModel hero;
const HeroDetailsPage(this.hero);
@override
_HeroDetailsPageState createState() => _HeroDetailsPageState();
}
class _HeroDetailsPageState extends State<HeroDetailsPage> {
final appBarHeight = 80.0;
ScrollController _scrollController;
double toolbarOpacity = 1.0;
@override
void initState() {
_scrollController = new ScrollController();
_scrollController.addListener(() {
setState(() {
if (_scrollController.offset <= appBarHeight) {
toolbarOpacity = (appBarHeight - _scrollController.offset) / appBarHeight;
} else {
toolbarOpacity = 0;
}
});
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
width: double.infinity,
height: double.infinity,
child: Stack(
children: [
ListView(
controller: _scrollController,
padding: EdgeInsets.only(top: appBarHeight),
children: [
_HeroDetailsImage(widget.hero.image),
_HeroDetailsName(widget.hero.name),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 22.0, vertical: 12),
child: Text(
"Super smash bros ultimate villagers from the animal crossing series. This troops fight most effectively in large group",
style:
TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.w300),
textAlign: TextAlign.center,
),
),
SizedBox(height: 28,),
Row(
children: [
SizedBox(
width: 28,
),
Expanded(
child: Container(
height: 54,
child: OutlineButton(
child: new Text(
'Add Favourite',
style: TextStyle(
color: Colors.white,
fontSize: 12,
),
),
onPressed: () {},
color: Colors.white,
borderSide: BorderSide(
color: Colors.white,
width: 1,
),
highlightedBorderColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
),
),
),
SizedBox(
width: 14,
),
Expanded(
child: Container(
height: 56,
child: RaisedButton(
onPressed: () {},
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(80.0)),
padding: const EdgeInsets.all(0.0),
child: Ink(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xFFF29758),
Color(0xFFEF5D67),
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter
),
borderRadius: BorderRadius.all(Radius.circular(80.0)),
),
child: Container(
constraints: const BoxConstraints(minWidth: 88.0, minHeight: 36.0),
// min sizes for Material buttons
alignment: Alignment.center,
child: const Text(
'OK',
style: TextStyle(color: Colors.white),
),
),
),
),
),
),
SizedBox(
width: 28,
),
],
),
SizedBox(height: 28,),
],
),
SafeArea(
child: Opacity(
opacity: toolbarOpacity,
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,
),
)
],
),
),
),
],
),
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,
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