簡體   English   中英

如何在Flutter中調整CircularProgressIndicator的大小?

[英]How can I resize CircularProgressIndicator in flutter?

我看到了這個問題這個問題 ,但無法解決我的問題。 我嘗試了SizedBoxSizedBox.fromSize以及BoxConstraints ,但是它們都不起作用。

我該如何處理?

import 'package:flutter/material.dart';
import 'package:mymovie/bloc_helpers/bloc_event_state_builder.dart';
import 'package:mymovie/logics/intro/intro.dart';
import 'package:mymovie/resources/strings.dart';
import 'package:mymovie/utils/bloc_navigator.dart';
import 'package:mymovie/utils/bloc_snackbar.dart';
import 'package:mymovie/utils/service_locator.dart';

class IntroScreen extends StatefulWidget{

  @override
  _IntroScreenState createState() => _IntroScreenState();
}

class _IntroScreenState extends State<IntroScreen> with SingleTickerProviderStateMixin{

  final IntroBloc introBloc = sl.get<IntroBloc>();
  AnimationController animationController;
  Animation buttonSqueeze;

  @override
  void initState() {
    super.initState();
    animationController = AnimationController(
      duration: const Duration(milliseconds: 1500),
      vsync: this
    );
    buttonSqueeze = Tween(
      begin: 320.0,
      end: 70.0
    ).animate(CurvedAnimation(
      parent: animationController,
      curve: Interval(0.0,0.250)
    ));
    animationController.addListener(() {
      if(animationController.isCompleted) {
        introBloc.emitEvent(IntroEventKakaoLogin());
      }
    });
  }

  Future<void> _playAnimation() async{
    try {
      await animationController.forward();
    } on TickerCanceled {}
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: double.infinity,
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage('assets/images/ironman.jpg'),
            fit: BoxFit.cover,
            colorFilter: ColorFilter.mode(Colors.black.withOpacity(0.6), BlendMode.darken)
          ),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              padding: const EdgeInsets.only(top: 180.0),
              child: Text(
                '영화일기',
                style: TextStyle(
                  color: Colors.white,
                  fontWeight: FontWeight.bold,
                  fontSize: 70.0
                ),
              ),
            ),
            SizedBox(height: 20.0),
            Container(
              color: Colors.white,
              width: 200.0,
              height: 4.0,
            ),
            SizedBox(height: 200.0),
            AnimatedBuilder(
              animation: buttonSqueeze,
              builder: (_,__){
                return BlocBuilder(
                  bloc: introBloc,
                  builder: (context, IntroState state){
                    if(state.isKakaoLoginSucceeded) {
                      BlocNavigator.pushReplacementNamed(context, routeHome);
                    }
                    if(state.isKakaoLoginFailed) {
                      BlocSnackbar.show(context, '로그인에 실패하였습니다.');
                      introBloc.emitEvent(IntroEventStateClear());
                    }
                    return GestureDetector(
                      child: Container(
                        width: buttonSqueeze.value,
                        height: 60.0,
                        decoration: BoxDecoration(
                          color: Colors.yellow,
                          borderRadius: BorderRadius.circular(15.0)
                        ),
                        child: buttonSqueeze.value>75.0 ? Row(
                          children: <Widget>[
                            SizedBox(width: 20.0),
                            buttonSqueeze.value<100.0 ? Container() :
                            Image.asset('assets/images/kakao.png'),
                            buttonSqueeze.value<300.0 ? Container() :
                            Container(
                              child: Text(
                                '카카오톡으로 로그인',
                                style: TextStyle(
                                  color: Colors.brown,
                                  fontWeight: FontWeight.bold,
                                  fontSize: 20.0
                                ),
                              ),
                            )
                          ],
                        ) : 
                        SizedBox(
                          child: CircularProgressIndicator(
                            valueColor: AlwaysStoppedAnimation<Color>(Colors.brown),
                            strokeWidth: 1.0,
                          ),
                          width: 30.0,
                          height: 30.0,
                        )
                      ),
                      onTap: () => _playAnimation()
                    );
                  }
                );
              }
            )
          ],
        )
      )
    );
  }
}

嘗試這種方式,這解決了我的問題:

new Container(
              height: 60.0,
              child: new Center(child: new CircularProgressIndicator()),
            )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM