所有小部件都可以通过单击按钮进行重建。
我只想重建按钮小部件。
使用单个按钮小部件并不是主要的性能问题,但是随着按钮小部件数量的增加,性能会急剧下降。
仅用一个按钮,性能就不足30fps。
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, v1.15.17-pre.5, on Microsoft Windows [Version 10.0.18362.657], locale ja-JP)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
[√] Chrome - develop for the web
[√] Android Studio (version 3.6)
[√] VS Code (version 1.42.1)
[√] Connected device (4 available)
• No issues found!
import 'package:flutter/material.dart';
void main() => runApp(Home());
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: SafeArea(
child: Center(
child: DurationButton(),
)
)
)
);
}
}
class DurationButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return SizedBox(
height: size.width/3.75,
width: size.width/3.75,
child: RaisedButton(
elevation: 10.0,
onPressed: () {},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const Spacer(flex: 15,),
Text(
"PREPARE",
style: Theme.of(context).textTheme.bodyText2,
textAlign: TextAlign.center,
),
const Spacer(flex: 10),
const Text('20s'),
const Spacer(flex: 15,),
],
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)
),
),
);
}
}