Skip to content

Commit

Permalink
added stars to night city sky
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcusjnr committed May 8, 2022
1 parent 8baf946 commit d93ef0d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
66 changes: 65 additions & 1 deletion lib/ui/night_city/night_city.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,90 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_weather_bg_null_safety/bg/weather_bg.dart';
import 'package:flutter_weather_bg_null_safety/utils/weather_type.dart';
import 'package:flutterpaintprojects/ui/night_city/night_city_painter.dart';
import 'package:flutterpaintprojects/ui/night_city/star.dart';

class NightCity extends StatelessWidget {
class NightCity extends StatefulWidget {
const NightCity({Key? key}) : super(key: key);

@override
State<NightCity> createState() => _NightCityState();
}


class _NightCityState extends State<NightCity> {
List<Star> randomStar = [];

@override
void initState() {
// TODO: implement initState
super.initState();


}
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
buildStartList(size);

return Scaffold(
body: Container(
color: const Color(0xFF404E7F).withOpacity(.9),
child: Stack(
children: [
for ( int i = 0; i < randomStar.length; i++ ) buildStar(i),

CustomPaint(
size: Size(
MediaQuery.of(context).size.width,(
MediaQuery.of(context).size.width).toDouble()),
painter: NightCityPainter(),
),



],
),
),
);
}

Widget starWidget(double left, double top, double extraSize) {
return Positioned(
child: Container(
child: Icon(
Icons.star,
color: Colors.white,
size: 2 + extraSize,
),
alignment: FractionalOffset.center,
width: 10.0,
height: 10.0,
),
left: left,
top: top,
);
}

buildStartList(Size size){
randomStar.clear();
for (int i = 0; i < 100; i++) {

randomStar.add(Star(
left: Random().nextDouble() * size.width,
top: Random().nextDouble() * size.height,
extraSize: Random().nextDouble() * 2,));
}
}

Widget buildStar(int i){

return starWidget(
randomStar[i].left,
randomStar[i].top,
randomStar[i].extraSize,
);
}
}
2 changes: 1 addition & 1 deletion lib/ui/night_city/night_city_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NightCityPainter extends CustomPainter{
path0.lineTo(0,0);
path0.close();

canvas.drawPath(path0, paint0);
// canvas.drawPath(path0, paint0);


Paint paint1 = Paint()
Expand Down
11 changes: 11 additions & 0 deletions lib/ui/night_city/star.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter/material.dart';

class Star {
double left;
double top;
double extraSize;

Star({required this.left,
required this.top,
required this.extraSize,});
}

0 comments on commit d93ef0d

Please sign in to comment.