Created
May 10, 2023 10:39
-
-
Save your-diary/53c4ad505b9271d8d75058653b75dc3c to your computer and use it in GitHub Desktop.
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 'dart:math'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: | |
ThemeData(brightness: Brightness.dark, primaryColor: Colors.blueGrey), | |
home: W(), | |
debugShowCheckedModeBanner: false, | |
); | |
} | |
} | |
class W extends StatefulWidget { | |
const W({ | |
super.key, | |
}); | |
@override | |
State<W> createState() => _WState(); | |
} | |
class _WState extends State<W> { | |
List<Tile> l = [ | |
Tile(key: UniqueKey(), text: "hello"), | |
Tile(key: UniqueKey(), text: "world") | |
]; | |
// List<ColorCard> l = [ColorCard(), ColorCard()]; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
floatingActionButton: FloatingActionButton( | |
onPressed: () => | |
setState(() => {this.l.insert(1, this.l.removeAt(0))}), | |
child: Icon(Icons.swap_horiz)), | |
body: Center( | |
child: Row( | |
children: this.l, | |
))); | |
} | |
} | |
class Tile extends StatelessWidget { | |
final String text; | |
const Tile({required String this.text, super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Stack(children: [ | |
ColorCard(), | |
Text(this.text), | |
]); | |
} | |
} | |
Color createRandomColor() { | |
final colors = [ | |
Colors.red, | |
Colors.blue, | |
Colors.orange, | |
Colors.green, | |
Colors.purple, | |
]; | |
return colors[Random().nextInt(colors.length)]; | |
} | |
class ColorCard extends StatelessWidget { | |
final color = createRandomColor(); | |
ColorCard({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
width: 100, | |
height: 100, | |
color: this.color, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment