Skip to content

Commit f4c5b3c

Browse files
committed
Refactor
1 parent dc10375 commit f4c5b3c

File tree

9 files changed

+284
-123
lines changed

9 files changed

+284
-123
lines changed

lib/main.dart

Lines changed: 7 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,11 @@
11
import 'package:flutter/material.dart';
2+
import 'screens/main_page.dart';
23

34
void main() {
4-
runApp(MyApp());
5-
}
6-
7-
class MyApp extends StatelessWidget {
8-
// This widget is the root of your application.
9-
@override
10-
Widget build(BuildContext context) {
11-
return MaterialApp(
12-
title: 'Flutter Demo',
13-
theme: ThemeData(
14-
// This is the theme of your application.
15-
//
16-
// Try running your application with "flutter run". You'll see the
17-
// application has a blue toolbar. Then, without quitting the app, try
18-
// changing the primarySwatch below to Colors.green and then invoke
19-
// "hot reload" (press "r" in the console where you ran "flutter run",
20-
// or simply save your changes to "hot reload" in a Flutter IDE).
21-
// Notice that the counter didn't reset back to zero; the application
22-
// is not restarted.
23-
primarySwatch: Colors.blue,
24-
// This makes the visual density adapt to the platform that you run
25-
// the app on. For desktop platforms, the controls will be smaller and
26-
// closer together (more dense) than on mobile platforms.
27-
visualDensity: VisualDensity.adaptivePlatformDensity,
28-
),
29-
home: MyHomePage(title: 'Flutter Demo Home Page'),
30-
);
31-
}
32-
}
33-
34-
class MyHomePage extends StatefulWidget {
35-
MyHomePage({Key key, this.title}) : super(key: key);
36-
37-
// This widget is the home page of your application. It is stateful, meaning
38-
// that it has a State object (defined below) that contains fields that affect
39-
// how it looks.
40-
41-
// This class is the configuration for the state. It holds the values (in this
42-
// case the title) provided by the parent (in this case the App widget) and
43-
// used by the build method of the State. Fields in a Widget subclass are
44-
// always marked "final".
45-
46-
final String title;
47-
48-
@override
49-
_MyHomePageState createState() => _MyHomePageState();
50-
}
51-
52-
class _MyHomePageState extends State<MyHomePage> {
53-
int _counter = 0;
54-
55-
void _incrementCounter() {
56-
setState(() {
57-
// This call to setState tells the Flutter framework that something has
58-
// changed in this State, which causes it to rerun the build method below
59-
// so that the display can reflect the updated values. If we changed
60-
// _counter without calling setState(), then the build method would not be
61-
// called again, and so nothing would appear to happen.
62-
_counter++;
63-
});
64-
}
65-
66-
@override
67-
Widget build(BuildContext context) {
68-
// This method is rerun every time setState is called, for instance as done
69-
// by the _incrementCounter method above.
70-
//
71-
// The Flutter framework has been optimized to make rerunning build methods
72-
// fast, so that you can just rebuild anything that needs updating rather
73-
// than having to individually change instances of widgets.
74-
return Scaffold(
75-
appBar: AppBar(
76-
// Here we take the value from the MyHomePage object that was created by
77-
// the App.build method, and use it to set our appbar title.
78-
title: Text(widget.title),
79-
),
80-
body: Center(
81-
// Center is a layout widget. It takes a single child and positions it
82-
// in the middle of the parent.
83-
child: Column(
84-
// Column is also a layout widget. It takes a list of children and
85-
// arranges them vertically. By default, it sizes itself to fit its
86-
// children horizontally, and tries to be as tall as its parent.
87-
//
88-
// Invoke "debug painting" (press "p" in the console, choose the
89-
// "Toggle Debug Paint" action from the Flutter Inspector in Android
90-
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
91-
// to see the wireframe for each widget.
92-
//
93-
// Column has various properties to control how it sizes itself and
94-
// how it positions its children. Here we use mainAxisAlignment to
95-
// center the children vertically; the main axis here is the vertical
96-
// axis because Columns are vertical (the cross axis would be
97-
// horizontal).
98-
mainAxisAlignment: MainAxisAlignment.center,
99-
children: <Widget>[
100-
Text(
101-
'You have pushed the button this many times:',
102-
),
103-
Text(
104-
'$_counter',
105-
style: Theme.of(context).textTheme.headline4,
106-
),
107-
],
108-
),
109-
),
110-
floatingActionButton: FloatingActionButton(
111-
onPressed: _incrementCounter,
112-
tooltip: 'Increment',
113-
child: Icon(Icons.add),
114-
), // This trailing comma makes auto-formatting nicer for build methods.
115-
);
116-
}
5+
runApp(
6+
MaterialApp(
7+
title: 'Arena',
8+
home: MainPage(),
9+
),
10+
);
11711
}

lib/models/Game.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import 'package:flutter/material.dart';
2+
3+
class Game {
4+
final String homeTeam;
5+
final String oppTeam;
6+
final Icon homeIcon;
7+
final Icon oppIcon;
8+
final int homeScore;
9+
final int oppScore;
10+
Game({
11+
@required this.homeTeam,
12+
@required this.oppTeam,
13+
this.homeIcon,
14+
this.oppIcon,
15+
@required this.homeScore,
16+
@required this.oppScore,
17+
});
18+
}

lib/screens/main_page.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:arena/views/partidos_view/partidos.dart';
3+
import 'package:arena/widgets/styled_card.dart';
4+
import 'package:arena/widgets/styled_app_bar.dart';
5+
6+
class MainPage extends StatelessWidget {
7+
@override
8+
Widget build(BuildContext context) {
9+
return Scaffold(
10+
backgroundColor: Colors.grey.shade200,
11+
appBar: StyledAppBar(),
12+
body: Column(
13+
children: [
14+
SizedBox(height: 8),
15+
Container(
16+
color: Colors.red,
17+
height: 60,
18+
),
19+
StyledCard(
20+
child: Partidos(),
21+
)
22+
],
23+
),
24+
);
25+
}
26+
}

lib/views/partidos_view/partido.dart

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import 'package:flutter/material.dart';
2+
3+
class Partido extends StatelessWidget {
4+
final bool displayNotification = false;
5+
6+
Icon get teamIcon {
7+
return Icon(Icons.tablet_mac);
8+
}
9+
10+
Widget get score {
11+
return Container(
12+
padding: EdgeInsets.all(4),
13+
color: Colors.grey[300],
14+
child: Text(
15+
'2',
16+
style: TextStyle(fontWeight: FontWeight.bold),
17+
),
18+
);
19+
}
20+
21+
Icon get ringer {
22+
return Icon(
23+
Icons.notifications_none,
24+
size: 24,
25+
);
26+
}
27+
28+
@override
29+
Widget build(BuildContext context) {
30+
return Column(
31+
children: [
32+
Row(
33+
children: [
34+
teamIcon,
35+
SizedBox(width: 8),
36+
Text('Barcelona'),
37+
Expanded(child: Container()),
38+
score,
39+
SizedBox(width: 8),
40+
Text('Direct TV'),
41+
Expanded(child: Container()),
42+
ringer
43+
],
44+
),
45+
SizedBox(height: 8),
46+
Row(
47+
children: [
48+
teamIcon,
49+
SizedBox(width: 8),
50+
Text('Barcelona'),
51+
Expanded(child: Container()),
52+
score,
53+
SizedBox(width: 8),
54+
Text('Direct TV'),
55+
Expanded(child: Container()),
56+
SizedBox(width: ringer.size),
57+
],
58+
),
59+
],
60+
);
61+
}
62+
}

lib/views/partidos_view/partidos.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'package:flutter/material.dart';
2+
import './partido.dart';
3+
4+
class Partidos extends StatelessWidget {
5+
@override
6+
Widget build(BuildContext context) {
7+
return Container(
8+
width: double.infinity,
9+
child: Column(
10+
crossAxisAlignment: CrossAxisAlignment.start,
11+
children: [
12+
Text(
13+
"UEFA Champions League",
14+
style: TextStyle(
15+
color: Colors.grey,
16+
fontSize: 14,
17+
fontWeight: FontWeight.w500,
18+
),
19+
),
20+
ListView.separated(
21+
separatorBuilder: (context, index) => Divider(),
22+
itemBuilder: (context, index) {
23+
return Partido();
24+
// print('hello');
25+
// return Container(
26+
// child: Text('32'),
27+
// height: 40,
28+
// // width: 20,
29+
// );
30+
},
31+
itemCount: 3,
32+
shrinkWrap: true,
33+
)
34+
],
35+
),
36+
);
37+
}
38+
}

lib/widgets/circle_button.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import 'package:flutter/material.dart';
2+
3+
class CircleButton extends StatelessWidget {
4+
const CircleButton({
5+
Key key,
6+
}) : super(key: key);
7+
8+
@override
9+
Widget build(BuildContext context) {
10+
return GestureDetector(
11+
onTap: () {},
12+
child: Container(
13+
decoration: BoxDecoration(
14+
shape: BoxShape.circle,
15+
color: Colors.grey.shade300,
16+
),
17+
padding: EdgeInsets.all(8),
18+
child: Container(
19+
child: Icon(
20+
Icons.search,
21+
color: Colors.grey.shade500,
22+
),
23+
),
24+
),
25+
);
26+
}
27+
}

lib/widgets/styled_app_bar.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import 'package:flutter/material.dart';
2+
import 'circle_button.dart';
3+
4+
class StyledAppBar extends StatelessWidget implements PreferredSizeWidget {
5+
StyledAppBar({Key key}) : super(key: key);
6+
7+
@override
8+
Size get preferredSize => new Size.fromHeight(_appBar.preferredSize.height);
9+
10+
@override
11+
Widget build(BuildContext context) {
12+
return _appBar;
13+
}
14+
15+
final _appBar = AppBar(
16+
backgroundColor: Colors.white,
17+
elevation: 1,
18+
title: Row(
19+
children: [
20+
Text(
21+
"ARENA",
22+
style: TextStyle(
23+
color: Colors.black,
24+
),
25+
),
26+
Expanded(child: Container()),
27+
Text(
28+
'Live',
29+
style: TextStyle(
30+
fontWeight: FontWeight.bold,
31+
color: Colors.black,
32+
),
33+
),
34+
Switch.adaptive(value: false, onChanged: (_) => {}),
35+
CircleButton()
36+
],
37+
),
38+
);
39+
}

lib/widgets/styled_card.dart

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import 'package:flutter/material.dart';
2+
3+
class StyledCard extends StatelessWidget {
4+
final Widget child;
5+
6+
const StyledCard({
7+
this.child,
8+
Key key,
9+
}) : super(key: key);
10+
11+
Widget _getHeader({String title}) {
12+
return Column(
13+
children: [
14+
Row(
15+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
16+
children: [
17+
Text(
18+
title,
19+
style: TextStyle(
20+
fontWeight: FontWeight.bold,
21+
),
22+
),
23+
Text(
24+
'Ver Todos',
25+
style: TextStyle(color: Colors.grey),
26+
)
27+
],
28+
),
29+
Container(
30+
color: Colors.grey.withOpacity(0.2),
31+
height: 1,
32+
margin: EdgeInsets.symmetric(vertical: 8),
33+
),
34+
child
35+
],
36+
);
37+
}
38+
39+
@override
40+
Widget build(BuildContext context) {
41+
return Card(
42+
elevation: 0.5,
43+
margin: EdgeInsets.all(8),
44+
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
45+
child: Container(
46+
// height: 200,
47+
width: double.infinity,
48+
padding: EdgeInsets.all(8),
49+
child: Column(
50+
children: [
51+
_getHeader(title: 'PARTIDOS'),
52+
],
53+
),
54+
),
55+
);
56+
}
57+
}

0 commit comments

Comments
 (0)