如何在 flutter 中调整 CircularProgressIndicator 的大小?

Pri*_*mal 4 dart progress-bar flutter

我看到了这个问题这个问题,但它不能解决我的问题。我尝试了SizedBoxSizedBox.fromSizeBoxConstraints但它们都不起作用。

\n\n

我该如何处理?

\n\n
import \'package:flutter/material.dart\';\nimport \'package:mymovie/bloc_helpers/bloc_event_state_builder.dart\';\nimport \'package:mymovie/logics/intro/intro.dart\';\nimport \'package:mymovie/resources/strings.dart\';\nimport \'package:mymovie/utils/bloc_navigator.dart\';\nimport \'package:mymovie/utils/bloc_snackbar.dart\';\nimport \'package:mymovie/utils/service_locator.dart\';\n\nclass IntroScreen extends StatefulWidget{\n\n  @override\n  _IntroScreenState createState() => _IntroScreenState();\n}\n\nclass _IntroScreenState extends State<IntroScreen> with SingleTickerProviderStateMixin{\n\n  final IntroBloc introBloc = sl.get<IntroBloc>();\n  AnimationController animationController;\n  Animation buttonSqueeze;\n\n  @override\n  void initState() {\n    super.initState();\n    animationController = AnimationController(\n      duration: const Duration(milliseconds: 1500),\n      vsync: this\n    );\n    buttonSqueeze = Tween(\n      begin: 320.0,\n      end: 70.0\n    ).animate(CurvedAnimation(\n      parent: animationController,\n      curve: Interval(0.0,0.250)\n    ));\n    animationController.addListener(() {\n      if(animationController.isCompleted) {\n        introBloc.emitEvent(IntroEventKakaoLogin());\n      }\n    });\n  }\n\n  Future<void> _playAnimation() async{\n    try {\n      await animationController.forward();\n    } on TickerCanceled {}\n  }\n\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      body: Container(\n        width: double.infinity,\n        decoration: BoxDecoration(\n          image: DecorationImage(\n            image: AssetImage(\'assets/images/ironman.jpg\'),\n            fit: BoxFit.cover,\n            colorFilter: ColorFilter.mode(Colors.black.withOpacity(0.6), BlendMode.darken)\n          ),\n        ),\n        child: Column(\n          crossAxisAlignment: CrossAxisAlignment.center,\n          children: [\n            Container(\n              padding: const EdgeInsets.only(top: 180.0),\n              child: Text(\n                \'\xec\x98\x81\xed\x99\x94\xec\x9d\xbc\xea\xb8\xb0\',\n                style: TextStyle(\n                  color: Colors.white,\n                  fontWeight: FontWeight.bold,\n                  fontSize: 70.0\n                ),\n              ),\n            ),\n            SizedBox(height: 20.0),\n            Container(\n              color: Colors.white,\n              width: 200.0,\n              height: 4.0,\n            ),\n            SizedBox(height: 200.0),\n            AnimatedBuilder(\n              animation: buttonSqueeze,\n              builder: (_,__){\n                return BlocBuilder(\n                  bloc: introBloc,\n                  builder: (context, IntroState state){\n                    if(state.isKakaoLoginSucceeded) {\n                      BlocNavigator.pushReplacementNamed(context, routeHome);\n                    }\n                    if(state.isKakaoLoginFailed) {\n                      BlocSnackbar.show(context, \'\xeb\xa1\x9c\xea\xb7\xb8\xec\x9d\xb8\xec\x97\x90 \xec\x8b\xa4\xed\x8c\xa8\xed\x95\x98\xec\x98\x80\xec\x8a\xb5\xeb\x8b\x88\xeb\x8b\xa4.\');\n                      introBloc.emitEvent(IntroEventStateClear());\n                    }\n                    return GestureDetector(\n                      child: Container(\n                        width: buttonSqueeze.value,\n                        height: 60.0,\n                        decoration: BoxDecoration(\n                          color: Colors.yellow,\n                          borderRadius: BorderRadius.circular(15.0)\n                        ),\n                        child: buttonSqueeze.value>75.0 ? Row(\n                          children: <Widget>[\n                            SizedBox(width: 20.0),\n                            buttonSqueeze.value<100.0 ? Container() :\n                            Image.asset(\'assets/images/kakao.png\'),\n                            buttonSqueeze.value<300.0 ? Container() :\n                            Container(\n                              child: Text(\n                                \'\xec\xb9\xb4\xec\xb9\xb4\xec\x98\xa4\xed\x86\xa1\xec\x9c\xbc\xeb\xa1\x9c \xeb\xa1\x9c\xea\xb7\xb8\xec\x9d\xb8\',\n                                style: TextStyle(\n                                  color: Colors.brown,\n                                  fontWeight: FontWeight.bold,\n                                  fontSize: 20.0\n                                ),\n                              ),\n                            )\n                          ],\n                        ) : \n                        SizedBox(\n                          child: CircularProgressIndicator(\n                            valueColor: AlwaysStoppedAnimation<Color>(Colors.brown),\n                            strokeWidth: 1.0,\n                          ),\n                          width: 30.0,\n                          height: 30.0,\n                        )\n                      ),\n                      onTap: () => _playAnimation()\n                    );\n                  }\n                );\n              }\n            )\n          ],\n        )\n      )\n    );\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

小智 9

试试这个方法,这解决了我的问题:

new Container(
              height: 60.0,
              child: new Center(child: new CircularProgressIndicator()),
            )
Run Code Online (Sandbox Code Playgroud)

  • 这里的“Center”小部件也是必不可少的。我一开始忽略了它,“CircularProgressIndicator”仍然扩展到全屏。 (2认同)