Last active
June 7, 2022 16:46
-
-
Save DaisukeNagata/29d5c0fc0ada3d49a5730bea89b5919d to your computer and use it in GitHub Desktop.
One of the calculation methods of flutter
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/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: const MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
const MyHomePage({Key? key, required this.title}) : super(key: key); | |
final String title; | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
int _counter = 0; | |
int _counter2 = 0; | |
List<int?>? _counter3 = []; | |
List<List<int?>?>? arraySt = [ | |
[null, 1, 2, null, 3, 3, 1, 2, 3, 4, 2, 2, 2] | |
]; | |
void _incrementCounter() { | |
setState(() { | |
check(); | |
}); | |
} | |
List<bool?> d = []; | |
void check() { | |
_counter = arraySt | |
?.map((e) => e | |
?.where((element) => element == _counter2) | |
.toList(growable: false)) | |
.map((element) { | |
_counter3 = element ?? []; | |
return element?.length; | |
}).first ?? | |
0; | |
if (_counter == 0) _counter2 = 0; | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text( | |
'$_counter3', | |
), | |
Text( | |
'$_counter', | |
style: Theme.of(context).textTheme.headline4, | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
_counter2++; | |
_incrementCounter(); | |
}, | |
tooltip: 'Increment', | |
child: const Icon(Icons.add), | |
), // This trailing comma makes auto-formatting nicer for build methods. | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2022-06-08.1.34.34.mov