Skip to content

Instantly share code, notes, and snippets.

@filiph
Created June 14, 2019 11:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filiph/e27f59b162afa132837ccb790ae49eb9 to your computer and use it in GitHub Desktop.
Save filiph/e27f59b162afa132837ccb790ae49eb9 to your computer and use it in GitHub Desktop.
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