Is it possible to use Home Widget with FlutterFlow?
home_widget | Flutter paketi (pub.dev)
How can Home Widget be used with FlutterFlow?
I tried Custom Widget, but it was only a widget in the application. My application did not appear among my widgets in the .apk file.
My customWidget code:
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/widgets/index.dart'; // Imports other custom widgets
import '/custom_code/actions/index.dart'; // Imports custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom widget code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'package:home_widget/home_widget.dart';
class LusidWidget extends StatefulWidget {
const LusidWidget({
Key? key,
this.width,
this.height,
required this.arkaPlanFoto,
required this.metin,
}) : super(key: key);
final double? width;
final double? height;
final String arkaPlanFoto;
final String metin;
@override
_LusidWidgetState createState() => _LusidWidgetState();
}
class _LusidWidgetState extends State<LusidWidget> {
String? text;
@override
void initState() {
super.initState();
HomeWidget.widgetClicked
.listen((uri) => _handleWidgetClicked()); // Uri? argümanını kabul et
_loadData(); // Başlangıçta veriyi yükle
}
Future<void> _updateWidget() async {
await HomeWidget.saveWidgetData<String>(
'backgroundImage', widget.arkaPlanFoto);
await HomeWidget.saveWidgetData<String>('text', widget.metin);
await HomeWidget.updateWidget(
name: 'LusidWidget',
iOSName: 'LusidWidget',
);
}
Future<void> _handleWidgetClicked() async {
// Widget tıklandığında yapılacak işlemler (Uri? argümanını kullanabilirsiniz)
print('Widget Tıklandı');
}
Future<void> _loadData() async {
text = await HomeWidget.getWidgetData<String>('text', defaultValue: '');
setState(() {}); // Veriyi aldıktan sonra arayüzü güncelle
}
@override
Widget build(BuildContext context) {
return Container(
width: widget.width,
height: widget.height,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(widget.arkaPlanFoto),
fit: BoxFit.cover,
),
),
child: Center(
child: text != null
? Text(
text!,
style: TextStyle(
color: Colors.white,
fontSize: 17,
fontFamily: 'Lora',
),
)
: CircularProgressIndicator(), // Veri yüklenirken gösterge
),
);
}
}