flutter 性能优化案例
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

85 wiersze
2.0 KiB

import 'dart:async';
import 'package:flutter/material.dart';
/// 常规布局
class One extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _OneState();
}
}
class _OneState extends State<One> {
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 MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("性能测试1"),
),
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: Text(
_count.toString(),
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
)
],
),
),
);
}
}