Skip to content

Instantly share code, notes, and snippets.

@mikebluestein
Created June 5, 2018 12:16
Show Gist options
  • Save mikebluestein/3350443df4689ddac115b68d1598d18e to your computer and use it in GitHub Desktop.
Save mikebluestein/3350443df4689ddac115b68d1598d18e to your computer and use it in GitHub Desktop.
Flutter article source
import 'package:flutter/material.dart';
void main() {
runApp(
Container(
color: Colors.lightBlue,
child: Padding(
padding: const EdgeInsets.fromLTRB(0.0, 50.0, 0.0, 0.0),
child: Directionality(
textDirection: TextDirection.ltr,
child: MyStatelessWidget(),
//child: MyStatefulWidget(), //uncomment to change widget
//child: StarWidget(),
)
)
)
);
}
class MyStatelessWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => print('you tapped the star'),
onDoubleTap: () => print('you double tapped the star'),
onLongPress: () => print('you long pressed the star'),
child: Icon(Icons.stars, size: 200.0),
);
}
}
class StarWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return StarState();
}
}
class StarState extends State<StarWidget> with SingleTickerProviderStateMixin {
AnimationController _ac;
final double _starSize = 300.0;
@override
void initState() {
super.initState();
_ac = new AnimationController(
duration: Duration(milliseconds: 750),
vsync: this,
);
_ac.forward();
}
@override
Widget build(BuildContext context) {
return new AnimatedBuilder(
animation: _ac,
builder: (BuildContext context, Widget child) {
return DecoratedBox(
child: Icon(Icons.stars, size: _ac.value * _starSize),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.red, Colors.blue, Colors.green],
tileMode: TileMode.mirror
),
),
);
}
);
}
}
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget();
@override
State<StatefulWidget> createState() {
return MyWidgetState();
}
}
class MyWidgetState extends State<MyStatefulWidget> {
String text = "some text";
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
FlatButton(
child: Text('Set State Button'),
onPressed: () {
setState(() {
text = "some new text";
});
},
),
Text(
text,
style: TextStyle(fontSize: 20.0)),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment