Skip to content

Commit

Permalink
중복 코드 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
Origogi committed Feb 20, 2024
1 parent 038680f commit fc5559f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 82 deletions.
97 changes: 17 additions & 80 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,81 +29,11 @@ class MyHomePage extends StatefulWidget {
_MyHomePageState createState() => _MyHomePageState();
}

final List<String> titles = [
"AKALI",
"CAMILE",
"EZREAL",
"IRELIA",
"POPPY",
"ZOE",
];

final List<Widget> images = [
Hero(
tag: "AKALI",
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Image.asset(
"images/akali_lol.gif",
fit: BoxFit.cover,
),
),
),
Hero(
tag: "CAMILE",
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Image.asset(
"images/camile_lol.gif",
fit: BoxFit.cover,
),
),
),
Hero(
tag: "EZREAL",
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Image.asset(
"images/ezreal_lol.gif",
fit: BoxFit.cover,
),
),
),
Hero(
tag: "IRELIA",
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Image.asset(
"images/irelia_lol.gif",
fit: BoxFit.cover,
),
),
),
Hero(
tag: "POPPY",
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Image.asset(
"images/poppy_lol.gif",
fit: BoxFit.cover,
),
),
),
Hero(
tag: "ZOE",
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Image.asset(
"images/zoe_lol.gif",
fit: BoxFit.cover,
),
),
),
];

class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
final champions = championsMap.values.toList();

return Scaffold(
body: SafeArea(
child: Column(
Expand All @@ -123,19 +53,26 @@ class _MyHomePageState extends State<MyHomePage> {
Expanded(
child: Container(
child: VerticalCardPager(
// textStyle: TextStyle(color : Colors.red),
titles: titles,
images: images,
onPageChanged: (page) {
// print(page);
},
titles: champions.map((e) => e.name.toUpperCase()).toList(),
images: champions
.map((e) => Hero(
tag: e.name.toUpperCase(),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Image.network(
e.imageUrl,
fit: BoxFit.cover,
),
),
))
.toList(),
onPageChanged: (page) {},
onSelectedItem: (index) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailView(
champion:
championsMap[titles[index].toLowerCase()]!,
champion: champions[index],
)),
);
},
Expand Down
14 changes: 14 additions & 0 deletions example/lib/model/champion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ class Champion {
final Role role;
final Difficulty difficulty;
final String description;
final String imageUrl;

const Champion(
{required this.name,
required this.nickName,
required this.difficulty,
required this.role,
required this.imageUrl,
required this.description});
}

Expand All @@ -21,41 +23,53 @@ final championsMap = {
role: Role.ASSASIN,
difficulty: Difficulty.MODERATE,
nickName: "THE ROGUE ASSASSIN",
imageUrl:
"https://firebasestorage.googleapis.com/v0/b/flutter-vertical-card-pager.appspot.com/o/akali_lol.webp?alt=media",
description:
"Abandoning the Kinkou Order and her title of the Fist of Shadow, Akali now strikes alone, ready to be the deadly weapon her people need. Though she holds onto all she learned from her master Shen, she has pledged to defend Ionia from its enemies, one kill at a time. Akali may strike in silence, but her message will be heard loud and clear: fear the assassin with no master."),
"camile": Champion(
name: "Camile",
role: Role.FIGHTER,
difficulty: Difficulty.MODERATE,
nickName: "THE STEEL SHADOW",
imageUrl:
"https://firebasestorage.googleapis.com/v0/b/flutter-vertical-card-pager.appspot.com/o/camile_lol.webp?alt=media",
description:
"Weaponized to operate outside the boundaries of the law, Camille is the Principal Intelligencer of Clan Ferros—an elegant and elite agent who ensures the Piltover machine and its Zaunite underbelly runs smoothly. Adaptable and precise, she views sloppy technique as an embarrassment that must be put to order. With a mind as sharp as the blades she bears, Camille's pursuit of superiority through hextech body augmentation has left many to wonder if she is now more machine than woman."),
"ezreal": Champion(
name: "Ezreal",
role: Role.MARKSMAN,
difficulty: Difficulty.MODERATE,
nickName: "THE PRODIGAL EXPLORER",
imageUrl:
"https://firebasestorage.googleapis.com/v0/b/flutter-vertical-card-pager.appspot.com/o/ezreal_lol.webp?alt=media",
description:
"A dashing adventurer, unknowingly gifted in the magical arts, Ezreal raids long-lost catacombs, tangles with ancient curses, and overcomes seemingly impossible odds with ease. His courage and bravado knowing no bounds, he prefers to improvise his way out of any situation, relying partially on his wits, but mostly on his mystical Shuriman gauntlet, which he uses to unleash devastating arcane blasts. One thing is for sure—whenever Ezreal is around, trouble isn't too far behind. Or ahead. Probably everywhere."),
"zoe": Champion(
name: "Zoe",
role: Role.MAGE,
difficulty: Difficulty.HIGH,
nickName: "THE ASPECT OF TWILIGHT",
imageUrl:
"https://firebasestorage.googleapis.com/v0/b/flutter-vertical-card-pager.appspot.com/o/zoe_lol.webp?alt=media",
description:
"As the embodiment of mischief, imagination, and change, Zoe acts as the cosmic messenger of Targon, heralding major events that reshape worlds. Her mere presence warps the arcane mathematics governing realities, sometimes causing cataclysms without conscious effort or malice. This perhaps explains the breezy nonchalance with which Zoe approaches her duties, giving her plenty of time to focus on playing games, tricking mortals, or otherwise amusing herself. An encounter with Zoe can be joyous and life affirming, but it is always more than it appears and often extremely dangerous."),
"irelia": Champion(
name: "Irelia",
role: Role.FIGHTER,
difficulty: Difficulty.MODERATE,
nickName: "THE BLADE DANCER",
imageUrl:
"https://firebasestorage.googleapis.com/v0/b/flutter-vertical-card-pager.appspot.com/o/irelia_lol.webp?alt=media",
description:
"The Noxian occupation of Ionia produced many heroes, none more unlikely than young Irelia of Navori. Trained in the ancient dances of her province, she adapted her art for war, using the graceful and carefully practised movements to levitate a host of deadly blades. After proving herself as a fighter, she was thrust into the role of resistance leader and figurehead, and to this day remains dedicated to the preservation of her homeland."),
"poppy": Champion(
name: "Poppy",
role: Role.TANKER,
difficulty: Difficulty.MODERATE,
nickName: "KEEPER OF THE HAMMER",
imageUrl:
"https://firebasestorage.googleapis.com/v0/b/flutter-vertical-card-pager.appspot.com/o/poppy_lol.webp?alt=media",
description:
"Runeterra has no shortage of valiant champions, but few are as tenacious as Poppy. Bearing the legendary hammer of Orlon, a weapon twice her size, this determined yordle has spent untold years searching in secret for the fabled “Hero of Demacia,” said to be its rightful wielder. Until then, she dutifully charges into battle, pushing back the kingdom's enemies with every whirling strike."),
};
4 changes: 2 additions & 2 deletions example/lib/page/detail_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class _DetailViewState extends State<DetailView> with TickerProviderStateMixin {
children: [
Hero(
tag: champion.name.toUpperCase(),
child: Image.asset(
"images/${champion.name.toLowerCase()}_lol.gif",
child: Image.network(
champion.imageUrl,
fit: BoxFit.fitWidth,
width: double.infinity,
),
Expand Down

0 comments on commit fc5559f

Please sign in to comment.