Created
February 2, 2024 10:31
-
-
Save hardy716/bcf61062182196c4b25f505766991c16 to your computer and use it in GitHub Desktop.
플러터챌린지 10일차 기본문제 - 신현호
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp( | |
MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: NetflixSelectProfileScreen(), | |
), | |
); | |
} | |
class NetflixSelectProfileScreen extends StatelessWidget { | |
final List<Map<String, dynamic>> profiles = [ | |
{'name': 'Honlee', 'color': Colors.blue}, | |
{'name': 'Kilee', 'color': Colors.yellow}, | |
{'name': 'Flutter Boot', 'color': Colors.red}, | |
]; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text( | |
"Flutter Boot", | |
style: Theme.of(context).textTheme.titleLarge?.copyWith( | |
color: Colors.red, | |
fontWeight: FontWeight.w900, | |
), | |
), | |
backgroundColor: Colors.black, | |
), | |
backgroundColor: Colors.black, | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Text( | |
"Select a profile to start the Flutter Boot.", | |
style: Theme.of(context).textTheme.bodyLarge?.copyWith( | |
color: Colors.white, | |
), | |
), | |
const SizedBox(height: 25), | |
Padding( | |
padding: EdgeInsets.symmetric( | |
horizontal: MediaQuery.of(context).size.width / 3 | |
), | |
child: Wrap( | |
spacing: 25.0, | |
runSpacing: 30.0, | |
children: profiles.map((profile) { | |
return _ProfileBox( | |
name: profile['name'], | |
color: profile['color'], | |
); | |
}).toList() | |
..add( | |
const _ProfileBox(isLast: true), | |
), | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} | |
class _ProfileBox extends StatelessWidget { | |
final String name; | |
final Color color; | |
final bool isLast; | |
const _ProfileBox({ | |
this.name = 'Add profile', | |
this.color = Colors.transparent, | |
this.isLast = false, | |
}); | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
Container( | |
width: 100, | |
height: 100, | |
margin: const EdgeInsets.only(bottom: 5), | |
decoration: BoxDecoration( | |
gradient: LinearGradient( | |
begin: Alignment.topCenter, | |
end: Alignment.bottomCenter, | |
colors: [ | |
HSLColor.fromColor(color).withLightness(0.45).toColor(), | |
HSLColor.fromColor(color).withLightness(0.7).toColor(), | |
], | |
), | |
borderRadius: BorderRadius.circular(4), | |
border: Border.all( | |
color: Colors.grey.shade500, | |
width: 0.7, | |
), | |
), | |
child: !isLast | |
? CustomPaint( | |
size: const Size(100, 100), | |
painter: _SmilePainter(), | |
) | |
: const Icon( | |
Icons.add, | |
size: 50, | |
color: Colors.white, | |
) | |
), | |
Text( | |
name, | |
style: Theme.of(context).textTheme.bodySmall?.copyWith( | |
color: Colors.grey, | |
fontWeight: FontWeight.w600, | |
), | |
), | |
], | |
); | |
} | |
} | |
class _SmilePainter extends CustomPainter { | |
@override | |
void paint(Canvas canvas, Size size) { | |
final eyePaint = Paint() | |
..color = Colors.white | |
..style = PaintingStyle.fill; | |
final smilePaint = Paint() | |
..color = Colors.white | |
..style = PaintingStyle.stroke | |
..strokeWidth = 5 | |
..strokeCap = StrokeCap.round; | |
const eyeRadius = 6.0; | |
final leftEyeCenter = Offset(size.width * 0.2, size.height / 3); | |
final rightEyeCenter = Offset(size.width * 0.8, size.height / 3); | |
canvas.drawCircle(leftEyeCenter, eyeRadius, eyePaint); | |
canvas.drawCircle(rightEyeCenter, eyeRadius, eyePaint); | |
final smileRect = Rect.fromCenter( | |
center: Offset(size.width / 2 + (size.width * 0.15), size.height * 0.55), | |
width: size.width * 0.45, | |
height: size.height * 0.2, | |
); | |
final smile = Path() | |
..arcTo(smileRect, pi / 8, pi * 3 / 4, false); | |
canvas.drawPath(smile, smilePaint); | |
} | |
@override | |
bool shouldRepaint(covariant CustomPainter oldDelegate) { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment