고고뜌지입니다.
타이머를 사용해서 시간당 image 경로 변경해서 UI화면에 보여주는 방법입니다.
import 'package:flutter/material.dart'; import 'dart:async'; import 'package:overflown/Model/Image.dart'; //intro image change 변수선언 int routeNo = 1; ValueNotifier<String> imgRoute = ValueNotifier<String>(''); Timer _timer; class Easy extends StatefulWidget{ @override State<StatefulWidget> createState() => Intro(); } class Intro extends State<Easy>{ Widget build(BuildContext context) { Intro_Image_Route(); //intro image route set 하는 함수 return Scaffold( appBar: AppBar( backgroundColor: Colors.deepOrangeAccent, automaticallyImplyLeading: false ), backgroundColor: Colors.white, body: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ ValueListenableBuilder( valueListenable: imgRoute, builder: (BuildContext context, String value, Widget child) { return Image( image: AssetImage(imgRoute.value) ); }, ) ] ), ); } Intro_Image_Route(){ ImageRoute Route = new ImageRoute(routeNo); imgRoute.value = Route.ImageRouteGo(); _timer = Timer.periodic(Duration(seconds: 1), (timer) { routeNo++; ImageRoute Route = new ImageRoute(routeNo); imgRoute.value = Route.ImageRouteGo(); if(routeNo == 21){ _timer?.cancel(); } }); } } |
'Flutter > - Useful Code' 카테고리의 다른 글
[에러] webview _ ERR_CACHE_MISS 에러 (0) | 2023.06.05 |
---|---|
[icons] AOS app icons/앱 이름 변경 (0) | 2023.06.05 |
[Appbar] appbar height 알아내는 법 (0) | 2022.12.14 |
[에러] setState() or markNeedsBuild() called during build (0) | 2022.12.14 |
AppBar 뒤로가기 icon visible false 처리 (0) | 2021.11.20 |
댓글