flutter 性能优化案例
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

97 linhas
2.2 KiB

import 'dart:async';
import 'package:flutter/material.dart';
class Two extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _TwoState();
}
}
class CountText extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _CountTextState();
}
}
class _CountTextState extends State<CountText> {
int _count = 0;
Timer _timer;
@override
void initState() {
super.initState();
Timer.periodic(Duration(milliseconds: 1000), (t) {
setState(() {
_count++;
});
});
}
@override
void dispose() {
if (_timer != null && _timer.isActive) {
_timer.cancel();
}
super.dispose();
}
@override
Widget build(BuildContext context) {
return Text(
_count.toString(),
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
);
}
}
class _TwoState extends State<Two> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("性能测试2"),
),
body: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(10, 10, 10, 5),
height: 100,
color: Colors.amberAccent,
),
Container(
margin: EdgeInsets.fromLTRB(10, 10, 10, 5),
height: 100,
color: Colors.blue,
),
Container(
height: 100,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 12,
itemBuilder: (context, index) {
return Container(
width: 70,
height: 70,
child: Image.asset(
"assets/2.png",
width: 50,
height: 50,
));
}),
),
Container(
height: 100,
margin: EdgeInsets.fromLTRB(10, 10, 10, 5),
color: Colors.yellow,
child: Center(child: CountText()),
)
],
),
),
);
}
}