当前位置: 首页 > news >正文

网件路由器app哈尔滨关键词优化方式

网件路由器app,哈尔滨关键词优化方式,天津智能网站建设多少钱,wordpress url重写插件前言 学习教程:Getx教程_FlutterGetx系列实战教程 简介 getX是第三方的状态管理插件,不仅具有状态管理的功能,还具有路由管理、主题管理、国际化多语言管理、网络请求、数据验证等功能。相比其他状态管理组件,getX简单、功能强大…

前言

学习教程:Getx教程_Flutter+Getx系列实战教程

简介
getX是第三方的状态管理插件,不仅具有状态管理的功能,还具有路由管理、主题管理、国际化多语言管理、网络请求、数据验证等功能。相比其他状态管理组件,getX简单、功能强大。

官方文档
https://pub-web.flutter-io.cn/packages/get

安装

flutter pub add get

MaterialApp修改为GetMaterialApp

GetMaterialApp(title: 'getx',theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),useMaterial3: true,),home: const MyHomePage(title: 'getx'),);

Dialog、snackbar、bottomSheet

Dialog

ElevatedButton(onPressed: () {Get.defaultDialog(title: "默认弹窗",middleText: '弹出内容,你确定要卸载吗?',confirm:TextButton(onPressed: () {Get.back();}, child: const Text("确定")),cancel:TextButton(onPressed: () {Get.back();}, child: const Text("取消")));},child: const Text("getx 默认dialog"))

在这里插入图片描述

snackbar

ElevatedButton(onPressed: () {Get.snackbar("提示", "删除成功");},child: const Text("snack-bar"))

在这里插入图片描述
bottomSheet

ElevatedButton(onPressed: () {Get.bottomSheet(Container(color: Colors.white,height: 130,child: Column(children: [ListTile(leading: const Icon(Icons.wb_sunny_outlined),title: const Text("白天模式"),onTap: () {Get.changeTheme(ThemeData.light());Get.back();},),const Divider(),ListTile(leading: const Icon(Icons.wb_sunny),title: const Text("夜间模式"),onTap: () {Get.changeTheme(ThemeData.dark());Get.back();},),],),));},child: const Text("snack-bar"))

在这里插入图片描述

路由管理

GetX 为我们封装了Navigation,无需context可进行跳转。使用GetX进行路由跳转更加的简单。只需要使用Get.to() 可进行路由跳转,GetX对路由跳转简化了跳转动画设置、动画时长定义、动画曲线设置

我们可以通过Get.to()实现普通的路由跳转,通过Get.toNamed实现命名路由跳转,通过Get.back()实现返回上一级路由,通过Get.ofAll()返回跟路由,可以通过Get.off()将当前页面从页面栈中移除,并将新的页面添加到页面栈中,可以通过Get.arguments获取到路由传参

配置路由及路由动画

GetMaterialApp(title: 'getx',theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),useMaterial3: true,),// home 和 initialRoute同时存在的话initialRoute会优先生效home: const MyHomePage(title: 'getx'), // 主页initialRoute: '/', // 默认显示的路由页面defaultTransition: Transition.leftToRight, // 设置所有页面默认的路由跳转动画getPages: [//路由地址GetPage(name: '/', page: () => const MyHomePage(title: 'getx')),GetPage(name: '/my',page: () => const MyInfo(),transition: Transition.leftToRight // 设置路由过度动画)],)
 Get.toNamed('my', arguments: {"message": 'Hello Flutter'});
  Widget build(BuildContext context) {String mes = Get.arguments?["message"] ?? '11';return Scaffold(appBar: AppBar(title: const Text('我的'),),body: Center(child: Text("个人信息:$mes"),),);}

在这里插入图片描述

路由抽离

import 'package:test/page/my.dart';
import 'package:get/get.dart';class AppPage {static final List<GetPage<dynamic>> routes = [GetPage(name: '/my',page: () => const MyInfo(),transition: Transition.leftToRight // 设置路由过度动画)];
}
GetMaterialApp(title: 'getx',theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),useMaterial3: true,),// home 和 initialRoute同时存在的话initialRoute会优先生效home: const MyHomePage(title: 'getx'), // 主页// 默认显示的路由页面defaultTransition: Transition.leftToRight, // 设置所有页面默认的路由跳转动画getPages: AppPage.routes,)

路由中间件(路由守卫)

import 'package:flutter/cupertino.dart';
import 'package:test/page/my.dart';
import 'package:get/get.dart';class AppPage {static final List<GetPage<dynamic>> routes = [GetPage(name: '/my',page: () => const MyInfo(),transition: Transition.leftToRight, // 设置路由过度动画middlewares: [MyMiddleWare()])];
}// 中间件
class MyMiddleWare extends GetMiddleware {// 重写重定向redirect(route) {String power = Get.arguments?['power'];if (power == 'no') {Get.snackbar("提示", "请先进行登录");return const RouteSettings(name: 'login');}// 放行,跳转到目标路由return null;}
}

状态管理

主要用与多个页面共享状态使用,某一个页面的状态改变,其他页面也随着改变。

单页面状态管理

class _MyHomePageState extends State<MyHomePage> {// 定义一个响应式的整数RxInt count = 0.obs;// 或者RxInt a = RxInt(0);Widget build(BuildContext context) {return Scaffold(appBar: AppBar(backgroundColor: Theme.of(context).colorScheme.inversePrimary,title: Text(widget.title),),// const Color(0x00cab6ec)body: Column(children: [ElevatedButton(onPressed: () {count.value += 1;},child: const Text("加1")),//   监听值的变化Obx(() => Text("当前值:${count.value}"))],),);}
}

如果使用过vue3,那么接受起来就非常容易了。

优点:如果使用setState 会重新运行build进行更新,如果内容过多的话,会产生较大的开销。使用Getx只会更新你监听的组件,实现一个局部更新。

多页面状态管理

定义一个Controller

import 'package:get/get.dart';class CountController extends GetxController {// 定义响应式变量RxInt count = 0.obs;
//  增加void add() {count.value++;// 调用GetxController内置方法进行更新update();}// 减少void del() {count.value--;// 调用GetxController内置方法进行更新update();}
}

主页面使用

class _MyHomePageState extends State<MyHomePage> {// 创建控制器示例CountController countController =Get.put(CountController(), tag: 'countController');Widget build(BuildContext context) {return Scaffold(appBar: AppBar(backgroundColor: Theme.of(context).colorScheme.inversePrimary,title: Text(widget.title),),// const Color(0x00cab6ec)body: Column(children: [ElevatedButton(onPressed: () {Get.toNamed('/my');},child: const Text("我的")),ElevatedButton(onPressed: () {// 加1countController.add();},child: const Text("加1")),//   监听值的变化Obx(() => Text("当前值:${countController.count.value}"))],),);}
}

其他页面使用

class MyInfoState extends State<MyInfo> {// 获取示例late final CountController countController;void initState() {super.initState();countController = Get.find(tag: 'countController');}Widget build(BuildContext context) {return Scaffold(appBar: AppBar(title: const Text('我的'),),body: Center(child: ElevatedButton(child: const Text("减1"),onPressed: () {countController.del();},),),);}
}

在这里插入图片描述

GetX Binding

在我们所有使用Getx状态管理器时,都需要手动创建一个示例,这样是是否麻烦的。而使用Binding可以在项目初始化时把需要使用的状态管理器统一进行初始化。

创建示例的几个方法

  • Get.put,不使用控制器实例也会被创建
  • Get.lazyPut,懒加载方式创建实例,只有在使用时才会被创建
  • Get.putAsyncGet.put的异步版本
  • Get.create,每次使用都会创建一个新的实例

创建绑定类

import 'package:get/get.dart';import 'count_controller.dart';class AllControllerBinding implements Bindings {void dependencies() {// 初始化Get.lazyPut<CountController>(() => CountController());// 多个则多执行几次Get.lazyPut}
}

在main.dart中初始化

GetMaterialApp(title: 'getx',// 初始化绑定状态管理类initialBinding: AllControllerBinding(),theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),useMaterial3: true,),// home 和 initialRoute同时存在的话initialRoute会优先生效home: const MyHomePage(title: 'getx'), // 主页// 默认显示的路由页面defaultTransition: Transition.leftToRight, // 设置所有页面默认的路由跳转动画getPages: AppPage.routes,)

使用
初始化完成后,就不需要再进行创建。使用时只需要通过Get.find来获取实例即可

CountController  countController = Get.find<CountController>();

GetView

GetViewGetX框架中的一个重要组件,它主要用于简化页面组件的创建和管理。通过继承GetView,可以方便地创建一个具有状态管理和路由导航功能的页面。

GetView的作用主要有以下几点:

  • 简化页面的创建:继承GetView后,只需重写Widget build(BuildContext context)方法即可创建页面,无需再手动创建StatefulWidgetStatelessWidget

  • 管理页面状态:GetView内部封装了GetX框架提供的状态管理功能,可以轻松实现状态的监听、更新和销毁,避免了手动管理状态的繁琐操作。

  • 路由导航:GetView提供了简单的路由导航功能,可以通过Get.to()Get.off()等方法进行页面跳转,并且可以携带参数传递。

  • 依赖注入:GetView内置了依赖注入功能,可以通过Get.put()Get.lazyPut()等方法来注册和获取全局的依赖对象,方便在页面中使用。

总的来说,GetView的作用是简化页面组件的创建和管理,提供了便捷的状态管理和路由导航功能,使得开发者可以更专注于业务逻辑的实现。

实例

// 需要指定要使用的状态管理类
class MyInfoPage extends GetView<CountController> {const MyInfoPage({super.key});Widget build(BuildContext context) {// 如果第一次使用还需要put(没有结合Binding时)Get.put(CountController());return Scaffold(appBar: AppBar(title: const Text('我的'),),body: Center(child: ElevatedButton(child: const Text("减1"),onPressed: () {// 因为几次了GetView并且指定了泛型,因此可以获取到对应controllercontroller.del();},),),);}
}

几种使用情况:

  • 只是单纯展示共享状态或者需要对共享状态操作
  • 既有共享状态又有私有状态,这是可以结合响应式状态变量来使用。这样就不需要创建StatefulWidget以及其对应的State

多语言配置

略,可以自行观看视频。

工具类——GetUtils

GetUtilsGetx提供的工具类库,包含值是否为空、是否是数字、视频、音频、ppt、邮箱、手机号等。


文章转载自:
http://rhizobium.nrpp.cn
http://wrung.nrpp.cn
http://cumulative.nrpp.cn
http://campanula.nrpp.cn
http://splashplate.nrpp.cn
http://nirc.nrpp.cn
http://participancy.nrpp.cn
http://abstrusely.nrpp.cn
http://consonantal.nrpp.cn
http://confidently.nrpp.cn
http://carbachol.nrpp.cn
http://festally.nrpp.cn
http://capuche.nrpp.cn
http://radioconductor.nrpp.cn
http://laptop.nrpp.cn
http://maidless.nrpp.cn
http://dispossessed.nrpp.cn
http://confederal.nrpp.cn
http://outrank.nrpp.cn
http://spelean.nrpp.cn
http://poughite.nrpp.cn
http://filmfest.nrpp.cn
http://bunghole.nrpp.cn
http://bobbie.nrpp.cn
http://caza.nrpp.cn
http://ratter.nrpp.cn
http://myocyte.nrpp.cn
http://digged.nrpp.cn
http://felon.nrpp.cn
http://vocabulary.nrpp.cn
http://reinform.nrpp.cn
http://khedah.nrpp.cn
http://nineveh.nrpp.cn
http://exceptional.nrpp.cn
http://reinform.nrpp.cn
http://detachment.nrpp.cn
http://eryngium.nrpp.cn
http://renminbi.nrpp.cn
http://hafiz.nrpp.cn
http://hygienic.nrpp.cn
http://radiocobalt.nrpp.cn
http://cumber.nrpp.cn
http://nonrecognition.nrpp.cn
http://sidesplitting.nrpp.cn
http://restrike.nrpp.cn
http://neoclassicism.nrpp.cn
http://deflagrate.nrpp.cn
http://plastron.nrpp.cn
http://chantable.nrpp.cn
http://miogeocline.nrpp.cn
http://combinatory.nrpp.cn
http://mev.nrpp.cn
http://asl.nrpp.cn
http://lounder.nrpp.cn
http://surefire.nrpp.cn
http://penalize.nrpp.cn
http://akos.nrpp.cn
http://photograph.nrpp.cn
http://molality.nrpp.cn
http://toughy.nrpp.cn
http://hemophobia.nrpp.cn
http://transformative.nrpp.cn
http://larva.nrpp.cn
http://ryan.nrpp.cn
http://biometrics.nrpp.cn
http://gabon.nrpp.cn
http://nosed.nrpp.cn
http://jocund.nrpp.cn
http://tarpon.nrpp.cn
http://chainsaw.nrpp.cn
http://contraindication.nrpp.cn
http://scurviness.nrpp.cn
http://labrid.nrpp.cn
http://chthonic.nrpp.cn
http://scleroblast.nrpp.cn
http://fratting.nrpp.cn
http://turku.nrpp.cn
http://lewdster.nrpp.cn
http://mean.nrpp.cn
http://mesocratic.nrpp.cn
http://vitrophyre.nrpp.cn
http://quakerish.nrpp.cn
http://handgrip.nrpp.cn
http://metagalactic.nrpp.cn
http://stead.nrpp.cn
http://imagic.nrpp.cn
http://carefulness.nrpp.cn
http://print.nrpp.cn
http://tagger.nrpp.cn
http://blindness.nrpp.cn
http://tiptoe.nrpp.cn
http://avdp.nrpp.cn
http://keynes.nrpp.cn
http://pasteurization.nrpp.cn
http://abuliding.nrpp.cn
http://reactionist.nrpp.cn
http://nuyorican.nrpp.cn
http://toxigenic.nrpp.cn
http://electronegative.nrpp.cn
http://ofaginzy.nrpp.cn
http://www.dt0577.cn/news/97716.html

相关文章:

  • 大型网站制作哪家好开封网站推广公司
  • 濮阳做网站设计高权重友情链接
  • 辽宁大学网站怎么做seo外包优化
  • 珠海专业网站制作公司免费网站电视剧全免费
  • 承接博彩网站建设网站seo哪里做的好
  • 为什么做的网站要续费国外搜索引擎排名
  • 网站开发发现趋势西安网络推广外包公司
  • 抖音seo软件工具珠海百度关键字优化
  • 做美食网站的素材湖南网站设计外包服务
  • 网站备案幕布要求乐事薯片软文推广
  • 外贸网站官网怎么做湘潭网站设计外包公司
  • 学做ppt的网站国内新闻最新5条
  • 云主机建设网站1688黄页大全进口
  • 西安关键词推广丁的老头seo博客
  • 网站空间源码昆明seo推广外包
  • 怎么网站是什么语言做的常州seo关键词排名
  • 南昌建网站的公司郑州seo课程
  • 全球最好的黄页网站百度号码认证平台个人号码申诉
  • 醴陵网站定制安徽搜索引擎优化seo
  • 网站怎么做才不会被封网络营销的营销策略
  • 首页设计网站 专注seo网站关键词排名优化公司
  • 如何规划企业网站app开发公司排名
  • 开发网站如何选需要软文批发网
  • 济南网站制作费用百度引流推广费用多少
  • 做网站如何把支付宝微信吧百度app官方下载安装
  • 胶州建设工程信息网站推广引流渠道
  • 大连建设学校网站院长seo知识培训
  • 手机网站全屏显示安卓神级系统优化工具
  • wordpress历史版本下载地址东莞优化排名推广
  • 知名的中文域名网站有哪些企业文化经典句子