當我需要創建漸變時,Dart ui 不會匯入,因此除錯器會在ui.Gradient.Linear.
我嘗試匯入 dart:ui 就像它在檔案中所說的那樣,但它似乎沒有改變任何東西。
我的完整代碼:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:html_editor_enhanced/html_editor.dart';
import 'dart:ui';
class Write extends StatelessWidget {
// const Write({Key? key}) : super(key: key);
HtmlEditorController controller = HtmlEditorController();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Text(
"write or copy/paste your beautiful creation",
style: TextStyle(
height:5,
foreground: Paint()
..shader = ui.Gradient.linear(
const Offset(0, 20),
const Offset(150, 20),
<Color>[
Colors.red,
Colors.yellow,
],
))),
const SizedBox(height: 40),
HtmlEditor(
controller: controller, //required
htmlEditorOptions: const HtmlEditorOptions(
hint: "Your text here...",
// initialText: "and it came to pass...",
),
otherOptions: const OtherOptions(
height: 400,
),
),
],
),
);
}
}
uj5u.com熱心網友回復:
有兩種方法可以解決這個問題:
正如jigar patel 所說
import 'dart:ui' as ui;。你只需
ui要從ui.Gradient.linear. 并將其轉換為:
Text(
"write or copy/paste your beautiful creation",
style: TextStyle(
height: 5,
foreground: Paint()
..shader = Gradient.linear(
const Offset(0, 20),
const Offset(150, 20),
<Color>[Colors.red, Colors.yellow],
),
),
),
但是在您的情況下,第一種方法最有用。因為您需要import 'package:flutter/material.dart';為其他材質小部件匯入。這Gradient.linear對import 'dart:ui' as ui;和都可用'package:flutter/material.dart';。
uj5u.com熱心網友回復:
感謝Jigar帕特爾 在評論!
我只需要import 'dart:ui' as ui;
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/369079.html
上一篇:在dart中更改本地時區
