一、集成
1、在https://pub.dev/packages/get查看以后的最新版本
2、在我的项目的根目录下的pubspec.yaml增加如下代码
dependencies: get: ^4.1.4
3、关上终端执行 flutter pub get 即可
二、根底配置
更改main.dart中的代码为(也就是将默认的MaterialApp替换为GetMaterialApp)
GetMaterialApp( navigatorKey: Get.key, debugShowCheckedModeBanner: false, defaultTransition: Transition.cupertino, theme: ThemeData( primaryColor: Colors.white, highlightColor: Color.fromRGBO(0, 0, 0, 0), splashColor: Color.fromRGBO(0, 0, 0, 0)), initialRoute: RouteManager.splashPage, getPages: AppPages.getPages(), ), );
三、根底应用(路由、Dialog、BottomSheet)
- 路由
新建页面FirstPage
import 'package:flutter/material.dart';class FirstPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('FirstPage')), body: Container( color: Colors.green, child:ElevatedButton( style: ElevatedButton.styleFrom( primary: CustomColors.appBarBgColor, ), onPressed: () async { // 跳转 Get.to(SecondPage(); }, child: Container( alignment: Alignment.center, margin: EdgeInsets.symmetric(horizontal: 16), width: 260, child: Text('to second page'), ), ), ), ); }}