티스토리 뷰
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 Demo',
      theme: ThemeData(
        
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
        useMaterial3: true,
      ),
      home: const DicePage(),
    );
  }
}
class DicePage extends StatefulWidget{
  const DicePage({super.key});
  @override
  State<StatefulWidget> createState() => _DicePageState();
}
class _DicePageState extends State<DicePage>{
  // states
  int _firstDiceNumber=3;
  int _secondDiceNumber=5;
   void _onDiceTap() {
    // Generate two random numbers between 1 and 6
    setState(() {
      _firstDiceNumber = Random().nextInt(6) + 1; // Random number between 1 and 6
      _secondDiceNumber = Random().nextInt(6) + 1; // Random number between 1 and 6
    });
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Theme.of(context).colorScheme.primary,
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.primary,
        title: Text('Dice App'),
    ),
    body: Center(
      child: Row(
        
        children: [
          Expanded(
            child: Padding(
              padding: const EdgeInsets.all(8.0),
               child: GestureDetector(
                onTap: _onDiceTap,
                child:  Image.asset('images/dice$_firstDiceNumber.png'),
               ),
            ),
          ),
          Expanded(
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: GestureDetector(
                onTap: _onDiceTap,
                child:  Image.asset('images/dice$_secondDiceNumber.png'),
              ),
            ),
          ),
              
        ],
      ),
    ),
      
    );
  }
  
}
주사위 이미지를 누를때 마다 바뀐다.


  assets:
   - images/
pubspec.yaml
'플러터(Flutter)' 카테고리의 다른 글
| 플러터 로그인 처리 (0) | 2024.10.25 | 
|---|---|
| 플러터 로그인 구현 (0) | 2024.10.24 | 
| 플러터 레이아웃 리팩토링 (0) | 2024.10.23 | 
| 플러터 레이아웃 (0) | 2024.10.23 | 
| 플러터 4.4.1 웹뷰 webview_flutter (0) | 2023.10.07 | 
					댓글
						
					
					
					
				
			
										공지사항
										
								
							
							
							
								최근에 올라온 글
								
							
							
								
									최근에 달린 댓글
									
							
							
								- Total
- Today
- Yesterday
									링크
									
							
							
								
									TAG
									
							
							
							- 프로씨
- proc
- XE
- webix
- 이클립스
- 파싱
- xe addon
- 자바
- 인포믹스
- EC
- MySQL
- KG
- 자바 smtp
- 오라클
- 파이썬
- ocajp
- 라이믹스
- 포인터
- 스크래핑
- Python
- 문자열
- XE3
- xe애드온
- C
- JDBC
- 플러터
- esql
- ocjap
- php
- C언어
| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | 
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | 
| 26 | 27 | 28 | 29 | 30 | 31 | 
									글 보관함
									
							
					