1、请问static 声明变量和final声明的变量有什么区别?
我的需求是期望类的变量在外部能获取到变量title,在内部也能使用比如:
import 'package:flutter/material.dart';
class StatefulGroup extends StatefulWidget {
StatefulGroup({Key key}) : super(key: key);
static String title = 'StatefulWidget与基础组件';
_StatefulGroupState createState() => _StatefulGroupState();
}
class _StatefulGroupState extends State<StatefulGroup> {
Widget build(BuildContext context) {
return MaterialApp(
title: widget.title, // 期望这里能够使用声明的变量
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: null,
);
}
}
// 期望能通过类直接访问到**title**这个变量,
print(StatefulGroup.title);
解锁Flutter开发新姿势,,系统掌握Flutter开发核心技术。
了解课程