这里使用代码为flutter创建pdf文件。我正在使用插件pdf 1.0.6。
我的问题:
如何创建具有不同字体大小的多行文本?
PDFDocument _generateDocument() {
final pdf = new PDFDocument(deflate: zlib.encode);
final page = new PDFPage(pdf, pageFormat: PDFPageFormat.A4);
final g = page.getGraphics();
final font = new PDFFont(pdf);
final top = page.pageFormat.height;
g.setColor(new PDFColor(0.0, 1.0, 1.0));
g.drawRect(50.0 * PDFPageFormat.MM, top - 80.0 * PDFPageFormat.MM,
100.0 * PDFPageFormat.MM, 50.0 * PDFPageFormat.MM);
g.fillPath();
g.setColor(new PDFColor(0.3, 0.3, 0.3));
g.drawString(font, 12.0, "Hello World!", 10.0 * PDFPageFormat.MM,
top - 10.0 * PDFPageFormat.MM);
return pdf;
Run Code Online (Sandbox Code Playgroud)
}
我将一个 firebase 数据库监听器添加到我的颤振项目中,如下所示:
databaseReference = database.reference().child("community_board");
databaseReference.onChildAdded.listen(_onEntryAdded);
databaseReference.onChildChanged.listen(_onEntryChanged);
Run Code Online (Sandbox Code Playgroud)
对于 Kotlin 和 swift of firebase,我必须删除 onPause()/onDestroy() 中的监听器。我可以知道如何在 flutter 中删除 firebase 数据库侦听器吗?
我想在片段中创建一个recyclerView,但它显示错误"java.lang.IllegalStateException:recylerView_Main在com.gph.bottomnavigation.FragmentMe.onCreateView(FragmentMe.kt:28)中不能为null"
但是相同的代码在Fragment中不起作用,它显示错误,所以我将"recylerView_Main.layoutManager = LinearLayoutManager(this)"更改为"recylerView_Main.layoutManager = LinearLayoutManager(context)"它显示没有错误,我可以在simlulator中运行,但是我单击片段的导航按钮,应用程序停止并显示此错误.请帮助解决它.
这里有FragmentMe.kt的代码:
class FragmentMe : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
recylerView_Main.layoutManager = LinearLayoutManager(context)
recylerView_Main.adapter = Mainadapter()
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_me, container, false)
}
}
Run Code Online (Sandbox Code Playgroud)
这里使用MainActivity.kt的代码:
class MainActivity : AppCompatActivity() {
val manager = supportFragmentManager
private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
when (item.itemId) {
R.id.navigation_home -> {
//message.setText(R.string.title_home)
createFragmentQpon()
return@OnNavigationItemSelectedListener true
}
R.id.navigation_dashboard -> {
//message.setText(R.string.title_dashboard)
createFragmentMe()
return@OnNavigationItemSelectedListener true
} …
Run Code Online (Sandbox Code Playgroud) android fragment android-context kotlin android-recyclerview
我的Flutter项目有一个utility.dart文件和一个main.dart文件。我在main.dart文件中调用了函数,但是有问题。它总是showAlert“ OK”,我认为问题是实用程序类checkConnection()返回了将来的布尔类型。
main.dart:
if (Utility.checkConnection()==false) {
Utility.showAlert(context, "internet needed");
} else {
Utility.showAlert(context, "OK");
}
Run Code Online (Sandbox Code Playgroud)
utility.dart:
import 'package:flutter/material.dart';
import 'package:connectivity/connectivity.dart';
import 'dart:async';
class Utility {
static Future<bool> checkConnection() async{
ConnectivityResult connectivityResult = await (new Connectivity().checkConnectivity());
debugPrint(connectivityResult.toString());
if ((connectivityResult == ConnectivityResult.mobile) || (connectivityResult == ConnectivityResult.wifi)){
return true;
} else {
return false;
}
}
static void showAlert(BuildContext context, String text) {
var alert = new AlertDialog(
content: Container(
child: Row(
children: <Widget>[Text(text)],
),
),
actions: <Widget>[
new FlatButton(
onPressed: () => …
Run Code Online (Sandbox Code Playgroud) 该ShareButton
函数在Xcode 6中有效,但升级到Xcode 7
行后有错误:
avc.completionWithItemsHandler = {
我的代码:
@IBAction func ShareButton(sender: AnyObject) {
let things = ["Thank you"]
let avc = UIActivityViewController(activityItems:things, applicationActivities:nil)
avc.setValue("Salon Job HK", forKey: "subject")
avc.completionWithItemsHandler = {
(s: String!, ok: Bool, items: [AnyObject]!, err:NSError!) -> Void in
}
self.presentViewController(avc, animated:true, completion:nil)
if let pop = avc.popoverPresentationController {
let v = sender as! UIView // sender would be the button view tapped, but could be any view
pop.sourceView = v
pop.sourceRect = v.bounds
} …
Run Code Online (Sandbox Code Playgroud) 我使用下面的sortwith方法对ArrayList进行排序,我想它将排序顺序从小数到大数。例如10,9,8,7,6 .... 0。但是结果不是我所期望的。请帮助解决此问题。
companyList.add(companyReg)
companyList.sortedWith(compareBy { it.order })
for (obj in companyList) {
println("order number: "+obj.order)
}
Run Code Online (Sandbox Code Playgroud)
我在其他 Activity 中调用 MainActivity 的一个函数,应用程序关闭并显示如下错误,请帮助解决此问题。
主活动功能:
fun checkInternet():Boolean {
val cm = baseContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkInfo = cm.activeNetworkInfo
if (networkInfo != null && networkInfo.isConnected) {
alertPopUp("internet ok", "")
return true
}
else {
val title = getString(R.string.No_Internet)
val message = getString(R.string.need_internet_for_service)
alertPopUp(title, message)
return false
}
}
Run Code Online (Sandbox Code Playgroud)
在其他活动中调用此函数:
var internetStatus:Boolean = MainActivity().checkInternet()
Run Code Online (Sandbox Code Playgroud)
错误信息:
引起:java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference at com.gph.qpon.MainActivity.checkInternet (MainActivity.kt:148) 在 com.gph.qpon.qponClickedActivity.onCreate(qponClickedActivity.kt:32)
我是否可以知道如何在flutter中使用Firebase数据库创建数据类,并且数据将立即在应用程序的第一页中加载?
import 'package:dnow/model/company.dart';
import 'package:firebase_database/firebase_database.dart';
class RepoData {
static final Company bawp = new Company(
name: 'King',
about: 'Selling Food',
backdropPhoto: 'assets/hk.jpg',
shop: <Shop>[
new Shop(
shopName: 'ABC',
thumbnail: 'assets/daofang.png',
tel: "88776655",
address: '23 Daisy street, Sydney'),
new Shop(
shopName: 'KKK',
thumbnail: 'assets/fefew.png',
tel: "88776655",
address: '131 Man street, Sydney'),
],
location: 'Sydney',
logo: 'assets/logo.png',
president: 'Grand Production House');
}
[1]: https://i.stack.imgur.com/DV3X0.png
Run Code Online (Sandbox Code Playgroud) 我正在使用 flutter 插件音频播放器:^0.7.8,以下代码在 Android 中有效,但在 IOS 中无效。我在真实的 ios 设备中运行代码并单击按钮。它假设播放 mp3 文件,但根本没有声音。请帮助解决这个问题。
我已经设置了 info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Run Code Online (Sandbox Code Playgroud)
这里是从控制台打印出来的:
这里有我的代码:
class _MyHomePageState extends State<MyHomePage> {
AudioPlayer audioPlugin = AudioPlayer();
String mp3Uri;
@override
void initState() {
AudioPlayer.logEnabled = true;
_load();
}
Future<Null> _load() async {
final ByteData data = await rootBundle.load('assets/demo.mp3');
Directory tempDir = await getTemporaryDirectory();
File tempFile = File('${tempDir.path}/demo.mp3');
await tempFile.writeAsBytes(data.buffer.asUint8List(), flush: true);
mp3Uri = tempFile.uri.toString();
print('finished …
Run Code Online (Sandbox Code Playgroud) 我正在使用qr_flutter创建 QrImage。没关系,但我想将 QrImage 转换为图像,以便创建一个 PDF 文件以在打印机上打印。请帮助!
QrImage(
data: qrString,
size: 300.0,
version: 10,
backgroundColor: Colors.white,
),
Run Code Online (Sandbox Code Playgroud) 我的 flutter 应用程序将小部件捕获为图像,然后将 PDF 文件创建到打印机,但它显示如下图所示的荒谬结果。
如果您有更好的方法将汉字和qr图像打印到收据(纸宽75mm的蓝牙打印机),请告诉我
这里有小部件:
RepaintBoundary(
key: _renderObjectKey,
child: ListView(
children: <Widget>[
Form(
key: tableNumberFormKey,
child:
ListTile(
title: TextFormField(
initialValue: "",
style: TextStyle(fontSize: 48.0),
textAlign: TextAlign.center,
maxLength: 4,
keyboardType: TextInputType.phone,
onSaved: (val) => inputTableNumber = val.toString(),
validator: (val) => val.isEmpty ? '' : null,
decoration: new InputDecoration(
labelText: "????",
hintText: "???12",
),
),
),
),
FlatButton(
textColor: Colors.blueAccent,
child: Text(
"?? QR CODE",
style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20.0),
),
color: Colors.transparent,
onPressed: () {
_showQRandPrint();
SystemChannels.textInput.invokeMethod('TextInput.hide');
},
), …
Run Code Online (Sandbox Code Playgroud) 我正在将flutter_inapp_purchase用于我的Flutter应用程序的非消费品 IAP。对于 IOS,它确实需要包含“恢复购买”功能,以允许用户恢复之前购买的应用内购买。我可以知道如何创建“恢复”按钮并在用户点击“恢复”按钮时启动恢复过程吗?
Future<Null> _buyProduct(IAPItem item) async {
try {
PurchasedItem purchased= await
FlutterInappPurchase.buyProduct(item.productId);
print('purcuased - ${purchased.toString()}');
} catch (error) {
print('$error');
}
}
Future<Null> _getProduct() async {
List<IAPItem> items = await FlutterInappPurchase.getProducts(_productLists);
for (var item in items) {
print('${item.toString()}');
this._items.add(item);
}
setState(() {
this._items = items;
});
}
Run Code Online (Sandbox Code Playgroud) 我创建了一个微调器,但是我想更改文本颜色和字体大小。Web上有很多Java教程。我是新手,因此很难将Java转换为Kotlin。请帮助找到解决方案。
SpinnerActivity.kt
class SpinnerActivity : AppCompatActivity() {
lateinit var option : Spinner
lateinit var result :TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_spinner)
option = findViewById(R.id.sp_option) as Spinner
result = findViewById(R.id.tv_result) as TextView
val options = arrayOf("111", "222", "333")
option.adapter = ArrayAdapter<String>(this,R.layout.spinner_layout,options)
option.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
override fun onNothingSelected(parent: AdapterView<*>?) {
//TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
result.text = "please select an option"
}
override fun onItemSelected(parent: AdapterView<*>?, view: View?, …
Run Code Online (Sandbox Code Playgroud)