Skip to content

Commit e5f91b0

Browse files
author
Pedro Massango
committed
Code improvements in the world_clock challenge
1 parent dfd1985 commit e5f91b0

File tree

3 files changed

+103
-9
lines changed

3 files changed

+103
-9
lines changed

lib/bubbles_rain.dart

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import 'dart:async';
2+
import 'dart:math';
3+
4+
import 'package:flutter/material.dart';
5+
6+
class MyApp extends StatelessWidget {
7+
@override
8+
Widget build(BuildContext context) {
9+
return MaterialApp(
10+
title: 'Bubble Rain',
11+
theme: ThemeData(
12+
primarySwatch: Colors.blue
13+
),
14+
home: HomePage(),
15+
);
16+
}
17+
}
18+
19+
class HomePage extends StatefulWidget {
20+
21+
@override
22+
_HomePageState createState() => _HomePageState();
23+
}
24+
25+
class _HomePageState extends State<HomePage> {
26+
27+
double maxScreenWith;
28+
double maxScreenHeight;
29+
30+
@override
31+
Widget build(BuildContext context) {
32+
maxScreenWith = MediaQuery.of(context).size.width;
33+
maxScreenHeight = MediaQuery.of(context).size.height;
34+
final size = Size(maxScreenWith, maxScreenHeight);
35+
36+
return Scaffold(
37+
body: Container(
38+
height: double.infinity,
39+
width: double.infinity,
40+
child: GameField(size),
41+
),
42+
);
43+
}
44+
}
45+
46+
class Circle extends StatelessWidget {
47+
final Color color;
48+
final double _size = 50;
49+
50+
const Circle({Key key, this.color = Colors.green})
51+
: assert(color != null),
52+
super(key: key);
53+
54+
@override
55+
Widget build(BuildContext context) {
56+
return Container(
57+
width: _size,
58+
height: _size,
59+
decoration: BoxDecoration(
60+
color: color,
61+
shape: BoxShape.circle
62+
),
63+
);
64+
}
65+
}
66+
class CircleController {
67+
}
68+
69+
class GameField extends StatefulWidget {
70+
final Size size;
71+
GameField(this.size);
72+
73+
@override
74+
_GameFieldState createState() => _GameFieldState();
75+
}
76+
77+
class _GameFieldState extends State<GameField> {
78+
79+
Size get size => widget.size;
80+
81+
Size _randomPosition(Size size) {
82+
final x = Random().nextInt(size.width~/2);
83+
final y = Random().nextInt(size.height~/2);
84+
return Size(x.toDouble(), y.toDouble());
85+
}
86+
87+
addItem(){
88+
89+
}
90+
91+
92+
@override
93+
Widget build(BuildContext context) {
94+
return Stack(
95+
children: <Widget>[
96+
97+
Center(child: Circle(color: Colors.orange,),)
98+
],
99+
);
100+
}
101+
}

lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import 'package:flutter/material.dart';
2-
import 'package:flutter_challenges/transformation_example.dart';
2+
import 'package:flutter_challenges/number_picker.dart';
33

44
void main() => runApp( MyApp());

lib/world_clock.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class HomePage extends StatefulWidget {
1010
_HomePageState createState() => _HomePageState();
1111
}
1212

13-
//final Color bgColor = Color(0xFF142550);
1413
final Color bgColor = Colors.white;
1514

1615
class _HomePageState extends State<HomePage> {
@@ -47,7 +46,6 @@ class _HomePageState extends State<HomePage> {
4746
hour = DateTime.now().second.toDouble();
4847
stopwatch.reset();
4948
}
50-
5149
setState(() {});
5250
});
5351

@@ -100,9 +98,8 @@ class _HomePageState extends State<HomePage> {
10098

10199
@override
102100
void dispose() {
103-
super.dispose();
104-
105101
stopwatch?.stop();
102+
super.dispose();
106103
}
107104

108105
@override
@@ -251,7 +248,6 @@ class _HomePageState extends State<HomePage> {
251248

252249
enum LineType{ hour, minute, second }
253250

254-
255251
class LinesPainter extends CustomPainter{
256252

257253
final Paint linePainter;
@@ -274,13 +270,11 @@ class LinesPainter extends CustomPainter{
274270
final radius = size.width/2;
275271

276272
List.generate(maxLines, (i){
277-
278273
canvas.drawLine(
279274
Offset(0, radius),
280275
Offset(0, radius - 8),
281276
linePainter
282277
);
283-
284278
canvas.rotate(2 * pi / maxLines);
285279
});
286280

@@ -315,7 +309,6 @@ class TimeLinesPainter extends CustomPainter{
315309

316310
@override
317311
void paint(Canvas canvas, Size size) {
318-
319312
final radius = size.width / 2;
320313

321314
canvas.translate(radius, radius);

0 commit comments

Comments
 (0)