我怎樣才能在我的容器左上角給出這個視圖。它只是讓人們意識到是否閱讀了此通知。我需要使用徽章嗎?因為我認為需要一個功能。

uj5u.com熱心網友回復:
如果您不想像其他答案所建議的那樣使用資產影像,您可以創建一個簡單的類,您可以使用它來繪制此形狀。請參閱下面的代碼,您必須在標有注釋的地方添加您的條件:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyUnreadMarker extends CustomPainter {
late Paint painter;
MyUnreadMarker() {
painter = Paint()
..color = const Color(0xFF1CCCA5)
..style = PaintingStyle.fill;
}
@override
void paint(Canvas canvas, Size size) {
var path = Path();
path.moveTo(0, 0);
path.lineTo(size.width, 0);
path.lineTo(0, size.height);
path.close();
canvas.drawPath(path, painter);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Stack(children: [
Container(color: Colors.grey, width: 100, height: 100),
if (true) // add your condition here
CustomPaint(size: const Size(10, 10), painter: MyUnreadMarker()),
]))));
}
}
uj5u.com熱心網友回復:
最簡單的方法是將此資產匯出為影像webp,然后制作您的卡片 aStack并在其上添加此影像。并進行適當的檢查以顯示資產,例如
Stack(
children:[
if (!hasSeen)
Image.asset('assets/not_read.webp'),
Card(),
]
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/411611.html
標籤:
下一篇:如何在其他地方使用變數
