Skip to content

Commit

Permalink
added a new appbar and fixed the CardDetailScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
joao committed Apr 13, 2021
1 parent f1e066c commit 9211b16
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 83 deletions.
55 changes: 38 additions & 17 deletions lib/Screens/CardDetail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,52 @@ import 'package:flutter/material.dart';
class CardDetail extends StatelessWidget {
CardDetail({this.card});
final MagicCard card;

TextStyle cardStyle = TextStyle(fontSize: 20, fontWeight: FontWeight.bold);
@override
Widget build(BuildContext context) {
Text power_toughness;
return Scaffold(
appBar: AppBar(
title: Text("carta"),
elevation: 0,
title: Text(
card.name,
style: cardStyle,
),
centerTitle: true,
),
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.network(card.image),
Container(
color: Colors.black,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Card name: " + card.name),
Text("Type: " + card.type),
Text("Card Text: " + card.text),
Text("Rarity: " + card.rarity),
power_toughness = card.power != null && card.toughness != null
? Text("P/T: " + card.power + "/" + card.toughness)
: null
],
Padding(
padding: EdgeInsets.all(10),
child: Container(
width: 187,
height: 260,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(15)),
image: DecorationImage(
image: NetworkImage(card.image), fit: BoxFit.cover),
),
),
),
Padding(
padding: EdgeInsets.only(left: 10),
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text("Card Name", style: cardStyle),
Text(card.name),
Text("Card Type", style: cardStyle),
Text(card.type),
Text("Card Text", style: cardStyle),
Text(card.text),
Text("Rarity", style: cardStyle),
Text(card.rarity),
Text("P/T: " + card.power + "/" + card.toughness)
],
),
),
)
],
Expand Down
170 changes: 125 additions & 45 deletions lib/Screens/HomeScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import 'package:MtgSearcher/Networking/NetworkHelper.dart';
import 'package:MtgSearcher/Widgets/MagicCard.dart';
import 'package:flutter/material.dart';

import '../Widgets/MagicCard.dart';
import '../Widgets/MagicCard.dart';

const url = "https://api.magicthegathering.io/v1/cards?name=";

class HomeScreen extends StatefulWidget {
Expand All @@ -10,7 +13,7 @@ class HomeScreen extends StatefulWidget {
}

class _HomeScreenState extends State<HomeScreen> {
var cards = <MagicCard>[];
List<MagicCard> cards;
var _textController = TextEditingController();

void search() async {
Expand All @@ -24,53 +27,79 @@ class _HomeScreenState extends State<HomeScreen> {
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
elevation: 0,
backgroundColor: ThemeData.dark().scaffoldBackgroundColor,
centerTitle: true,
title: Text(
"MTG Searcher",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w700),
),
),
body: Padding(
padding: EdgeInsets.fromLTRB(8, 10, 8, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TextField(
style: TextStyle(fontWeight: FontWeight.bold),
cursorColor: Colors.green,
decoration: InputDecoration(
labelText: "Search Terms..",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(18),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(18),
),
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScroled) {
return <Widget>[
SliverAppBar(
title: Text(
"MTG Searcher",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w700),
),
controller: _textController,
onSubmitted: (text) {
search();
},
/*onEditingComplete: search*/
elevation: 0,
toolbarHeight: 50,
centerTitle: true,
floating: true,
pinned: false,
snap: false,
),
Flexible(
child: GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 5.0,
mainAxisSpacing: 2.0,
childAspectRatio: 0.6),
children: cards,
scrollDirection: Axis.vertical,
physics: BouncingScrollPhysics(),
padding: EdgeInsets.all(10),
];
},
body: Padding(
padding: EdgeInsets.fromLTRB(8, 10, 8, 10),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TextField(
style: TextStyle(fontWeight: FontWeight.bold),
cursorColor: Colors.green,
decoration: InputDecoration(
labelText: "Search Terms..",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(18),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(18),
),
),
controller: _textController,
onSubmitted: (text) {
search();
},
/*onEditingComplete: search*/
),
),
],
FutureBuilder<List<MagicCard>>(
future: NetworkHelper.getData(_textController.text),
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.hasError) {
return Text("Something went wrong");
}
if (snapshot.connectionState == ConnectionState.done) {
return Flexible(
child: GridView(
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 5.0,
mainAxisSpacing: 2.0,
childAspectRatio: 0.6),
children: cards,
scrollDirection: Axis.vertical,
physics: BouncingScrollPhysics(),
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
),
);
}

return Padding(
padding: EdgeInsets.only(top: 50),
child: CircularProgressIndicator(
backgroundColor: Colors.green,
),
);
}),
],
),
),
),
),
Expand All @@ -79,7 +108,58 @@ class _HomeScreenState extends State<HomeScreen> {
}

//#c2c2c2
// Padding(
// padding: EdgeInsets.fromLTRB(8, 10, 8, 0),
// child: Column(
// mainAxisAlignment: MainAxisAlignment.start,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// TextField(
// style: TextStyle(fontWeight: FontWeight.bold),
// cursorColor: Colors.green,
// decoration: InputDecoration(
// labelText: "Search Terms..",
// border: OutlineInputBorder(
// borderRadius: BorderRadius.circular(18),
// ),
// focusedBorder: OutlineInputBorder(
// borderRadius: BorderRadius.circular(18),
// ),
// ),
// controller: _textController,
// onSubmitted: (text) {
// search();
// },
// /*onEditingComplete: search*/
// ),
// FutureBuilder<List<MagicCard>>(
// future: NetworkHelper.getData(_textController.text),
// builder: (context, AsyncSnapshot snapshot) {
// if (snapshot.hasError) {
// return Text("Something went wrong");
// }
// if (snapshot.connectionState == ConnectionState.done) {
// return Flexible(
// child: GridView(
// gridDelegate:
// SliverGridDelegateWithFixedCrossAxisCount(
// crossAxisCount: 2,
// crossAxisSpacing: 5.0,
// mainAxisSpacing: 2.0,
// childAspectRatio: 0.6),
// children: cards,
// scrollDirection: Axis.vertical,
// physics: BouncingScrollPhysics(),
// padding: EdgeInsets.all(10),
// ),
// );
// }

// return Text("loading");
// }),
// ],
// ),
// ),
/*CheckboxListTile(
title: Text("Specific name"),
value: algo,
Expand Down
2 changes: 1 addition & 1 deletion lib/Widgets/MagicCard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MagicCard extends StatelessWidget {
),
CardContainer(
image: NetworkImage(image),
x: 220,
x: 250,
y: 200,
),
],
Expand Down
4 changes: 3 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(),
theme: ThemeData.dark().copyWith(
accentColor: ThemeData.dark().scaffoldBackgroundColor,
primaryColor: ThemeData.dark().scaffoldBackgroundColor),
home: HomeScreen(),
);
}
Expand Down
Loading

0 comments on commit 9211b16

Please sign in to comment.