flutter html 加载_flutter 入口文件配置路由+加载页面

本文介绍了Flutter应用的入口程序配置,包括自定义主题、定义路由表、指定首页和加载页面。在main.dart中设置自定义主题,定义包含应用程序、好友动态和搜索页面的路由,并将加载页面作为首页。加载页面在初始化时停留3秒,然后跳转到主页面。文章还提供了一个简单的主页面布局示例。
摘要由CSDN通过智能技术生成

入口程序

所有的应用都有一个入口程序,通常是main函数引导进入应用程序,入口程序主要做一下几个方面的处理:

1、自定义主题:通过自定义将主题定义为XX风格,定义导航栏、弹出菜单等。

2、定义路由表:为整个应用程序作导航使用。例如:整个应用分三块需要路由,分别是:应用程序app、好友动态frends、搜索页面search。

3、指定首页:打开应用的第一个页面即为首页。通常首页并不是应用程序的主页面,而是加载页面。

指定方式:  home:new LoadingPage()

4、打开main.dart文件,按照上面几个步骤编写代码

//main 入口文件

import 'package:flutter/material.dart';

import'./app.dart';

import'./loading.dart';//应用程序入口

void main() =>runApp(MaterialApp(

debugShowCheckedModeBanner:false, //去除右上角的Debug标签

title: '测试',//自定义主题

theme: mDefaultTheme,//添加路由

routes: {"/app": (BuildContext context) => new App(), //主页面

},//首页

home: new LoadingPage(), //加载页面

));//自定义主题

final ThemeData mDefaultTheme = newThemeData(

primaryColor: Colors.green,

scaffoldBackgroundColor: Color(0xFFebebeb),

cardColor: Colors.green);

加载页面

其实加载页面和普通的页面并没有什么两样,唯一的区别是,加载页面是伴随着应用程序的加载完成的。由于这个过程是需要时间处理的,所以这个页面需要停留一定的时间,通常设置成几秒即可。

import 'package:flutter/material.dart';

import'dart:async';//加载页面

classLoadingPage extends StatefulWidget {

@override

_LoadingState createState()=> new_LoadingState();

}class _LoadingState extends State{

@overridevoidinitState(){

super.initState();//在加载页面停顿3秒

new Future.delayed(Duration(seconds: 3),(){

print("Flutter即时通讯APP界面实现...");

Navigator.of(context).pushReplacementNamed("/app");

});

}

@override

Widget build(BuildContext context){return newCenter(

child: Stack(

children:[//加载页面居中背景图 使用cover模式

Image.asset("images/loading.png",fit:BoxFit.cover,),

]

),

);

}

}

5、应用页面:为加载页面跳转后进入的页面。应用页面为整个程序的核心页面。

先写个测试的主页面,后续再添加相关功能。

import 'package:flutter/material.dart';//应用页面使用有状态Widget

classApp extends StatefulWidget {

@override

AppState createState()=>AppState();

}class AppState extends State{

@override

Widget build(BuildContext context) {//TODO: implement build

returnScaffold(

body:newCenter(

child:newText('主页面',

textAlign: TextAlign.center,

style:newTextStyle(

color: Colors.red[500],

fontSize:24.0,

fontWeight: FontWeight.bold

),

),

),

);

}

}///主页面

现在就可以打开设备运行查看效果了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flutter Zoomable Image 是一个用于 Flutter 应用程序的库,它提供了一个可缩放和拖动的图像小部件。使用 Flutter Zoomable Image,您可以轻松地实现图像的缩放、拖动和捏放手势操作。这对于创建具有可交互性的图像查看器和画廊等应用程序非常有用。 要使用 Flutter Zoomable Image,您需要在项目的 `pubspec.yaml` 文件中添加依赖项,并运行 `flutter packages get` 命令来获取库。 以下是一个简单的示例代码,演示了如何在 Flutter 中使用 Zoomable Image: ```dart import 'package:flutter/material.dart'; import 'package:flutter_zoomable_image/flutter_zoomable_image.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Zoomable Image Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(), ); } } class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Zoomable Image Demo'), ), body: Center( child: ZoomableImage( AssetImage('path/to/your/image.jpg'), placeholder: Center(child: CircularProgressIndicator()), backgroundColor: Colors.black, ), ), ); } } ``` 在上面的示例中,我们创建了一个简单的 Flutter 应用程序,其中包含一个使用 ZoomableImage 小部件的页面。ZoomableImage 接受一个 AssetImage 对象作为图像源,并提供了一些可选参数,例如 placeholder(用于在图像加载期间显示的小部件)和 backgroundColor(用于设置图像背景色)。 您可以根据自己的需求定制 Zoomable Image 的样式和行为。要了解更多关于 Flutter Zoomable Image 的信息和用法,请参考官方文档或库的 GitHub 页面
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值