主题化扑动应用程序
今天我尝试为我的应用程序设置主题...我浏览了几个包并最终使用了 stacked_themes 包。现在我尝试实现文档中所示的代码,但我不确定如何实现对话框
主题模型文件:
import 'package:google_fonts/google_fonts.dart';
import 'package:stacked_themes/stacked_themes.dart';
import 'package:flutter/material.dart';
class MultiThemeModel {
int index;
String themeName;
MultiThemeModel({required this.index, required this.themeName});
}
titlesForThemeModel(int index) {
switch (index) {
case 0:
return 'Luxury Purple';
case 1:
return 'Red Fine Wine';
}
return 'No theme for index';
}
List<MultiThemeModel> get themes => List<MultiThemeModel>.generate(
2,
(index) =>
MultiThemeModel(index: index, themeName: titlesForThemeModel(index)));
List<Widget> get widgets => themes
.map((themeData) => MultipleThemeViewerWidget(themeData: themeData))
.toList();
class MultipleThemeViewerWidget extends StatelessWidget {
MultipleThemeViewerWidget({Key? key, required this.themeData})
: super(key: key);
final MultiThemeModel themeData;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(
right: 40,
),
child: GestureDetector(
onTap: () {
getThemeManager(context).selectThemeAtIndex(themeData.index);
},
child: Container(
height: 60,
width: 105,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Theme.of(context).scaffoldBackgroundColor.withOpacity(.3),
border: Border.all(
color: Theme.of(context).scaffoldBackgroundColor, width: 3)),
child: Center(
child: Text(
themeData.themeName,
style: GoogleFonts.poppins(
textStyle: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Theme.of(context).scaffoldBackgroundColor,
),
),
),
),
),
),
);
}
}
主题列表:
List<ThemeData> getThemes() {
return [
ThemeData(
brightness: Brightness.light,
primaryColor: purpleDesign[100],
scaffoldBackgroundColor: purpleDesign[400],
indicatorColor: purpleDesign[50],
primaryColorLight: purpleDesign[300],
hintColor: purpleDesign[400]),
ThemeData(
brightness: Brightness.light,
primaryColor: redDesign[100],
scaffoldBackgroundColor: redDesign[400],
indicatorColor: redDesign[50],
primaryColorLight: redDesign[300],
hintColor: redDesign[400])
];
}
对话框:
showDialog(
context: context,
builder: (BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25),
),
elevation: 1,
backgroundColor: Theme.of(context).indicatorColor,
insetAnimationCurve: Curves.decelerate,
child: Container(
height: 170,
child: Padding(
padding: const EdgeInsets.only(
left: 33,
top: 85,
),
child: Column(
children: [
Row(children: [
for(var theme in themes)
MultipleThemeViewerWidget(themeData: ),],),
],
),
),
),
);
我的问题 - 我不知道要传递给 themeData: 在forloop 来自对话框...如果有人可以帮助解决这个问题,那就太好了,
提前致谢:)
today I tried theming my app... I looked through a few packages and ended up using the stacked_themes package. Now I tried to implement the code as shown in the documentation but Im not sure how I have to implement the dialog
theme model file:
import 'package:google_fonts/google_fonts.dart';
import 'package:stacked_themes/stacked_themes.dart';
import 'package:flutter/material.dart';
class MultiThemeModel {
int index;
String themeName;
MultiThemeModel({required this.index, required this.themeName});
}
titlesForThemeModel(int index) {
switch (index) {
case 0:
return 'Luxury Purple';
case 1:
return 'Red Fine Wine';
}
return 'No theme for index';
}
List<MultiThemeModel> get themes => List<MultiThemeModel>.generate(
2,
(index) =>
MultiThemeModel(index: index, themeName: titlesForThemeModel(index)));
List<Widget> get widgets => themes
.map((themeData) => MultipleThemeViewerWidget(themeData: themeData))
.toList();
class MultipleThemeViewerWidget extends StatelessWidget {
MultipleThemeViewerWidget({Key? key, required this.themeData})
: super(key: key);
final MultiThemeModel themeData;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(
right: 40,
),
child: GestureDetector(
onTap: () {
getThemeManager(context).selectThemeAtIndex(themeData.index);
},
child: Container(
height: 60,
width: 105,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Theme.of(context).scaffoldBackgroundColor.withOpacity(.3),
border: Border.all(
color: Theme.of(context).scaffoldBackgroundColor, width: 3)),
child: Center(
child: Text(
themeData.themeName,
style: GoogleFonts.poppins(
textStyle: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Theme.of(context).scaffoldBackgroundColor,
),
),
),
),
),
),
);
}
}
List of themes:
List<ThemeData> getThemes() {
return [
ThemeData(
brightness: Brightness.light,
primaryColor: purpleDesign[100],
scaffoldBackgroundColor: purpleDesign[400],
indicatorColor: purpleDesign[50],
primaryColorLight: purpleDesign[300],
hintColor: purpleDesign[400]),
ThemeData(
brightness: Brightness.light,
primaryColor: redDesign[100],
scaffoldBackgroundColor: redDesign[400],
indicatorColor: redDesign[50],
primaryColorLight: redDesign[300],
hintColor: redDesign[400])
];
}
dialog:
showDialog(
context: context,
builder: (BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25),
),
elevation: 1,
backgroundColor: Theme.of(context).indicatorColor,
insetAnimationCurve: Curves.decelerate,
child: Container(
height: 170,
child: Padding(
padding: const EdgeInsets.only(
left: 33,
top: 85,
),
child: Column(
children: [
Row(children: [
for(var theme in themes)
MultipleThemeViewerWidget(themeData: ),],),
],
),
),
),
);
my problem - I don't know what to pass to the themeData: in the forloop from the dialog... it would be really nice if somebody could help with this
thanks in advance:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论