Created
June 14, 2019 11:11
-
-
Save filiph/e27f59b162afa132837ccb790ae49eb9 to your computer and use it in GitHub Desktop.
Code for the 50K followers tweet: https://twitter.com/FlutterDev/status/1139200781905727489
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 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
const List<List<int>> _pixels = [ | |
[1, 1, 1, 1, 0, 0, 1, 1, 0], | |
[1, 0, 0, 0, 0, 1, 0, 0, 1], | |
[1, 1, 1, 0, 0, 1, 0, 0, 1], | |
[0, 0, 0, 1, 0, 1, 0, 0, 1], | |
[0, 0, 0, 1, 0, 1, 0, 0, 1], | |
[0, 0, 0, 1, 0, 1, 0, 0, 1], | |
[1, 1, 1, 0, 0, 0, 1, 1, 0], | |
]; | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
bool _on = false; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
for (int y = 0; y < 7; y++) | |
Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
for (int x = 0; x < 9; x++) | |
CupertinoSwitch( | |
value: _on && _pixels[y][x] > 0, | |
onChanged: (_) => _toggle(), | |
) | |
], | |
) | |
], | |
)), | |
); | |
} | |
void _toggle() { | |
setState(() => _on = !_on); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment