是否可以為該功能應用主題?這個想法是對加載許可證時出現的圓形進度指示器顏色進行風格化。
OutlinedButton(
onPressed: () {
showLicensePage( // how to apply theme to this function?
context: context,
applicationIcon: const MyAppIcon(48),
);
},
child: Text(
AppLocalizations.key(context, 'licenses'),
),
),
該showLicensePage
功能實際上只是一個簡單的Navigator.push
.
void showLicensePage({
required BuildContext context,
String? applicationName,
String? applicationVersion,
Widget? applicationIcon,
String? applicationLegalese,
bool useRootNavigator = false,
}) {
assert(context != null);
assert(useRootNavigator != null);
Navigator.of(context, rootNavigator: useRootNavigator).push(MaterialPageRoute<void>(
builder: (BuildContext context) => LicensePage(
applicationName: applicationName,
applicationVersion: applicationVersion,
applicationIcon: applicationIcon,
applicationLegalese: applicationLegalese,
),
));
}
您可以創建自己的showLicensePageWithTheme
,LicensePage
用Theme
小部件包裝的地方:
void showLicensePageWithTheme({
required BuildContext context,
required ThemeData theme,
String? applicationName,
String? applicationVersion,
Widget? applicationIcon,
String? applicationLegalese,
bool useRootNavigator = false,
}) {
assert(context != null);
assert(useRootNavigator != null);
Navigator.of(context, rootNavigator: useRootNavigator)
.push(MaterialPageRoute<void>(
builder: (BuildContext context) => Theme(
data: theme,
child: LicensePage(
applicationName: applicationName,
applicationVersion: applicationVersion,
applicationIcon: applicationIcon,
applicationLegalese: applicationLegalese,
),
),
));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句