Flutter_18. DialogAlert, Slider Function, Size, List, Switch
์ง๋ ํฌ์คํ ์ ์ด์ด ์ค๋๋ Function ๋ถ๋ถ์ ๊ตฌํํด๋ณด๋๋ก ํ๊ฒ ๋ค.
์ฝ๋๋ฅผ ๋ค์ ์คํํด๋ณด๊ณ , ํด์ผํ ์ฒดํฌ ํญ๋ชฉ์ ํ์ธํ์ :)
๐ฟ ์ฒดํฌ ํญ๋ชฉโ Detail Page์์๋ง Play ํ๋ฉด์ ์ง์ ๊ฐ๋ฅ, Detail Page์ ์ถ๋ ฅ์ค์ธ ์ด๋ฏธ์ง๋ฅผ Play ํ๋ฉด์ ์ถ๋ ฅํ์ฌ ์ฌ์ฉโ SwitchImageChange : ์ด๋ฏธ์ง ๋ณ๊ฒฝ(์ํ/์ํฐ์คํธ)โ SwitchImageSize : ์ด๋ฏธ์ง ์ฌ์ด์ฆ ๋ณ๊ฒฝ(์๊ฒ/ํฌ๊ฒ) & ์ค์์น Label ๋ณ๊ฒฝ(Size-Max/Size-Min)โ SwitchImageShow : ์ด๋ฏธ์ง ์ถ๋ ฅ ์ฌ๋ถ ์ค์ (๋ ธ์ถ/๋น๋ ธ์ถ), ๋น๋ ธ์ถ์ผ ๊ฒฝ์ฐ ํด๋น ์์ญ Color ํ์, ๋ ธ์ถ์ผ ๊ฒฝ์ฐ์๋ง 1๋ฒ ๊ฐ๋ฅ
4) SliderSize : ์ด๋ฏธ์ง ์ฌ์ด์ฆ๋ฅผ 6๋จ๊ณ(0~5) ์ต์ ์ผ๋ก ์ ํํ์ฌ ์กฐ์
5) SliderRotation : ์ด๋ฏธ์ง ๊ฐ๋๋ฅผ 0~360๋ ๋ด์์ ์์ ๋กญ๊ฒ ์กฐ์
https://api.flutter.dev/flutter/material/Slider-class.html
Slider class - material library - Dart API
A Material Design slider. Used to select from a range of values. The Sliders value is part of the Stateful widget subclass to change the value setState was called. link To create a local project with this code sample, run: flutter create --sample=material.
api.flutter.dev
Figma Case Check, AlertDialog
1) Figma - ๋จ์ ์๋ ๊ธฐ๋ฅ ์ฒดํฌ
โ Switch Function โ
1. _showAlertTurnOff(BuildContext context) : Image ์ค์์น๋ฅผ Off ํ๋ ๊ฒฝ์ฐ, Alert ์ถ๋ ฅํ๊ณ ์ด๋ฏธ์ง ๋น๋ ธ์ถ ์ฒ๋ฆฌ
โ Slider Function โ
2. _playSliderSize() : ์ฌ๋ผ์ด๋ Max๋ฅผ 100(%)์ผ๋ก ๋๊ณ , 5๊ฐ ๊ตฌ๊ฐ์ผ๋ก ๋ถ๋ฆฌํ์ฌ ์ฌ์ด์ฆ ๋ณ๊ฒฝ
3. _playSliderRotation() : ์ฌ๋ผ์ด๋ Max๋ฅผ 360(º)๋ก ๋๊ณ , 0~360๊น์ง ์์ ๋กญ๊ฒ ํ์
2) AlertDialog ํจ์ ์ฝ๋ ๋ถ์ฌ๋ฃ๊ธฐ
2023.05.03 - [๊ฐ๋ฐํ๊ธฐ] - Flutter_08. AlertDialog, Navigator, Routing, PushNamed
// ---Function ImageShow ๋ฌผ์ด๋ณด๊ณ ๋๊ธฐ
_showAlertTurnOff(BuildContext context){
// ํ๋ ์ ๋ง๋ค๊ธฐ
showDialog(
// ๋ฐ๋์ ๋ฒํผ ๋๋ฌ์ผ ์ข
๋ฃ์ํค๊ณ ์ฝ๋ค๋ฉด, barrierDismissible false
barrierDismissible: false,
context: context,
// ๋ค์ด์ด๋ก๊ทธ ๋ด์ฉ ๋ง๋ค๊ธฐ - ctx์ ์ ์ฅ
builder: (BuildContext ctx){
return AlertDialog(
title: const Text(
'Image Show Off',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
content: const Text('์ด๋ฏธ์ง๋ฅผ ๋น๋
ธ์ถํ์๊ฒ ์ต๋๊น?'),
actions: [
// Center์ ๋๊ฑฐ๋, Row ๋๋ Column์ ๋ฉํํ์ฌ ๋ค์ํ๊ฒ ํ์ฉ ๊ฐ๋ฅ!
Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () {
// --- ctx ์ข
๋ฃ ์ํค๊ธฐ
Navigator.of(ctx).pop();
},
child: const Text(
'๋ค',
),
),
TextButton(
onPressed: () {
// --- ctx๋ง ์ข
๋ฃ ์ํค๊ธฐ
Navigator.of(ctx).pop();
},
child: const Text(
'์๋์',
),
),
],
),
),
],
);
}
);
}
3) ํจ์ "_playImageShow()"์ Alert ํจ์ ์ฌ์ฉ
_switchImageShow ์ค์์น ๊ฐ์ด Off์ผ ๊ฒฝ์ฐ, ๊ธฐ์กด ์ด๋ฏธ์ง ๊ฒฝ๋ก ๋ณ๊ฒฝํ๋ ์ฝ๋๋ ์ฐ์ ์ฃผ์ ์ฒ๋ฆฌํ๋ค.
ํด๋น ์ฝ๋๋ Alert ์ถ๋ ฅ ํ, ์ฌ์ฉ์๊ฐ "๋ค" ํด๋ฆญ ์์๋ง ์ ์ฉ๋๋๋ก ์์น๋ฅผ ์ฎ๊ฒจ์ค ์์ ์ด๋ค.
4) AlertDialog ํจ์์ button ์ด๋ฒคํธ ์ถ๊ฐ
AlertDialog
- Yes : setState๋ก ์ด๋ฏธ์ง ๊ฒฝ๋ก๋ฅผ ๋ณ๊ฒฝ
- No : setState๋ก _switchImageShow ๊ฐ ๋ค์ true๋ก ๋ณ๊ฒฝ
5) ์ ์ฅํ๊ณ ํ๋ฉด ํ์ธ
Slider Function, List, Size-Min/Max
1) ์ด๋ฏธ์ง ์ฌ์ด์ฆ : 5๊ตฌ๊ฐ(0~5)์ผ๋ก ์ ํ ์กฐ์
์ด๋ฏธ์ง๋ฅผ ๊ฐ๊ณ ์๋ ์ฌ์ด์ฆ ๋ฐ์ค ํฌ๊ธฐ๊ฐ 350 * 350์์ผ๋ก,
Max350, Min 100๋ก ์ก๊ณ +50์ฉ 0~5๊น์ง์ ๊ตฌ๊ฐ์ ๋ง๋ค ์์ ์ด๋ค.
List์ ์ฌ์ด์ฆ ๊ฐ์ ๋ด๊ณ , index ๋ณ์(int)๋ฅผ ๋ณ๋๋ก ์ ์ธํ์๋ค.
→ [0]100, [1]150, [2]200, [3]250, [4]300, [5]350
class _CardPlayState extends State<CardPlay> {
// Field
late double _SliderValueSize;
late List<double> _sliderValueSizeList;
late int _sliderValueCurrent;
@override
void initState() {
super.initState();
_SliderValueSize = 0;
_sliderValueSizeList = [100, 150, 200, 250, 300, 350];
_sliderValueCurrent = 0;
}
2) Slider ๋ณ์๋ก ์ฝ๋ ๋ณ๊ฒฝ
ํ ์คํธ๋ก ๋ฃ์ print๋ฅผ ํ์ธํด๋ณด์!
- ์ฌ๋ผ์ด๋์ ๋ค์ด์จ value(double) ๊ฐ์ด sliderValueSize(double) ๋ณ์์ ๋ค์ด์จ๋ค.
- sliderValueCurrent(int) ๋ณ์์ ๋ค์ด์จ sliderValueSize(double) ๊ฐ์ toInt()๋ก ๋ณ๊ฒฝํ์ฌ ๋ฃ์ด์ค๋ค.
- sliderValueCurrent(int) ๋ณ์๋ index๋ก List์ ๋ช๋ฒ์งธ ์ฌ์ด์ฆ์ธ์ง ์ฒดํฌํ ๋ ์ฌ์ฉํ ์ ์๋ค.
max: _sliderValueSizeList.length -1,
divisions: _sliderValueSizeList.length -1,
_SliderValueSize = value;
_sliderValueCurrent = _SliderValueSize.toInt();
3) ์ด๋ฏธ์ง ์ฌ์ด์ฆ ์ ์ฉ ํจ์ ๊ตฌํ
- ์ฌ๋ผ์ด๋์ ์๋ ์ฝ๋ ํจ์๋ก ์ด๋
- Index๊ฐ [0]์ผ ๊ฒฝ์ฐ๋, ์ฌ์ด์ฆ ์ค์์น{Off}์ผ ๊ฒฝ์ฐ์ ๋์ผ ์ฌ์ด์ฆ์์ผ๋ก ์ฌ๋ผ์ด๋๊ฐ ์์ง์ฌ 0์ผ๋, ์ค์์น๋ false ์ฒ๋ฆฌ
- Index๊ฐ [5]์ผ ๊ฒฝ์ฐ๋, ์ฌ์ด์ฆ ์ค์์น{On}์ผ ๊ฒฝ์ฐ์ ๋์ผ ์ฌ์ด์ฆ์์ผ๋ก ์ฌ๋ผ์ด๋๊ฐ ์์ง์ฌ MAx์ผ๋, ์ค์์น๋ true ์ฒ๋ฆฌ
// ---Func4. Slider Size
_playSliderSize(){
_sliderValueCurrent = _sliderValueSize.toInt();
_imageWidth = _sliderValueSizeList[_sliderValueCurrent];
_imageHeight = _sliderValueSizeList[_sliderValueCurrent];
// print('slider : $_sliderValueSize');
// print('index : $_sliderValueCurrent');
// print('size : ${_sliderValueSizeList[_sliderValueCurrent]}');
// *** Slider Min Value{100} = Switch Label{Size-Min}
if(_sliderValueCurrent == 0){
_switchImageSizeLabel = 'Size-Min';
_switchImageSize = false;
}
// *** Slider Max Value{350} = Switch Label{Size-Max}
if(_sliderValueCurrent == _sliderValueSizeList.length-1){
_switchImageSizeLabel = 'Size-Max';
_switchImageSize = true;
}
}
4) ์ ์ฅํ๊ณ ๊ธฐ๋ฅ ํ์ธ
5) ์ค์์น์๋ ๋์ผํ๊ฒ ์ฌ๋ผ์ด๋ ๊ฐ ๋ณ๊ฒฝ ์ฝ๋ ์ถ๊ฐ :)
๋ณด๋ค๋ณด๋, ์์ ์ ๋ง๋ ์ฌ์ด์ฆ ํจ์์ ์กฐ๊ฑด๋ณ if ๋ฌธ์ ์ฌ์ด์ฆ ๊ฐ์ด ๋ฐ๋๋ก ๋ค์ด๊ฐ ์์๋ค ;;
ํจ์ ์์ ํ๋ฉด์ ๊ฐ์ด ์์ :) ์ฌ๋ผ์ด๋์ ์ค์์น ์ด๊ธฐ๊ฐ๋ ๋ณ๊ฒฝํด์ฃผ์๋ค.
_switchImageSizeLabel = 'Size-Max';
_switchImageSize = true;
_sliderValueSize = 5;
-------------------------------------------------
// ---Func3. ์ด๋ฏธ์ง ์ฌ์ด์ฆ์ switch ์ด๋ฆ ๋ณ๊ฒฝ(Min/Max)
_playImageSize(){
if(_switchImageSize){
_imageWidth = 350;
_imageHeight = 350;
_switchImageSizeLabel = 'Size-Max';
// *** ์ค์์น๊ฐ ON์ด๋ฉด, ์ฌ๋ผ์ด๋๋ ๋ง์ง๋ง ๊ฐ์ผ๋ก ๊ฐ์ด ๋ณ๊ฒฝ
_sliderValueSize = 5;
}else{
_imageWidth = 100;
_imageHeight = 100;
_switchImageSizeLabel = 'Size-Min';
// *** ์ค์์น๊ฐ OFF๋ฉด, ์ฌ๋ผ์ด๋๋ 0 ๊ฐ์ผ๋ก ๊ฐ์ด ๋ณ๊ฒฝ
_sliderValueSize = 0;
}
}
6) ์ ์ฅํ๊ณ ๊ธฐ๋ฅ ํ์ธ
Slider Function, 360, Rotation
1) Slider division : 360์ผ๋ก ๋ณ๊ฒฝ
0~360๊น์ง 1 ๋จ์๋ก ์ ํ์ด ๊ฐ๋ฅํ๋๋ก ๊ตฌ๊ฐ ๊ฐ์๋ฅผ ๋ณ๊ฒฝํด์ค๋ค.
Slider(
activeColor: const Color.fromARGB(255, 134, 98, 243),
value: _SliderValueRotation,
max: 360,
divisions: 360,
label: _SliderValueRotation.round().toString(),
onChanged: (value) {
// --- Slider Event
setState(() {
_SliderValueRotation = value;
});
},
),
2) Image์ RotationTransition
RotationTransition(
turns: AlwaysStoppedAnimation(_SliderValueRotation / 360),
SizedBox(
width: 350,
height: 350,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RotationTransition(
turns: AlwaysStoppedAnimation(_SliderValueRotation / 360),
child: Image.asset(
_imagePath,
width: _imageWidth,
height: _imageHeight,
),
),
],
),
),
3) ์ ์ฅํ๊ณ ๊ธฐ๋ฅ ํ์ธ
๐ฟ ์ฒดํฌ ํญ๋ชฉโ Detail Page์์๋ง Play ํ๋ฉด์ ์ง์ ๊ฐ๋ฅ, Detail Page์ ์ถ๋ ฅ์ค์ธ ์ด๋ฏธ์ง๋ฅผ Play ํ๋ฉด์ ์ถ๋ ฅํ์ฌ ์ฌ์ฉโ SwitchImageChange : ์ด๋ฏธ์ง ๋ณ๊ฒฝ(์ํ/์ํฐ์คํธ)โ SwitchImageSize : ์ด๋ฏธ์ง ์ฌ์ด์ฆ ๋ณ๊ฒฝ(์๊ฒ/ํฌ๊ฒ) & ์ค์์น Label ๋ณ๊ฒฝ(Size-Max/Size-Min)โ SwitchImageShow : ์ด๋ฏธ์ง ์ถ๋ ฅ ์ฌ๋ถ ์ค์ (๋ ธ์ถ/๋น๋ ธ์ถ), ๋น๋ ธ์ถ์ผ ๊ฒฝ์ฐ ํด๋น ์์ญ Color ํ์, ๋ ธ์ถ์ผ ๊ฒฝ์ฐ์๋ง 1๋ฒ ๊ฐ๋ฅโ SliderSize : ์ด๋ฏธ์ง ์ฌ์ด์ฆ๋ฅผ 6๋จ๊ณ(0~5) ์ต์ ์ผ๋ก ์ ํํ์ฌ ์กฐ์ โ SliderRotation : ์ด๋ฏธ์ง ๊ฐ๋๋ฅผ 0~360๋ ๋ด์์ ์์ ๋กญ๊ฒ ์กฐ์
https://api.flutter.dev/flutter/widgets/RotationTransition-class.html
RotationTransition class - widgets library - Dart API
Animates the rotation of a widget. Here's an illustration of the RotationTransition widget, with it's turns animated by a CurvedAnimation set to Curves.elasticOut: link To create a local project with this code sample, run: flutter create --sample=widgets.R
api.flutter.dev
https://api.flutter.dev/flutter/animation/AlwaysStoppedAnimation-class.html
AlwaysStoppedAnimation class - animation library - Dart API
An animation that is always stopped at a given value. The status is always AnimationStatus.forward. Inheritance Constructors AlwaysStoppedAnimation(T value) Creates an AlwaysStoppedAnimation with the given value. const Properties hashCode → int The hash
api.flutter.dev