Last active
March 13, 2021 11:49
-
-
Save mxm5/90819c434a1a513e256532ac55e4dc3e to your computer and use it in GitHub Desktop.
some random code
This file contains hidden or 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 'package:flutter/material.dart'; | |
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter_svg/flutter_svg.dart'; | |
import 'package:flutter/services.dart'; | |
import 'package:rive/rive.dart'; | |
import 'package:flutter_neumorphic/flutter_neumorphic.dart'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
import 'package:smarthome_flutter/cubits/cubit_class.dart'; | |
import 'package:smarthome_flutter/cubits/states.dart'; | |
import 'package:smarthome_flutter/cubits/state_event_click.dart'; | |
import 'package:smarthome_flutter/cubits/cubit_click.dart'; | |
class Roshanaiee extends StatefulWidget { | |
@override | |
_RoshanaieeState createState() => _RoshanaieeState(); | |
} | |
class _RoshanaieeState extends State<Roshanaiee> { | |
double slidervalue = 0; | |
Artboard _riveArtboard; | |
RiveAnimationController _controller; | |
int selectedIndex; | |
String id_selected; | |
void initState() { | |
super.initState(); | |
context.read<Cubit_class>().getline(); | |
context.read<Cubit_click>().init(); | |
rootBundle.load('assets/lumpanim.riv').then( | |
(data) async { | |
final file = RiveFile(); | |
if (file.import(data)) { | |
final artboard = file.mainArtboard; | |
artboard.addController(_controller = SimpleAnimation('0.0')); | |
setState(() { | |
_riveArtboard = artboard; | |
}); | |
} | |
}, | |
); | |
} | |
final snackBar = SnackBar( | |
content: Text( | |
'!لطفا مکان را انتخاب کنید', | |
textAlign: TextAlign.right, | |
)); | |
@override | |
Widget build(BuildContext context) { | |
final appbar = AppBar( | |
title: Text( | |
'روشنایی', | |
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), | |
), | |
centerTitle: true, | |
leading: new IconButton( | |
icon: new Icon(Icons.arrow_back, color: Colors.grey), | |
onPressed: () => Navigator.of(context).pop(), | |
), | |
backgroundColor: Color(0xff222831), | |
); | |
double screen_width = MediaQuery.of(context).size.width; | |
double screen_height = MediaQuery.of(context).size.height - | |
appbar.preferredSize.height - | |
MediaQuery.of(context).padding.top; | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
backgroundColor: Color(0xff222831), | |
appBar: appbar, | |
body: | |
BlocConsumer<Cubit_click, State_Event_click>( | |
buildWhen: (previous, current) { | |
return true; | |
}, | |
listenWhen: (previous, current) { | |
if (current is Slider_value && previous is Slider_value) { | |
if (current.value == previous.value) { | |
return false; | |
} else { | |
return true; | |
} | |
} else { | |
return false; | |
} | |
}, | |
listener: (context, state) { | |
if (state is Slider_value) { | |
slidervalue = state.value; | |
} | |
}, | |
builder: (context, state) { | |
return Container( | |
width: screen_width, | |
height: screen_height, | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.center, | |
// mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
SizedBox( | |
height: screen_height * 0.05, | |
), | |
Container( | |
width: screen_width * 0.85, | |
height: screen_height * 0.75, | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.circular(10), | |
color: Color(0xff393E46), | |
), | |
child: Column( | |
children: [ | |
SizedBox( | |
height: screen_height * 0.01, | |
), | |
Align( | |
alignment: Alignment.topLeft, | |
child: Icon( | |
Icons.more_vert, | |
color: Colors.grey, | |
size: screen_width * 0.07, | |
), | |
), | |
SizedBox( | |
height: screen_height * 0.01, | |
), | |
Row( | |
children: [ | |
Expanded( | |
flex: 1, | |
child: Container( | |
// height: 100, | |
// color: Colors.red, | |
)), | |
Expanded( | |
flex: 3, | |
child: Container( | |
height: screen_height * 0.5, | |
// color: Colors.blue, | |
child: Stack( | |
children: [ | |
Center( | |
child: _riveArtboard == null | |
? const SizedBox() | |
: Rive( | |
artboard: _riveArtboard, | |
fit: BoxFit.cover, | |
), | |
), | |
Align( | |
alignment: | |
Alignment.topCenter, | |
child: Container( | |
// color: Colors.red, | |
height: | |
screen_height * 0.2, | |
width: screen_width * 0.4, | |
child: Column( | |
children: [ | |
SizedBox( | |
height: | |
screen_height * | |
0.1, | |
), | |
Row( | |
mainAxisAlignment: | |
MainAxisAlignment | |
.center, | |
crossAxisAlignment: | |
CrossAxisAlignment | |
.center, | |
children: [ | |
Text( | |
slidervalue | |
.toStringAsFixed( | |
0), | |
style: TextStyle( | |
fontSize: | |
screen_width * | |
0.08, | |
fontFamily: | |
'DigitalNumbers', | |
color: Colors | |
.white70), | |
), | |
Text( | |
'%', | |
style: TextStyle( | |
fontSize: | |
screen_width * | |
0.05, | |
color: Colors | |
.white70), | |
), | |
], | |
), | |
], | |
))) | |
], | |
))), | |
Expanded( | |
flex: 1, | |
child: Column( | |
children: [ | |
Container( | |
height: screen_height * 0.35, | |
child: RotatedBox( | |
quarterTurns: -1, | |
child: Slider( | |
value: slidervalue, | |
divisions: 10, | |
min: 0, | |
max: 100, | |
inactiveColor: | |
Colors.white70, | |
activeColor: | |
Colors.grey[600], | |
label: '${slidervalue}%', | |
onChanged: (event) { | |
// slidervalue = event; | |
context | |
.read<Cubit_click>() | |
.changeslider(event, | |
id_selected); | |
// print(state.value.toString()); | |
rootBundle | |
.load( | |
'assets/lumpanim.riv') | |
.then( | |
(data) async { | |
final file = | |
RiveFile(); | |
if (file | |
.import(data)) { | |
final artboard = file | |
.mainArtboard; | |
artboard.addController( | |
_controller = | |
SimpleAnimation( | |
slidervalue | |
.toString())); | |
_riveArtboard = | |
artboard; | |
} | |
}, | |
); | |
// Cubit_click().changeslider(event, id_selected); | |
}))), | |
SizedBox( | |
height: screen_height * 0.05, | |
) | |
], | |
)), | |
], | |
), | |
Row( | |
mainAxisAlignment: | |
MainAxisAlignment.spaceBetween, | |
children: [ | |
SizedBox( | |
width: screen_width * 0.02, | |
), | |
Neumorphic( | |
style: NeumorphicStyle( | |
shape: NeumorphicShape.flat, | |
boxShape: NeumorphicBoxShape.roundRect( | |
BorderRadius.circular(8)), | |
depth: 8, | |
// lightSource: LightSource.top, | |
border: NeumorphicBorder( | |
width: 1, | |
), | |
shadowDarkColor: Colors.black, | |
shadowLightColor: Colors.white, | |
color: Colors.black), | |
child: Container( | |
width: screen_width * 0.125, | |
height: screen_height * 0.12, | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.circular(5), | |
color: Color(0xff222831), | |
), | |
child: InkWell( | |
child: Icon( | |
Icons.access_time, | |
size: screen_width * 0.11, | |
color: Colors.white70, | |
), | |
onTap: () { | |
id_selected == null | |
? ScaffoldMessenger.of(context) | |
.showSnackBar(snackBar) | |
: context | |
.read<Cubit_click>() | |
.event_click( | |
'time', id_selected); | |
}, | |
), | |
), | |
), | |
InkWell( | |
child: Stack( | |
children: [ | |
Neumorphic( | |
style: NeumorphicStyle( | |
shape: NeumorphicShape.flat, | |
boxShape: | |
NeumorphicBoxShape.roundRect( | |
BorderRadius.circular(8)), | |
depth: 12, | |
// lightSource: LightSource.top, | |
border: NeumorphicBorder( | |
width: 1, | |
), | |
shadowDarkColor: Colors.black, | |
shadowLightColor: slidervalue == 0 | |
? Colors.white | |
: Colors.grey[700], | |
color: Colors.black), | |
child: Container( | |
width: screen_width * 0.125, | |
height: screen_height * 0.12, | |
decoration: BoxDecoration( | |
borderRadius: | |
BorderRadius.circular(5), | |
color: Color(0xff222831), | |
), | |
child: Column( | |
mainAxisAlignment: | |
MainAxisAlignment.center, | |
crossAxisAlignment: | |
CrossAxisAlignment.center, | |
children: [ | |
SvgPicture.asset( | |
"assets/images/power2_dark.svg", | |
width: screen_width * 0.07, | |
color: Colors.white70), | |
SizedBox( | |
height: screen_height * 0.01, | |
), | |
Text('خاموش', | |
style: TextStyle( | |
color: Colors.white70, | |
fontWeight: | |
FontWeight.bold), | |
textAlign: TextAlign.center) | |
], | |
), | |
), | |
), | |
], | |
), | |
onTap: () { | |
id_selected == null | |
? ScaffoldMessenger.of(context) | |
.showSnackBar(snackBar) | |
: context | |
.read<Cubit_click>() | |
.event_click('off', id_selected); | |
}, | |
), | |
InkWell( | |
child: Stack( | |
alignment: Alignment.center, | |
children: [ | |
// Neumorphic( | |
// style: NeumorphicStyle( | |
// shape: NeumorphicShape.flat, | |
// boxShape: NeumorphicBoxShape.roundRect( | |
// BorderRadius.circular(10)), | |
// depth: -12, | |
// // lightSource: LightSource.top, | |
// | |
// border: NeumorphicBorder( | |
// width: 1, | |
// ), | |
// shadowDarkColor: Colors.black, | |
// shadowLightColor: slidervalue == 0 | |
// ? Colors.grey[600] | |
// : Colors.white, | |
// color: Colors.grey[700]), | |
// | |
// child: Container( | |
// width: screen_width * 0.16, | |
// height: screen_height * 0.14, | |
// ), | |
// ), | |
Neumorphic( | |
style: NeumorphicStyle( | |
shape: NeumorphicShape.flat, | |
boxShape: | |
NeumorphicBoxShape.roundRect( | |
BorderRadius.circular(8)), | |
depth: 12, | |
// lightSource: LightSource.top, | |
border: NeumorphicBorder( | |
width: 1, | |
), | |
shadowDarkColor: Colors.black, | |
shadowLightColor: slidervalue == 0 | |
? Colors.grey[700] | |
: Colors.white, | |
color: Colors.black), | |
child: Container( | |
width: screen_width * 0.125, | |
height: screen_height * 0.12, | |
decoration: BoxDecoration( | |
// borderRadius: BorderRadius.circular(5), | |
color: Color(0xff222831), | |
), | |
child: Column( | |
mainAxisAlignment: | |
MainAxisAlignment.center, | |
crossAxisAlignment: | |
CrossAxisAlignment.center, | |
children: [ | |
SvgPicture.asset( | |
"assets/images/power2_dark.svg", | |
width: screen_width * 0.07, | |
color: Colors.white70), | |
SizedBox( | |
height: screen_height * 0.01, | |
), | |
Text( | |
'روشن', | |
style: TextStyle( | |
color: Colors.white70, | |
fontWeight: | |
FontWeight.bold), | |
textAlign: TextAlign.center, | |
) | |
], | |
), | |
), | |
), | |
], | |
), | |
onTap: () { | |
id_selected == null | |
? ScaffoldMessenger.of(context) | |
.showSnackBar(snackBar) | |
: context | |
.read<Cubit_click>() | |
.event_click('on+${slidervalue}', | |
id_selected); | |
}, | |
), | |
SizedBox( | |
width: screen_width * 0.02, | |
), | |
], | |
) | |
], | |
)), | |
SizedBox( | |
height: screen_height * 0.03, | |
), | |
Expanded(child: BlocBuilder<Cubit_class, List<States>>( | |
builder: (context, state) { | |
return Container( | |
width: screen_width * 0.85, | |
height: screen_height * 0.07, | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.circular(10), | |
color: Color(0xff393E46), | |
), | |
child: ListView.builder( | |
shrinkWrap: true, | |
itemCount: state.length, | |
scrollDirection: Axis.horizontal, | |
itemBuilder: (context, index) { | |
return Container( | |
width: screen_width * 0.25, | |
height: screen_height * 0.07, | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.circular(5), | |
color: selectedIndex == index | |
? Colors.grey[600] | |
: Colors.transparent, | |
), | |
child: Center( | |
child: ListTile( | |
onTap: () { | |
// setState(() { | |
// selectedIndex = index; | |
// id_selected = state[index].id; | |
// }); | |
}, | |
title: Text( | |
state[index].name, | |
style: TextStyle( | |
color: selectedIndex == index | |
? Colors.white | |
: Colors.grey, | |
), | |
textAlign: TextAlign.center, | |
), | |
), | |
)); | |
}, | |
), | |
); | |
})), | |
SizedBox( | |
height: screen_height * 0.03, | |
), | |
], | |
)); | |
}))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment