Skip to content

Instantly share code, notes, and snippets.

@barongun
Created June 4, 2019 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barongun/b23392e7b0ec6901db5f1753f64dc8bf to your computer and use it in GitHub Desktop.
Save barongun/b23392e7b0ec6901db5f1753f64dc8bf to your computer and use it in GitHub Desktop.
slider
import 'package:flutter/material.dart';
void main(){
runApp(new MaterialApp(
home: new MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
_State createState() => new _State();
}
//State is information of the application that can change over time or when some actions are taken.
class _State extends State<MyApp>{
double _value = 0.0;
int r = 100;
int g = 100;
int b = 100;
void _setvalue(double value) => setState(() => {
_value = value,
r = value * 100 > 50 ? 200 : 100,
g = value * 100 > 50 ? 200 : 11,
b = value * 100 > 50 ? 200 : 100
});
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Name here'),
),
//hit Ctrl+space in intellij to know what are the options you can use in flutter widgets
body: new Container(
color: Color.fromRGBO(r, g, b, 0.3),
padding: new EdgeInsets.all(32.0),
child: new Center(
child: new Column(
children: <Widget>[
new Text('Value: ${(_value * 100).round()}'),
new Text('R: ${r}, G:${g}, B:${b}'),
new Slider(value: _value, onChanged: _setvalue)
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment