我想在 selectedOption 的值发生变化时调用一个函数。有没有办法在 SwiftUI 中做到这一点,类似于编辑 TextField 时?
具体来说,我想在用户更改 selectedOption 时保存所选选项。
这是我的选择器:
struct BuilderPicker: View {
let name: String
let options: Array<String>
@State var selectedOption = 0
var body: some View {
HStack {
Text(name)
.font(.body)
.padding(.leading, 10)
Picker(selection: $selectedOption, label: Text(name)) {
ForEach(0 ..< options.count) {
Text(self.options[$0]).tag($0)
}
}.pickerStyle(SegmentedPickerStyle())
.padding(.trailing, 25)
}.onTapGesture {
self.selectedOption = self.selectedOption == 0 ? 1 : 0
}
.padding(.init(top: 10, leading: 10, bottom: 10, trailing: 0))
.border(Color.secondary, width: 3)
.padding(.init(top: 0, leading: 15, bottom: 0, …Run Code Online (Sandbox Code Playgroud) 我有一个fl_chart (pub),它显示在下面的 gif 中。转换数据时,画家会在图表的边界之外进行绘制。我怎样才能clipper在下面的图表中添加一个(或其他一些修复),这样这个错误就不会发生?底部有一些代码和一些图像。fl_chart使用 aCustomPainter来绘制图表,所以也许我可以覆盖源代码中的某些内容?
我的快速修复(我删除了过渡动画,但我想使用动画):
忽略 y 轴(左侧)上的标签错误
(如果你没有看到错误,请仔细观察右侧)
我想使用这样的转换,但图表不会超出边界:
这是代码:
LineChartData mainData() {
return LineChartData(
lineTouchData: LineTouchData(
touchTooltipData: LineTouchTooltipData(
fitInsideHorizontally: true,
tooltipBgColor: Colors.white,
getTooltipItems: (List<LineBarSpot> touchedBarSpots) {
return touchedBarSpots.map((barSpot) {
return LineTooltipItem(
'${barSpot.y.toInt()}',
TextStyle(
fontFamily: 'Jost*',
fontSize: 15,
color: Colors.black,
),
);
}).toList();
}
),
getTouchedSpotIndicator: (LineChartBarData barData, List<int> spotIndexes) {
return spotIndexes.map((spotIndex) {
return TouchedSpotIndicatorData(
FlLine(
color: const Color.fromARGB(255, 77, 77, 77),
strokeWidth: 1,
dashArray: [4,4],
),
FlDotData(
getDotPainter: …Run Code Online (Sandbox Code Playgroud) 我试过这个,但我不知道如何在 SwiftUI 视图中使用结果:
func getProfilePicture(_ completion: @escaping ((UIImage) -> Void)) {
Alamofire.request(GIDSignIn.sharedInstance()?.currentUser.profile.imageURL(withDimension: 75) ?? "https://httpbin.org/image/png").responseImage { response in
if let image = response.result.value {
completion(image)
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果你能帮忙,我想把完成处理程序返回的图像放在这个视图中:
struct ProfileView: View {
let profileInfo = ProfileInfo()
var placeHolderImage = Image(systemName: "person")
var body: some View {
Group {
placeHolderImage
.clipShape(Circle())
.overlay(
Circle().stroke(Color.white, lineWidth: 4))
.shadow(radius: 10)
.padding(10)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望它返回一个 UIImage 以便我最终可以在 SwiftUI 视图中使用它。我已经尝试使用带有 @escaping 完成处理程序的方法,但我不知道如何使用它来解决问题。谢谢!
我有一个 next.js 应用程序设置,使用 prisma (v3.13) 作为 ORM。我正在测试bit.io的数据库托管,并且在尝试与客户端连接时收到此错误。当我使用本地 postgres 数据库时,一切都按预期工作。我当前使用的连接字符串如下所示:
DATABASE_URL="postgresql://[username]:[password]@db.bit.io/[username]/[dbname]"
Run Code Online (Sandbox Code Playgroud)
我正在尝试运行prisma db push并收到以下错误
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "eli-front/rankstl", schema "public" at "db.bit.io:5432"
Error: P1000: Authentication failed against database server at `db.bit.io`, the provided database credentials for `(not available)` are not valid.
Please make sure to provide valid database credentials for the database server at `db.bit.io`.
Run Code Online (Sandbox Code Playgroud)
我假设问题的核心是由于错误的一部分导致的,credentials for '(not available)'好像有些东西没有正确加载。
使用失败的连接字符串可以psql完全正常工作,但不能使用 prisma。