[모바일 앱개발] video 7 Using Keys,
2022. 10. 19. 22:09ㆍ모바일앱개발_flutter
728x90
import 'dart:math';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter App',
theme: ThemeData(
primarySwatch: Colors.purple,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<Widget> listTile = [ Padding(
key: UniqueKey(),
padding: const EdgeInsets.all(8.0),
child: const MyTile(),
), Padding(
key: UniqueKey(),
padding: const EdgeInsets.all(8.0),
child: const MyTile(),
), ];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('My Home Page'),
actions: [
IconButton(
icon: const Icon(Icons.add),
onPressed: (){},
),
],
),
body: Row(
children: listTile,
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.swap_calls),
onPressed: () {
setState(() {
listTile.insert(1, listTile.removeAt(0));
});
},
),
);
}
}
class MyTile extends StatefulWidget {
const MyTile({Key? key}) : super(key: key);
@override
State<MyTile> createState() => _MyTileState();
}
class _MyTileState extends State<MyTile> {
var myColor = UniqueColorGenerator.getColor();
@override
Widget build(BuildContext context) {
return Container(
width: 100,
height: 100,
color: myColor,
);
}
}
class UniqueColorGenerator {
static Random random = Random();
static Color getColor() {
return Color.fromARGB(
255, random.nextInt(255), random.nextInt(255), random.nextInt(255));
}
}
'모바일앱개발_flutter' 카테고리의 다른 글
Video 10 - 11 Login/Usage Package 내용정리 (macOS) (0) | 2022.11.19 |
---|---|
모앱팀플_android studio git 협업방법 (0) | 2022.11.13 |
[모바일앱개발] Video 6 Receiving User Information (0) | 2022.10.18 |
[모바일앱개발] video 5 - Layout Part 2 (0) | 2022.10.18 |
모앱 video4 - Layout Part1 (2) | 2022.10.18 |