我无法找到第一次启动应用程序时导航动画如此缓慢的原因。这是3个文件的代码,这些文件应该可以让您完全了解我所拥有的。
login.dart
import 'package:flutter/material.dart';
import 'package:navtest/main.dart';
class LoginPage extends StatefulWidget {
@override
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Login Page'),
),
backgroundColor: Colors.red,
floatingActionButton: FloatingActionButton(
onPressed: () => Navigator.push(
context, MaterialPageRoute(builder: (context) => HomePage())),
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
placeholder.dart
import 'package:flutter/material.dart';
class PlaceholderPage extends StatefulWidget {
@override
_PlaceholderPageState createState() => _PlaceholderPageState();
}
class _PlaceholderPageState extends State<PlaceholderPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.green,
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[Center(child: Text('Placeholder Page'))],
),
);
}
}
main.dart:
import 'package:flutter/material.dart';
import 'package:navtest/placeholder.dart';
import 'login.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: LoginPage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
List<Widget> pages = [PlaceholderPage(), PlaceholderPage()];
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.yellow,
appBar: AppBar(
title: Text('Home Page'),
),
floatingActionButton: FloatingActionButton(
onPressed: () => Navigator.of(context).pop(),
tooltip: 'Increment',
child: Icon(Icons.remove),
),
body: DefaultTabController(
length: 2,
initialIndex: 0,
child: Scaffold(
body: TabBarView(
children: pages,
),
bottomNavigationBar: TabBar(
tabs: [
Tab(
icon: Icon(Icons.home),
),
Tab(
icon: Icon(Icons.perm_identity),
),
],
unselectedLabelColor: Colors.black,
labelColor: Colors.orange,
indicatorColor: Colors.transparent,
),
),
),
);
}
}
您是否也经历了缓慢的过渡?我是否使用了非常苛刻的结构,应该切换其他功能?