Last active
January 25, 2020 00:19
-
-
Save esron/099f3b257781cdafaef7d7ca1e9bd81a to your computer and use it in GitHub Desktop.
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'; | |
| void main() => runApp(MyApp()); | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: 'Flutter Demo', | |
| theme: ThemeData( | |
| primarySwatch: Colors.blue, | |
| ), | |
| home: MyHomePage(title: 'Calculadora Mexicana'), | |
| ); | |
| } | |
| } | |
| class MyHomePage extends StatefulWidget { | |
| MyHomePage({Key key, this.title}) : super(key: key); | |
| final String title; | |
| @override | |
| _MyHomePageState createState() => _MyHomePageState(); | |
| } | |
| class _MyHomePageState extends State<MyHomePage> { | |
| int _counter = 0; | |
| List list = new List<int>.generate(12, (i) => i + 1); | |
| void _incrementCounter(int incremet) { | |
| setState(() { | |
| _counter += incremet; | |
| }); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| backgroundColor: Colors.black87, | |
| appBar: AppBar( | |
| title: Text(widget.title), | |
| ), | |
| body: Center( | |
| child: Column( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: <Widget>[ | |
| GestureDetector( | |
| onLongPress: () { setState(() { | |
| _counter = 0; | |
| });}, | |
| child: Text( | |
| '$_counter', | |
| style: TextStyle( | |
| color: Colors.white, | |
| fontSize: 112, | |
| ), | |
| ), | |
| ), | |
| GridView.count( | |
| shrinkWrap: true, | |
| primary: false, | |
| padding: const EdgeInsets.all(10), | |
| crossAxisSpacing: 5, | |
| mainAxisSpacing: 5, | |
| crossAxisCount: 4, | |
| children: list.map((item) => DominoPiece( | |
| onTap: () => _incrementCounter(item), | |
| value: item, | |
| )).toList(), | |
| ) | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class DominoPiece extends StatelessWidget { | |
| final GestureTapCallback onTap; | |
| final int value; | |
| const DominoPiece({ Key key, this.onTap, this.value }) : super(key: key); | |
| @override | |
| Widget build(BuildContext context) { | |
| List list = [ | |
| new DominoZero(), | |
| new DominoOne(), | |
| new DominoTwo(), | |
| new DominoOne(), | |
| new DominoOne(), | |
| new DominoOne(), | |
| new DominoOne(), | |
| new DominoOne(), | |
| new DominoOne(), | |
| new DominoOne(), | |
| new DominoOne(), | |
| new DominoOne(), | |
| new DominoOne(), | |
| ]; | |
| return GestureDetector( | |
| onTap: onTap, | |
| child: new Container( | |
| padding: const EdgeInsets.all(8), | |
| decoration: BoxDecoration( | |
| color: Colors.white, | |
| borderRadius: BorderRadius.only( | |
| topLeft: Radius.circular(10), | |
| topRight: Radius.circular(10) | |
| ), | |
| ), | |
| child: Center( | |
| child: list[value], | |
| ) | |
| ), | |
| ); | |
| } | |
| } | |
| class DominoZero extends StatelessWidget { | |
| const DominoZero({ | |
| Key key, | |
| }) : super(key: key); | |
| @override | |
| Widget build(BuildContext context) { | |
| return Container(); | |
| } | |
| } | |
| class DominoOne extends StatelessWidget { | |
| const DominoOne({ | |
| Key key, | |
| }) : super(key: key); | |
| @override | |
| Widget build(BuildContext context) { | |
| return Container( | |
| width: 20, | |
| decoration: BoxDecoration( | |
| color: Color(0xFF204c83), | |
| shape: BoxShape.circle, | |
| ), | |
| ); | |
| } | |
| } | |
| class DominoTwo extends StatelessWidget { | |
| const DominoTwo({ | |
| Key key, | |
| }) : super(key: key); | |
| @override | |
| Widget build(BuildContext context) { | |
| return Row( | |
| children: <Widget>[ | |
| Container( | |
| width: 20, | |
| decoration: BoxDecoration( | |
| color: Color(0xFF172F0C), | |
| shape: BoxShape.circle, | |
| ), | |
| ), | |
| Container( | |
| width: 20, | |
| decoration: BoxDecoration( | |
| color: Color(0xFF172F0C), | |
| shape: BoxShape.circle, | |
| ), | |
| ), | |
| ], | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment