一、集成
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'),
),
),
),
);
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。