Hi I've been recently shifted from Android Native to Flutter.
What I'm trying to do is to read text from other apps by drawing over other apps.
What I found is flutter_mobile_vision for OCR which works with mobile camera.
https://pub.dev/packages/flutter_mobile_vision
Can anyone guide me to make my app draw on other apps and detect text from other apps.
Though in IOS Floating Panel is not possible due to restriction , but in android you can do so with flutter . Use:
dependencies:
system_alert_window: ^1.0.0
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:system_alert_window/system_alert_window.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
///
/// Whenever a button is clicked, this method will be invoked with a tag (As tag is unique for every button, it helps in identifying the button).
/// You can check for the tag value and perform the relevant action for the button click
///
void callBack(String tag) {
WidgetsFlutterBinding.ensureInitialized();
print(tag);
switch (tag) {
case "simple_button":
case "updated_simple_button":
SystemAlertWindow.closeSystemWindow(prefMode: SystemWindowPrefMode.OVERLAY);
break;
case "focus_button":
print("Focus button has been called");
break;
default:
print("OnClick event of $tag");
}
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
bool _isShowingWindow = false;
bool _isUpdatedWindow = false;
SystemWindowPrefMode prefMode = SystemWindowPrefMode.OVERLAY;
#override
void initState() {
super.initState();
_initPlatformState();
_requestPermissions();
SystemAlertWindow.registerOnClickListener(callBack);
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> _initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await SystemAlertWindow.platformVersion;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
Future<void> _requestPermissions() async {
await SystemAlertWindow.requestPermissions(prefMode: prefMode);
}
void _showOverlayWindow() {
if (!_isShowingWindow) {
SystemWindowHeader header = SystemWindowHeader(
title: SystemWindowText(text: "Incoming Call", fontSize: 10, textColor: Colors.black45),
padding: SystemWindowPadding.setSymmetricPadding(12, 12),
subTitle: SystemWindowText(text: "9898989899", fontSize: 14, fontWeight: FontWeight.BOLD, textColor: Colors.black87),
decoration: SystemWindowDecoration(startColor: Colors.grey[100]),
button: SystemWindowButton(text: SystemWindowText(text: "Personal", fontSize: 10, textColor: Colors.black45), tag: "personal_btn"),
buttonPosition: ButtonPosition.TRAILING);
SystemWindowBody body = SystemWindowBody(
rows: [
EachRow(
columns: [
EachColumn(
text: SystemWindowText(text: "Some body", fontSize: 12, textColor: Colors.black45),
),
],
gravity: ContentGravity.CENTER,
),
EachRow(columns: [
EachColumn(
text: SystemWindowText(text: "Long data of the body", fontSize: 12, textColor: Colors.black87, fontWeight: FontWeight.BOLD),
padding: SystemWindowPadding.setSymmetricPadding(6, 8),
decoration: SystemWindowDecoration(startColor: Colors.black12, borderRadius: 25.0),
margin: SystemWindowMargin(top: 4)),
], gravity: ContentGravity.CENTER),
EachRow(
columns: [
EachColumn(
text: SystemWindowText(text: "Notes", fontSize: 10, textColor: Colors.black45),
),
],
gravity: ContentGravity.LEFT,
margin: SystemWindowMargin(top: 8),
),
EachRow(
columns: [
EachColumn(
text: SystemWindowText(text: "Some random notes.", fontSize: 13, textColor: Colors.black54, fontWeight: FontWeight.BOLD),
),
],
gravity: ContentGravity.LEFT,
),
],
padding: SystemWindowPadding(left: 16, right: 16, bottom: 12, top: 12),
);
SystemWindowFooter footer = SystemWindowFooter(
buttons: [
SystemWindowButton(
text: SystemWindowText(text: "Simple button", fontSize: 12, textColor: Color.fromRGBO(250, 139, 97, 1)),
tag: "simple_button",
padding: SystemWindowPadding(left: 10, right: 10, bottom: 10, top: 10),
width: 0,
height: SystemWindowButton.WRAP_CONTENT,
decoration: SystemWindowDecoration(startColor: Colors.white, endColor: Colors.white, borderWidth: 0, borderRadius: 0.0),
),
SystemWindowButton(
text: SystemWindowText(text: "Focus button", fontSize: 12, textColor: Colors.white),
tag: "focus_button",
width: 0,
padding: SystemWindowPadding(left: 10, right: 10, bottom: 10, top: 10),
height: SystemWindowButton.WRAP_CONTENT,
decoration: SystemWindowDecoration(
startColor: Color.fromRGBO(250, 139, 97, 1), endColor: Color.fromRGBO(247, 28, 88, 1), borderWidth: 0, borderRadius: 30.0),
)
],
padding: SystemWindowPadding(left: 16, right: 16, bottom: 12),
decoration: SystemWindowDecoration(startColor: Colors.white),
buttonsPosition: ButtonPosition.CENTER);
SystemAlertWindow.showSystemWindow(
height: 230,
header: header,
body: body,
footer: footer,
margin: SystemWindowMargin(left: 8, right: 8, top: 200, bottom: 0),
gravity: SystemWindowGravity.TOP,
notificationTitle: "Incoming Call",
notificationBody: "+1 646 980 4741",
prefMode: prefMode);
setState(() {
_isShowingWindow = true;
});
} else if (!_isUpdatedWindow) {
SystemWindowHeader header = SystemWindowHeader(
title: SystemWindowText(text: "Outgoing Call", fontSize: 10, textColor: Colors.black45),
padding: SystemWindowPadding.setSymmetricPadding(12, 12),
subTitle: SystemWindowText(text: "8989898989", fontSize: 14, fontWeight: FontWeight.BOLD, textColor: Colors.black87),
decoration: SystemWindowDecoration(startColor: Colors.grey[100]),
button: SystemWindowButton(text: SystemWindowText(text: "Personal", fontSize: 10, textColor: Colors.black45), tag: "personal_btn"),
buttonPosition: ButtonPosition.TRAILING);
SystemWindowBody body = SystemWindowBody(
rows: [
EachRow(
columns: [
EachColumn(
text: SystemWindowText(text: "Updated body", fontSize: 12, textColor: Colors.black45),
),
],
gravity: ContentGravity.CENTER,
),
EachRow(columns: [
EachColumn(
text: SystemWindowText(text: "Updated long data of the body", fontSize: 12, textColor: Colors.black87, fontWeight: FontWeight.BOLD),
padding: SystemWindowPadding.setSymmetricPadding(6, 8),
decoration: SystemWindowDecoration(startColor: Colors.black12, borderRadius: 25.0),
margin: SystemWindowMargin(top: 4)),
], gravity: ContentGravity.CENTER),
EachRow(
columns: [
EachColumn(
text: SystemWindowText(text: "Notes", fontSize: 10, textColor: Colors.black45),
),
],
gravity: ContentGravity.LEFT,
margin: SystemWindowMargin(top: 8),
),
EachRow(
columns: [
EachColumn(
text: SystemWindowText(text: "Updated random notes.", fontSize: 13, textColor: Colors.black54, fontWeight: FontWeight.BOLD),
),
],
gravity: ContentGravity.LEFT,
),
],
padding: SystemWindowPadding(left: 16, right: 16, bottom: 12, top: 12),
);
SystemWindowFooter footer = SystemWindowFooter(
buttons: [
SystemWindowButton(
text: SystemWindowText(text: "Updated Simple button", fontSize: 12, textColor: Color.fromRGBO(250, 139, 97, 1)),
tag: "updated_simple_button",
padding: SystemWindowPadding(left: 10, right: 10, bottom: 10, top: 10),
width: 0,
height: SystemWindowButton.WRAP_CONTENT,
decoration: SystemWindowDecoration(startColor: Colors.white, endColor: Colors.white, borderWidth: 0, borderRadius: 0.0),
),
SystemWindowButton(
text: SystemWindowText(text: "Focus button", fontSize: 12, textColor: Colors.white),
tag: "focus_button",
width: 0,
padding: SystemWindowPadding(left: 10, right: 10, bottom: 10, top: 10),
height: SystemWindowButton.WRAP_CONTENT,
decoration: SystemWindowDecoration(
startColor: Color.fromRGBO(250, 139, 97, 1), endColor: Color.fromRGBO(247, 28, 88, 1), borderWidth: 0, borderRadius: 30.0),
)
],
padding: SystemWindowPadding(left: 16, right: 16, bottom: 12),
decoration: SystemWindowDecoration(startColor: Colors.white),
buttonsPosition: ButtonPosition.CENTER);
SystemAlertWindow.updateSystemWindow(
height: 230,
header: header,
body: body,
footer: footer,
margin: SystemWindowMargin(left: 8, right: 8, top: 200, bottom: 0),
gravity: SystemWindowGravity.TOP,
notificationTitle: "Outgoing Call",
notificationBody: "+1 646 980 4741",
prefMode: prefMode);
setState(() {
_isUpdatedWindow = true;
});
} else {
setState(() {
_isShowingWindow = false;
_isUpdatedWindow = false;
});
SystemAlertWindow.closeSystemWindow(prefMode: prefMode);
}
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('System Alert Window Example App'),
),
body: Center(
child: Column(
children: <Widget>[
Text('Running on: $_platformVersion\n'),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: MaterialButton(
onPressed: _showOverlayWindow,
textColor: Colors.white,
child: !_isShowingWindow
? Text("Show system alert window")
: !_isUpdatedWindow
? Text("Update system alert window")
: Text("Close system alert window"),
color: Colors.deepOrange,
padding: const EdgeInsets.symmetric(vertical: 8.0),
),
)
],
),
),
),
);
}
}
With this You can Have the Floating Panel Option . You can Establish your Logic According to your functionality .
thanks
Related
My dropdown list has a multi-select feature. I have shown the list and selected Items are saved in an array called selectedClassList. Basically, it's a normal checkbox procedure.
But in the scenario of clicking a value called "any", I need to unselect all other items and need to mark "Any" as selected. The same is for other items, when a user clicks any of the other items, then item "any" should get unselected.
My code is like
DropdownButtonFormField2<dynamic>(
itemHeight: 40,
dropdownOverButton: false,
buttonWidth: double.infinity,
selectedItemHighlightColor: Colors.grey.shade300,
isExpanded: true,
value: widget.value,
dropdownElevation: 0,
itemPadding: const EdgeInsets.only(left: 15),
buttonDecoration: BoxDecoration(
border: Border.all(color: Colors.black87, width: 1),
borderRadius: BorderRadius.circular(5),
),
decoration: const InputDecoration.collapsed(
hintText: '',
border: InputBorder.none,
),
isDense: true,
offset: const Offset(0, -2),
iconSize: 20,
buttonHeight: 50,
buttonPadding: const EdgeInsets.only(left: 15, right: 10),
focusColor: const Color(0xffFFFFFF),
hint: const Text('Select One',
style: TextStyle(
fontSize: 14,
fontFamily: 'Poppins, Regular',
color: Color(0xffAAAAAA))),
style: const TextStyle(
fontSize: 14,
fontFamily: 'Poppins, Regular',
overflow: TextOverflow.ellipsis,
color: Color(0xff121212)),
iconOnClick: AnimatedRotation(
turns: 0.5,
duration: const Duration(milliseconds: 300),
child: Icon(Icons.arrow_down),
),
icon: AnimatedRotation(
turns: 1,
duration: const Duration(milliseconds: 300),
child: Icon(Icons.arrow_up),
),
dropdownDecoration: BoxDecoration(
border: Border.all(
color: Colors.black45,
width: 1,
),
borderRadius: const BorderRadius.all(Radius.circular(5)),
shape: BoxShape.rectangle),
dropdownMaxHeight: 200,
items: getClassDetails.data?.map((item) {
return DropdownMenuItem<dynamic>(
value: item,
enabled: false,
child: StatefulBuilder(
builder: (context, menuSetState) {
var _isSelected = selectedClass!
.where((element) =>
element.settingName == item.settingName)
.toList()
.isNotEmpty;
return InkWell(
onTap: () {
if (item.settingName == "Any") {
selectedClass!.clear();
}
if (_isSelected == true) {
selectedClass!.remove(item);
} else {
selectedClass!.add(item);
}
setState(() {});
menuSetState(() {});
},
child: Row(
children: [
_isSelected
? const Icon(Icons.check_box_outlined)
: const Icon(Icons.check_box_outline_blank),
const SizedBox(width: 16),
Text(
item.settingName.toString(),
style: const TextStyle(
fontSize: 14,
fontFamily: 'Poppins, Regular',
color: Color(0xff121212)),
),
],
),
);
},
),
);
}).toList(),
)
I am not good at explaining things. Kindly let me know if I made any mistake.
I am making a simple weather application, with the OpenWeather API, and it throws me the following error:
"The following _CastError was thrown building FutureBuilder(dirty, state: _FutureBuilderState#9133d): type '_Type' is not a subtype of type 'Weather?' in type cast"
The Code is the following:
Future getForecast(Location location) async {
Forecast forecast;
String apiKey = "117bf0ee07134176cf271f0ad49f3807";
String lat = location.lat;
String lon = location.lon;
var url =
"https://api.openweathermap.org/data/2.5/onecall?lat=$lat&lon=$lon&appid=$apiKey&units=metric";
final response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
forecast = Forecast.fromJson(jsonDecode(response.body));
}
return _forecast;
}
class _forecast {
}
This is my complete code:
class CurrentWeatherPage extends StatefulWidget {
final List<Location> locations;
final BuildContext context;
const CurrentWeatherPage(this.locations, this.context);
#override
_CurrentWeatherPageState createState() =>
_CurrentWeatherPageState(this.locations, this.context);
}
class _CurrentWeatherPageState extends State<CurrentWeatherPage> {
final List<Location> locations;
Location location;
final BuildContext context;
_CurrentWeatherPageState(List<Location> locations, BuildContext context)
: this.locations = locations,
this.context = context,
this.location = locations[0];
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color.fromRGBO(241, 254, 252, 1),
appBar: AppBar(
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Datos ",
style: TextStyle(fontSize: 22),
),
Text(
"Meteorológicos",
style: TextStyle(fontSize: 22, color: Color.fromRGBO(56, 215, 199, 1)),
)
],
),
backgroundColor: Color.fromRGBO(10, 45, 66, 0.9),
),
body: ListView(children: <Widget>[
currentWeatherViews(this.locations, this.location, this.context),
forcastViewsHourly(this.location),
forcastViewsDaily(this.location),
]),
);
}
void _changeLocation(Location newLocation) {
setState(() {
location = newLocation;
});
}
Widget currentWeatherViews(
List<Location> locations, Location location, BuildContext context) {
Weather? _weather;
return FutureBuilder(
builder: (context, snapshot) {
if (snapshot.hasData) {
_weather = snapshot.data as Weather?;
if (_weather == null) {
return Text("Error getting weather");
} else {
return Column(children: [
createAppBar(locations, location, context),
// CityDropDown(locations),
weatherBox(_weather!),
weatherDetailsBox(_weather!),
]);
}
} else {
return Center(child: CircularProgressIndicator());
}
},
future: getCurrentWeather(location),
);
}
Widget forcastViewsHourly(Location location) {
Forecast? _forcast;
return FutureBuilder(
builder: (context, snapshot) {
if (snapshot.hasData) {
_forcast = snapshot.data as Forecast?;
if (_forcast == null) {
return Text("Error getting weather");
} else {
return hourlyBoxes(_forcast!);
}
} else {
return Center(child: CircularProgressIndicator());
}
},
future: getForecast(location),
);
}
Widget forcastViewsDaily(Location location) {
Forecast? _forcast;
return FutureBuilder(
builder: (context, snapshot) {
if (snapshot.hasData) {
_forcast = snapshot.data as Forecast?;
if (_forcast == null) {
return Text("Error getting weather");
} else {
return dailyBoxes(_forcast!);
}
} else {
return Center(child: CircularProgressIndicator());
}
},
future: getForecast(location),
);
}
Widget createAppBar(
List<Location> locations, Location location, BuildContext context) {
// Location dropdownValue = locations.first;
return Container(
padding:
const EdgeInsets.only(left: 20, top: 15, bottom: 15, right: 20),
margin: const EdgeInsets.only(
top: 35, left: 15.0, bottom: 15.0, right: 15.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(60)),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3),
)
]),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
DropdownButton<Location>(
value: location,
icon: Icon(
Icons.keyboard_arrow_down_rounded,
color: Colors.black,
size: 24.0,
semanticLabel: 'Tap to change location',
),
elevation: 16,
underline: Container(
height: 0,
color: Color.fromRGBO(10, 45, 66, 0.9),
),
onChanged: (newLocation) {
// callback(newValue);
// setState(() {
// location = newValue;
// });
var changeLocation = newLocation;
},
items:
locations.map<DropdownMenuItem<Location>>((Location value) {
return DropdownMenuItem<Location>(
value: value,
child: Text.rich(
TextSpan(
children: <TextSpan>[
TextSpan(
text: '${value.city.capitalizeFirstOfEach}, ',
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 16)),
TextSpan(
text: '${value.country.capitalizeFirstOfEach}',
style: TextStyle(
fontWeight: FontWeight.normal, fontSize: 16)),
],
),
),
);
}).toList(),
),
],
));
}
Widget weatherDetailsBox(Weather _weather) {
return Container(
padding: const EdgeInsets.only(left: 15, top: 25, bottom: 25, right: 15),
margin: const EdgeInsets.only(left: 15, top: 5, bottom: 15, right: 15),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(20)),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3),
)
]),
child: Row(
children: [
Expanded(
child: Column(
children: [
Container(
child: Text(
"Viento",
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 12,
color: Colors.grey),
)),
Container(
child: Text(
"${_weather.wind} km/h",
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 15,
color: Colors.black),
))
],
)),
Expanded(
child: Column(
children: [
Container(
child: Text(
"Humedad",
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 12,
color: Colors.grey),
)),
Container(
child: Text(
"${_weather.humidity.toInt()}%",
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 15,
color: Colors.black),
))
],
)),
Expanded(
child: Column(
children: [
Container(
child: Text(
"Presión atmosférica",
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 12,
color: Colors.black45),
)),
Container(
child: Text(
"${_weather.pressure} hPa",
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 15,
color: Colors.black),
))
],
))
],
),
);
}
Widget weatherBox(Weather _weather) {
return Stack(children: [
Container(
padding: const EdgeInsets.all(15.0),
margin: const EdgeInsets.all(15.0),
height: 160.0,
decoration: BoxDecoration(
color: Color.fromRGBO(55, 187, 174, 1),
borderRadius: BorderRadius.all(Radius.circular(20))),
),
ClipPath(
clipper: Clipper(),
child: Container(
padding: const EdgeInsets.all(15.0),
margin: const EdgeInsets.all(15.0),
height: 160.0,
decoration: BoxDecoration(
color: Color.fromRGBO(198, 9, 125, 1),
borderRadius: BorderRadius.all(Radius.circular(20))))),
Container(
padding: const EdgeInsets.all(15.0),
margin: const EdgeInsets.all(15.0),
height: 160.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20))),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
getWeatherIcon(_weather.icon),
Container(
margin: const EdgeInsets.all(5.0),
child: Text(
"${_weather.description.capitalizeFirstOfEach}",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 16,
color: Colors.white),
)),
Container(
margin: const EdgeInsets.all(5.0),
child: Text(
"Máxima:${_weather.high.toInt()}° Mínima:${_weather.low.toInt()}°",
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 13,
color: Colors.white),
)),
])),
Column(children: <Widget>[
Container(
child: Text(
"${_weather.temp.toInt()}°",
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 60,
color: Colors.white),
)),
Container(
margin: const EdgeInsets.all(0),
child: Text(
"Sensación térmica ${_weather.feelsLike.toInt()}°",
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 13,
color: Colors.white),
)),
])
],
))
]);
}
Image getWeatherIcon(String _icon) {
String path = 'assets/icons/';
String imageExtension = ".png";
return Image.asset(
path + _icon + imageExtension,
width: 70,
height: 70,
);
}
Image getWeatherIconSmall(String _icon) {
String path = 'assets/icons/';
String imageExtension = ".png";
return Image.asset(
path + _icon + imageExtension,
width: 40,
height: 40,
);
}
Widget hourlyBoxes(Forecast _forecast) {
return Container(
margin: EdgeInsets.symmetric(vertical: 0.0),
height: 150.0,
child: ListView.builder(
padding:
const EdgeInsets.only(left: 8, top: 0, bottom: 0, right: 8),
scrollDirection: Axis.horizontal,
itemCount: _forecast.hourly.length,
itemBuilder: (BuildContext context, int index) {
return Container(
padding: const EdgeInsets.only(
left: 10, top: 15, bottom: 15, right: 10),
margin: const EdgeInsets.all(5),
decoration: BoxDecoration(
color: Color.fromRGBO(1, 68, 109, 1),
borderRadius: BorderRadius.all(Radius.circular(18)),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
spreadRadius: 2,
blurRadius: 2,
offset: Offset(0, 1), // changes position of shadow
)
]),
child: Column(children: [
Text(
"${_forecast.hourly[index].temp}°",
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 17,
color: Color.fromRGBO(56, 215, 199, 1)),
),
getWeatherIcon(_forecast.hourly[index].icon),
Text(
"${getTimeFromTimestamp(_forecast.hourly[index].dt)}",
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 12,
color: Colors.white),
),
]));
}));
}
String getTimeFromTimestamp(int timestamp) {
var date = new DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
var formatter = new DateFormat('h:mm a');
return formatter.format(date);
}
String getDateFromTimestamp(int timestamp) {
var date = new DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
var formatter = new DateFormat('E');
return formatter.format(date);
}
Widget dailyBoxes(Forecast _forcast) {
return Expanded(
child: ListView.builder(
shrinkWrap: true,
physics: ClampingScrollPhysics(),
padding:
const EdgeInsets.only(left: 8, top: 0, bottom: 0, right: 8),
itemCount: _forcast.daily.length,
itemBuilder: (BuildContext context, int index) {
return Container(
decoration: BoxDecoration(
color: Color.fromRGBO(1, 68, 109, 1),
borderRadius: BorderRadius.circular(10),
),
padding: const EdgeInsets.only(
left: 10, top: 5, bottom: 5, right: 10),
margin: const EdgeInsets.all(5),
child: Row(children: [
Expanded(
child: Text(
"${getDateFromTimestamp(_forcast.daily[index].dt)}",
style: TextStyle(fontSize: 14, color: Color.fromRGBO(56, 215, 199, 1)),
)),
Expanded(
child: getWeatherIconSmall(_forcast.daily[index].icon)),
Expanded(
child: Text(
"${_forcast.daily[index].high.toInt()}/${_forcast.daily[index].low.toInt()}",
textAlign: TextAlign.right,
style: TextStyle(fontSize: 14, color: Colors.white),
)),
]));
}));
}
}
class Clipper extends CustomClipper<Path> {
#override
Path getClip(Size size) {
Path path = Path();
path.moveTo(0, size.height - 20);
path.quadraticBezierTo((size.width / 6) * 1, (size.height / 2) + 15,
(size.width / 3) * 1, size.height - 30);
path.quadraticBezierTo((size.width / 2) * 1, (size.height + 0),
(size.width / 3) * 2, (size.height / 4) * 3);
path.quadraticBezierTo((size.width / 6) * 5, (size.height / 2) - 20,
size.width, size.height - 60);
path.lineTo(size.width, size.height - 60);
path.lineTo(size.width, size.height);
path.lineTo(0, size.height);
path.close();
return path;
}
#override
bool shouldReclip(Clipper oldClipper) => false;
}
Future getCurrentWeather(Location location) async {
Weather weather;
String city = location.city;
String apiKey = "117bf0ee07134176cf271f0ad49f3807";
var url =
"https://api.openweathermap.org/data/2.5/weather?q=$city&appid=$apiKey&units=metric";
final response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
weather = Weather.fromJson(jsonDecode(response.body));
}
return _weather;
}
class _weather {
}
Future getForecast(Location location) async {
Forecast forecast;
String apiKey = "117bf0ee07134176cf271f0ad49f3807";
String lat = location.lat;
String lon = location.lon;
var url =
"https://api.openweathermap.org/data/2.5/onecall?lat=$lat&lon=$lon&appid=$apiKey&units=metric";
final response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
forecast = Forecast.fromJson(jsonDecode(response.body));
}
return _forecast;
}
class _forecast {
}
I'm new to this, and I've tried many ways, but I can't get it to work. I would be grateful if someone could tell me the error and how to solve it. Thank you!
In your getCurrentWeather method, you assign the return value of the API call to weather, a local variable, but then continue to return _weather, a class not a variable. I don't know why it compiles even, probably because you did not use proper types.
I'll clean up one of the methods, please do the same with all of them where you may have done this. This is how your method should look like:
Future<Weather?> getCurrentWeather(Location location) async {
String city = location.city;
String apiKey = "117bf0ee07134176cf271f0ad49f3807";
var url =
"https://api.openweathermap.org/data/2.5/weather?q=$city&appid=$apiKey&units=metric";
final response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
return Weather.fromJson(jsonDecode(response.body));
}
return null;
}
Just a few random other remarks: the future should be a state variable, not called recreated every time build is called. This will happen if you put the call int the FutureBuilder directly. You pass a BuildContext through your class hierarchy. You should not need that. Just remove it altogether.
I'm trying to set margin/padding top for the list of items that come in dropdown button when clicked. How to set padding for dropdown button.
After clicking dropdown button I get the items on top of the view like this,
I need to get the items below the dropdown button.
I tried giving padding inside a container but only the dropdown button seems to be moving and not the items in it.
Is there a solution for this?
Code for reference,
ButtonTheme(
alignedDropdown: true,
padding: EdgeInsets.only(left: 0.0, right: 0.0, top: 100, bottom: 0.0),
child:
DropdownButton(
menuMaxHeight: 300.0,
hint: _dropDownValue == null
? Text("---SELECT---", style: TextStyle(color: Colors.black))
:
Text(
_dropDownValue,
style: TextStyle(color: Colors.blue, fontSize: 20),
),
isExpanded: true,
iconSize: 30.0,
icon: Icon(Icons.arrow_drop_down_circle),
iconDisabledColor: Colors.red,
iconEnabledColor: Colors.green,
style: TextStyle(color: Colors.black),
dropdownColor: Colors.white,
items: answer.map(
(val) {
return DropdownMenuItem<String>(
value: val,
child: Text(val),
);
},
).toList(),
onChanged: (val) {
setState(
() {
_dropDownValue = val;
},
);
},
),
),
Try below code hope its helpful to you . you must used dropdown_below from here
Create your list
List numberList = [
{'no': 1, 'number': '1'},
{'no': 2, 'number': '2'},
{'no': 3, 'number': '3'},
{'no': 4, 'number': '4'},
{'no': 5, 'number': '5'},
{'no': 6, 'number': '6'},
{'no': 7, 'number': '7'},
{'no': 8, 'number': '8'},
{'no': 9, 'number': '9'},
];
One varibale and list our value
List<DropdownMenuItem<Object?>> _dropdownTestItems = [];
var selectedNumber;
Create initState() and dispose() method:
#override
void initState() {
_dropdownTestItems = buildDropdownTestItems(numberList);
super.initState();
}
#override
void dispose() {
super.dispose();
}
Add your selected number value in dropdown
List<DropdownMenuItem<Object?>> buildDropdownTestItems(List numberList) {
List<DropdownMenuItem<Object?>> items = [];
for (var i in numberList) {
items.add(
DropdownMenuItem(
value: i,
child: Text(
i['number'],
style: TextStyle(color: Colors.black),
),
),
);
}
return items;
}
Your Widget:
Padding(
padding: const EdgeInsets.all(8.0),
child: DropdownBelow(
itemWidth: 100,
itemTextstyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w400,
color: Colors.black),
boxTextstyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w400,
color: Colors.white54),
boxPadding: EdgeInsets.fromLTRB(13, 12, 13, 12),
boxWidth: 100,
boxHeight: 45,
boxDecoration: BoxDecoration(
color: Colors.transparent,
border: Border.all(
width: 1,
color: Colors.black,
),
),
icon: Icon(
Icons.arrow_downward,
color: Colors.black,
),
hint: Text(
'Select',
style: TextStyle(
color: Colors.black,
),
),
value: selectedNumber,
items: _dropdownTestItems,
onChanged: (selectedTest) {
setState(() {
selectedNumber = selectedTest;
});
},
),
),
Your result screen->
I am Trying to pass a function to a static callback, i have added the code below.
I am using a plugin like system alert window that is the call back, it has a tag with is pass to button. the same as system Alert window, to draw over other app, the draw over screen has a button(the static call Back function). i am trying to pass a function to this call call back so that when the button is pressed it is able to perform something inside the app
This is the Alert window body code with the button. The button doesnt have an onpresse function, instead it is identified by a string tag.
final header = float.FloatyHeadHeader(
title: float.FloatyHeadText(
text: "Ongoing Ride",
fontSize: 12,
textColor: Colors.black45,
fontWeight: float.FontWeight.normal,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
padding: float.FloatyHeadPadding.setSymmetricPadding(12, 12),
subTitle: float.FloatyHeadText(
text: 'Name $riderName',
fontSize: 16,
fontWeight: float.FontWeight.bold,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
textColor: Colors.black87,
),
decoration: float.FloatyHeadDecoration(startColor: Colors.grey[100]),
button: float.FloatyHeadButton(
text: float.FloatyHeadText(
fontWeight: float.FontWeight.bold,
text: "Personal",
fontSize: 10,
textColor: Colors.black45,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
tag: "personal_btn"),
);
final body = float.FloatyHeadBody(
rows: [
float.EachRow(
columns: [
float.EachColumn(
text: float.FloatyHeadText(
fontWeight: float.FontWeight.bold,
text: "Updated body $pickUpAdd",
fontSize: 12,
textColor: Colors.black45,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
),
],
gravity: float.ContentGravity.center,
),
float.EachRow(columns: [
float.EachColumn(
text: float.FloatyHeadText(
text: "Updated long data of the body",
fontSize: 12,
textColor: Colors.black87,
fontWeight: float.FontWeight.bold,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
padding: float.FloatyHeadPadding.setSymmetricPadding(6, 8),
decoration: float.FloatyHeadDecoration(
startColor: Colors.black12, borderRadius: 25.0),
margin: float.FloatyHeadMargin(top: 4),
),
], gravity: float.ContentGravity.center),
float.EachRow(
columns: [
float.EachColumn(
text: float.FloatyHeadText(
text: "Notes",
fontSize: 10,
textColor: Colors.black45,
fontWeight: float.FontWeight.normal,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
),
],
gravity: float.ContentGravity.left,
margin: float.FloatyHeadMargin(top: 8),
),
float.EachRow(
columns: [
float.EachColumn(
text: float.FloatyHeadText(
text: "Updated random notes.",
fontSize: 13,
textColor: Colors.black54,
fontWeight: float.FontWeight.bold,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
),
],
gravity: float.ContentGravity.left,
),
],
padding: float.FloatyHeadPadding(left: 16, right: 16, bottom: 12, top: 12),
);
final footer = FloatyHeadFooter(
buttons: [
float.FloatyHeadButton(
text: float.FloatyHeadText(
text: "Simple button",
fontSize: 12,
textColor: Color.fromRGBO(250, 139, 97, 1),
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
fontWeight: float.FontWeight.normal,
),
tag: "simple_button",
padding: float.FloatyHeadPadding(left: 10, right: 10, bottom: 10, top: 10),
width: 0,
height: float.FloatyHeadButton.WRAP_CONTENT,
decoration: float.FloatyHeadDecoration(
startColor: Colors.white,
endColor: Colors.white,
borderWidth: 0,
borderRadius: 0.0),
),
float.FloatyHeadButton(
text: float.FloatyHeadText(
fontWeight: float.FontWeight.normal,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
text: "Focus button",
fontSize: 12,
textColor: Colors.white,
),
tag: "focus_button",
width: 0,
padding: float.FloatyHeadPadding(left: 10, right: 10, bottom: 10, top: 10),
height: float.FloatyHeadButton.WRAP_CONTENT,
decoration: float.FloatyHeadDecoration(
startColor: Color.fromRGBO(250, 139, 97, 1),
endColor: Color.fromRGBO(247, 28, 88, 1),
borderWidth: 0,
borderRadius: 30.0),
)
],
padding: float.FloatyHeadPadding(left: 16, right: 16, bottom: 12),
decoration: float.FloatyHeadDecoration(startColor: Colors.white),
buttonsPosition: float.ButtonPosition.center,
);
Here is the call back containing the String tag for the button, when i click the button it prints out the result but i unable to pass a woking function to the button.
static void floatCallBack(String tag) {
print('CALLBACK FROM FRAGMENT BUILDED: $tag');
switch (tag) {
case "simple_button":
// float.callback;Dispatcher();
print('CALLBACK-FROM Static void: $tag');
break;
case "updated_simple_button":
break;
case "focus_button":
print("Focus button has been called");
break;
default:
print("OnClick event of $tag");
}
}
Here is an example of the function i want to pass to the alert window button.
void openInstalledMapToPickUp(){
double destiLat = widget.rideDetails.pickUpLat;
double destLng = widget.rideDetails.pickUpLng;
MapsSheet.show(
context: context,
onMapTap: (map) {
map.showDirections(
destination: mapLaunch.Coords(
destiLat,
destLng,
),
destinationTitle: 'Drop off Location',
origin: mapLaunch.Coords(
currentPosition.latitude,
currentPosition.longitude,
),
originTitle: "My Current Location",
// waypoints: waypoints,
directionsMode: directionsMode,
);
},
);
// print('pickup $startLat');
// print('pickup $startLng');
print('dropoff lat $destiLat');
print('dropoff lat $destLng ');
}
Here is a full code, on the page i have a Raised button which works as expexted, i would also like to pass to have the alertwindow button do thesame thing the raised button does
class NewRideScreen extends StatefulWidget
{
#override
_NewRideScreenState createState() => _NewRideScreenState();
}
class _NewRideScreenState extends State<NewRideScreen> with TickerProviderStateMixin
{
final float.FloatyHead floatyHead = float.FloatyHead();
final header = float.FloatyHeadHeader(
title: float.FloatyHeadText(
text: "Ongoing Ride",
fontSize: 12,
textColor: Colors.black45,
fontWeight: float.FontWeight.normal,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
padding: float.FloatyHeadPadding.setSymmetricPadding(12, 12),
subTitle: float.FloatyHeadText(
text: 'Name $riderName',
fontSize: 16,
fontWeight: float.FontWeight.bold,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
textColor: Colors.black87,
),
decoration: float.FloatyHeadDecoration(startColor: Colors.grey[100]),
button: float.FloatyHeadButton(
text: float.FloatyHeadText(
fontWeight: float.FontWeight.bold,
text: "Personal",
fontSize: 10,
textColor: Colors.black45,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
tag: "personal_btn"),
);
final body = float.FloatyHeadBody(
rows: [
float.EachRow(
columns: [
float.EachColumn(
text: float.FloatyHeadText(
fontWeight: float.FontWeight.bold,
text: "Updated body $pickUpAdd",
fontSize: 12,
textColor: Colors.black45,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
),
],
gravity: float.ContentGravity.center,
),
float.EachRow(columns: [
float.EachColumn(
text: float.FloatyHeadText(
text: "Updated long data of the body",
fontSize: 12,
textColor: Colors.black87,
fontWeight: float.FontWeight.bold,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
padding: float.FloatyHeadPadding.setSymmetricPadding(6, 8),
decoration: float.FloatyHeadDecoration(
startColor: Colors.black12, borderRadius: 25.0),
margin: float.FloatyHeadMargin(top: 4),
),
], gravity: float.ContentGravity.center),
float.EachRow(
columns: [
float.EachColumn(
text: float.FloatyHeadText(
text: "Notes",
fontSize: 10,
textColor: Colors.black45,
fontWeight: float.FontWeight.normal,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
),
],
gravity: float.ContentGravity.left,
margin: float.FloatyHeadMargin(top: 8),
),
float.EachRow(
columns: [
float.EachColumn(
text: float.FloatyHeadText(
text: "Updated random notes.",
fontSize: 13,
textColor: Colors.black54,
fontWeight: float.FontWeight.bold,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
),
],
gravity: float.ContentGravity.left,
),
],
padding: float.FloatyHeadPadding(left: 16, right: 16, bottom: 12, top: 12),
);
final footer = FloatyHeadFooter(
buttons: [
float.FloatyHeadButton(
text: float.FloatyHeadText(
text: "Simple button",
fontSize: 12,
textColor: Color.fromRGBO(250, 139, 97, 1),
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
fontWeight: float.FontWeight.normal,
),
tag: "simple_button",
padding: float.FloatyHeadPadding(left: 10, right: 10, bottom: 10, top: 10),
width: 0,
height: float.FloatyHeadButton.WRAP_CONTENT,
decoration: float.FloatyHeadDecoration(
startColor: Colors.white,
endColor: Colors.white,
borderWidth: 0,
borderRadius: 0.0),
),
float.FloatyHeadButton(
text: float.FloatyHeadText(
fontWeight: float.FontWeight.normal,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
text: "Focus button",
fontSize: 12,
textColor: Colors.white,
),
tag: "focus_button",
width: 0,
padding: float.FloatyHeadPadding(left: 10, right: 10, bottom: 10, top: 10),
height: float.FloatyHeadButton.WRAP_CONTENT,
decoration: float.FloatyHeadDecoration(
startColor: Color.fromRGBO(250, 139, 97, 1),
endColor: Color.fromRGBO(247, 28, 88, 1),
borderWidth: 0,
borderRadius: 30.0),
)
],
padding: float.FloatyHeadPadding(left: 16, right: 16, bottom: 12),
decoration: float.FloatyHeadDecoration(startColor: Colors.white),
buttonsPosition: float.ButtonPosition.center,
);
String status = "accepted";
String arrivedStatus = 'ContinueTrip';
String onRideStatus = 'ContinueTrip';
String durationRide="";
bool isRequestingDirection = false;
String btnTitle = "Arrived";
String arrivedBtnTitle = "Continue Trip";
String onRideBtnTitle = "Continue Trip";
Color btnColor = Colors.black87;
Color arrivedBtnColor = Colors.green;
Color onRideBtnColor = Colors.green;
Timer timer;
int durationCounter = 0;
bool arrivedStat = false;
bool onRideStat = false;
bool statStat = false;
#override
void initState() {
super.initState();
Wakelock.enable();
float.FloatyHead.registerOnClickListener(floatCallBack);
}
static void floatCallBack(String tag) {
print('CALLBACK FROM FRAGMENT BUILDED: $tag');
switch (tag) {
case "simple_button":
// float.callback;Dispatcher();
print('CALLBACK-FROM Static void: $tag');
break;
case "updated_simple_button":
break;
case "focus_button":
print("Focus button has been called");
break;
default:
print("OnClick event of $tag");
}
}
void openInstalledMapToPickUp(){
double destiLat = widget.rideDetails.pickUpLat;
double destLng = widget.rideDetails.pickUpLng;
MapsSheet.show(
context: context,
onMapTap: (map) {
map.showDirections(
destination: mapLaunch.Coords(
destiLat,
destLng,
),
destinationTitle: 'Drop off Location',
origin: mapLaunch.Coords(
currentPosition.latitude,
currentPosition.longitude,
),
originTitle: "My Current Location",
// waypoints: waypoints,
directionsMode: directionsMode,
);
},
);
// print('pickup $startLat');
// print('pickup $startLng');
print('dropoff lat $destiLat');
print('dropoff lat $destLng ');
}
#override
Widget build(BuildContext context)
{
return new Scaffold(
body: Stack(
children: [
Positioned(
child: SlidingUpPanel(
minHeight: 110,
maxHeight: 400 ,
borderRadius: BorderRadius.only(topLeft: Radius.circular(16.0), topRight: Radius.circular(16.0)),
panel: Container(
height: 300.0,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 15.0, vertical: 18.0),
child: Column(
children: [
Container(
padding: EdgeInsets.only(top: 10, bottom: 10),
decoration: BoxDecoration(color: Colors.cyan[600],
borderRadius: BorderRadius.all(Radius.circular(40.0),),),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"${durationRide} to Destination",
style: TextStyle(fontSize: 15.0, fontFamily: "Brand Bold", color: Colors.white),
),
],
),
),
SizedBox(height: 8.0,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(widget.rideDetails.rider_name, style: TextStyle(fontFamily: "Brand Bold", fontSize: 20.0, fontWeight: FontWeight.w600),),
Text("R ${itemCount.toString()}"),
Column(
children: [
Text("Total Rides", style: TextStyle(fontSize: 12), ),
Text("${widget.rideDetails.totalTrip}", style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600), ),
],
),
],
),
SizedBox(height: 8.0,),
Divider(height: 2.0, thickness: 2.0,),
SizedBox(height: 8.0,),
Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: EdgeInsets.all(0.0),
child: MaterialButton(
onPressed: () {
launch(('tel://${widget.rideDetails.phone}'));
},
color: Colors.black,
textColor: Colors.white,
child: Icon(
Icons.call, color: Colors.white, size: 20.0,
),
padding: EdgeInsets.all(12),
shape: CircleBorder(),
),
),
],
),
),
SizedBox(height: 10.0,),
Divider(height: 2.0, thickness: 2.0,),
SizedBox(height: 10.0,),
Row(
children: [
Image.asset("images/pickicon.png", height: 16.0, width: 16.0,),
SizedBox(width: 18.0,),
Expanded(
child: Container(
child: Text(
widget.rideDetails.pickup_address,
style: TextStyle(fontSize: 14.0),
overflow: TextOverflow.visible,
),
),
),
],
),
SizedBox(height: 16.0,),
Row(
children: [
Image.asset("images/desticon.png", height: 16.0, width: 16.0,),
SizedBox(width: 10.0,),
Expanded(
child: Container(
child: Text(
widget.rideDetails.dropoff_address,
style: TextStyle(fontSize: 14.0),
overflow: TextOverflow.ellipsis,
),
),
),
],
),
SizedBox(height: 16.0,),
Visibility(
visible: statStat,
child:RaisedButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(24.0),
),
onPressed: () async
{
if(status == "accepted")
{
status = "arrived";
setState(() {
btnTitle = "Start Trip";
btnColor = Colors.cyan[600];
});
}
else if(status == "arrived")
{
status = "onride";
setState(() {
btnTitle = "End Trip";
btnColor = Colors.redAccent;
});
initTimer();
openInstalledMapToPickUp();
}
else if(status == "onride")
{
endTheTrip();
}
},
color: btnColor,
child: Padding(
padding: EdgeInsets.all(17.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(btnTitle, style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold, color: Colors.white),),
Icon(Icons.directions_car, color: Colors.white, size: 26.0,),
],
),
),
),
),
],
),
),
),
),
),
],
),
);
}
endTheTrip() async
void setCustomHeader() {
floatyHead.updateFloatyHeadContent(
header: header,
body: body,
footer: footer,
);
}
void openHead(){
if(openHeads == true){
setCustomHeader();
setCloseIcon();
setIcon();
floatyHead.openBubble();
setNotificationTitle();
setNotificationIcon();
//floatyHead.openBubble();
}
//else floatyHead.isOpen;
}
void closeFloatyHead() {
if (floatyHead.isOpen) {
floatyHead.closeHead();
}
}
Future<void> setNotificationTitle() async {
String result;
try {
result = await floatyHead
.setNotificationTitle("OH MY GOD! THEY KILL KENNY!!!");
} on PlatformException {
result = 'Failed to get icon.';
}
print('result: $result');
if (!mounted) return;
}
Future<void> setNotificationIcon() async {
String result;
String assetPath = "images/notificationIcon.png";
try {
result = await floatyHead.setNotificationIcon(assetPath);
print(result);
} on PlatformException {
result = 'Failed to get icon.';
print("failed: $result");
}
if (!mounted) return;
}
Future<void> setIcon() async {
String result;
String assetPath = "images/headIcon.png";
try {
result = await floatyHead.setIcon(assetPath);
print('result: $result');
} on PlatformException {
return;
//result = 'Failed to get icon.';
}
if (!mounted) return;
}
Future<void> setCloseIcon() async {
String assetPath = "images/closeIcon.png";
try {
await floatyHead.setCloseIcon(assetPath);
} on PlatformException {
return;
}
if (!mounted) return;
}
Future<void> setCloseIconBackground() async {
String assetPath = "assets/closeBg.png";
try {
await floatyHead.setCloseBackgroundIcon(assetPath);
} on PlatformException {
return;
}
if (!mounted) return;
}
}
I want to be able to pass onpressed or onTap function from the alert window button to my app, the plugin name is FLoaty_head github https://github.com/Crdzbird/floaty_chathead
pub.dev https://pub.dev/packages/floaty_head
Never post pictures, post your code, it'll be easier for anybody who is answering to work with your code, instead of having to type it out manually, which ultimately makes your chances of getting an answer slimmer.
Anyway, for your code, copy everything in the on pressed you pointed to, and create a new function, call it myFunction for example, and put it outside your widget build.
void myFunction ()async {
await Sharedpreferences...etc}
And in your onPressed:
onPressed: ()=>myFunction(),
Here I have a form like this. i want to change the value of the blue button week below when i swipe left or right of Calendar Week. What should i do guys ?. It can only changed when I clicked on the number
Here is the code I'm using:
import 'package:flutter/material.dart';
import 'package:myhumgupdate/App/Config/palette.dart';
import 'package:myhumgupdate/Widgets/dialog_loading.dart';
import 'package:myhumgupdate/giangvien/Screens/XemTKB/TKBTheoTuan/tkbtuan_viewmodel.dart';
import 'package:myhumgupdate/Widgets/calender_week.dart';
import 'package:myhumgupdate/giangvien/models/meeting.dart';
import 'package:myhumgupdate/giangvien/models/meetingdata_source.dart';
import 'package:stacked/stacked.dart';
import 'package:syncfusion_flutter_calendar/calendar.dart';
class TKBTuan extends StatefulWidget {
#override
_TKBTuanState createState() => _TKBTuanState();
}
final String _customTimeLabelText = 'Tiết';
class _TKBTuanState extends State<TKBTuan> {
#override
Widget build(BuildContext context) {
return ViewModelBuilder<TKBTuanViewModel>.reactive(
onModelReady: (model) => Future.delayed(Duration.zero,
() => DialogLoading.show(context, model.getTkbTuan(model.timeNow))),
builder: (context, TKBTuanViewModel model, child) => Column(
children: [
Row(
children: [
Expanded(
child: Container(
margin: EdgeInsets.only(
top: 18,
),
child: CalendarWeek(
calendarController: model.calendarController,
press: (DateTime date, _, __) {
model.getTkbTuan(date);
},
),
),
),
Container(
width: 40,
height: 56,
margin: EdgeInsets.only(right: 3),
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Palette.kPrimaryColor,
),
child: Center(
child: Text(
"Week ${model.week}",
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
),
),
],
),
Expanded(
child: SfCalendar(
view: CalendarView.week,
firstDayOfWeek: 1,
maxDate: DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day, 00, 45, 0),
minDate: DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day, 00, 45, 0),
headerHeight: 0,
viewHeaderHeight: 0,
dataSource: MeetingDataSource(model.getDataSource),
appointmentTimeTextFormat: 'hh:mm:ss a',
appointmentBuilder: appointmentBuilder,
initialDisplayDate: DateTime(DateTime.now().year,
DateTime.now().month, DateTime.now().day, 00, 45, 0),
monthViewSettings: MonthViewSettings(showAgenda: true),
timeSlotViewSettings: TimeSlotViewSettings(
startHour: 0,
endHour: 16,
timeFormat: _customTimeLabelText + " H",
timeIntervalHeight: 70,
timeTextStyle: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
)),
// selectionDecoration: BoxDecoration(
// color: Colors.transparent,
// border: Border.all(color: Colors.red, width: 1),
// borderRadius: const BorderRadius.all(Radius.circular(4)),
// shape: BoxShape.rectangle,
// ),
),
),
],
),
viewModelBuilder: () => TKBTuanViewModel());
}
}
Widget appointmentBuilder(BuildContext context,
CalendarAppointmentDetails calendarAppointmentDetails) {
final Meeting appointment = calendarAppointmentDetails.appointments.first;
return Container(
width: calendarAppointmentDetails.bounds.width,
height: calendarAppointmentDetails.bounds.height,
// color: appointment.background,
decoration: BoxDecoration(
color: appointment.background,
border: Border.all(
color: Colors.grey,
width: 0.5,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(2.0, 0, 0, 5.0),
child: Text(
appointment.eventName,
// textAlign: TextAlign.center,
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(2.0, 0, 0, 0),
child: Text(
"Phòng: ${appointment.subText}",
style: TextStyle(fontSize: 10, fontStyle: FontStyle.italic),
),
)
],
),
);
}
And if there is no way to change the value like that, what should I do and how can I change that?
In the Flutter Event Calendar, you can programmatically select the date using selectedDate property of the CalendarController.
Inside the state, initialize the calendar controller.
final CalendarController _calendarController= CalendarController();
Using onViewChanged callback of the Flutter event calendar, you can set the first date of visible dates as selected date.
child: SfCalendar(
view: CalendarView.month,
controller: _calendarController,
onViewChanged: viewChanged,
),
void viewChanged(ViewChangedDetails viewChangedDetails) {
SchedulerBinding.instance!.addPostFrameCallback((Duration duration) {
_calendarController.selectedDate = viewChangedDetails.visibleDates[0];
});
}
Wrap your Widget in GestureDetector and use onPanUpdate like this:
GestureDetector(onPanUpdate: (details) {
if (details.delta.dx > 0) {
// swiping in right direction
// update week number
}
});