첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

test_app.zip
0.13MB

▶ main.dart

import 'dart:async';
import 'package:flutter/material.dart';

void main() {
  runApp(TestApplication());
}

class TestApplication extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Test Application',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MainPage(),
    );
  }
}

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  Timer _timer;
  bool _isRunning = false;
  int _timerCount = 0;
  String _buttonText = 'Start';

  @override
  void dispose() {
    _timer?.cancel();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Test Application'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            RaisedButton(
              child: Text("$_buttonText"),
              color: Colors.orange,
              onPressed: () {
                _isRunning = !_isRunning;

                if (_isRunning) {
                  setState(() {
                    _timerCount = 0;

                    _buttonText = 'Stop';
                  });

                  _timer = Timer.periodic(Duration(milliseconds: 10), (timer) {
                    setState(() {
                      _timerCount++;
                    });
                  });
                } else {
                  _timer?.cancel();

                  setState(() {
                    _buttonText = 'Start';
                  });
                }
              },
            ),
            Padding(
              padding: const EdgeInsets.only(top: 10.0),
              child: Text("$_timerCount"),
            ),
          ],
        ),
      ),
    );
  }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker
TAG ,

댓글을 달아 주세요