How can I turn on/off WiFi programmatically in flutter?
wifi_iot: ^0.1.1 package use in pubspac
import 'package:wifi_iot/wifi_iot.dart';
RaisedButton( child: Text("Enable"), onPressed: () { setState(() { WiFiForIoTPlugin.setEnabled(true); }); }, ),
Related
I'm looking for approaches to play video Live Stream in Flutter.
I tested on Chewie and Video_player plugins. It works well on Android but doesn`t on IOS devices. And unfortunately, debug console is empty...
Here is working .m3u8 file I tried to play.
Here is a simple reproducer:
import 'package:video_player/video_player.dart';
import 'package:flutter/material.dart';
void main() => runApp(VideoApp());
class VideoApp extends StatefulWidget {
#override
_VideoAppState createState() => _VideoAppState();
}
class _VideoAppState extends State<VideoApp> {
VideoPlayerController _controller;
#override
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'https://streamvideo.luxnet.ua/news24/smil:news24.stream.smil/playlist.m3u8')
..addListener(() {
if (_controller.value.initialized) {
print(_controller.value.position);
}
})
..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
setState(() {});
});
}
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Video Demo',
home: Scaffold(
body: Center(
child: Stack(
children: <Widget>[
_controller.value.initialized
? AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
)
: Container()
],
)
),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.orange,
onPressed: () {
setState(() {
_controller.value.isPlaying
? _controller.pause()
: _controller.play();
});
},
child: Icon(
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
),
),
),
);
}
#override
void dispose() {
super.dispose();
_controller.dispose();
}
}
Maybe somebody has experience with playing Video Stream on IOS with Flutter? Thanks a lot! 🍺
The video_player plugin doesn't currently support the iOS simulators. Your code is likely working correctly on a physical device.
The problem is in:
if ([self duration] == 0) {
return;
}
It is in platform level FLTVideoPlayerPlugin.m . Line number 325. It seems like duration is zero for live videos. If you remove that part of code it should work.
When I click on the avatar and want to upload a photo, I need to choose to upload it from the gallery or take a photo. If you click to select from the gallery, everything works fine. But if you click to take a photo, the dialog box just closes and nothing happens.
Help I can not get rid of this problem!
My GitHub with project
import 'dart:io';
import 'package:logining/account_screen/button_countries.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
String imagePath = 'images/user.png';
class AccountScreen extends StatefulWidget {
_AccountScreenState createState() => _AccountScreenState();
}
class _AccountScreenState extends State<AccountScreen> {
imageSelectorGallery() async {
final File imageFile = await ImagePicker.pickImage(
source: ImageSource.gallery,
);
setState(() {
if (imageFile != null) imagePath = imageFile.path;
});
}
imageSelectorCamera() async {
final File imageFile = await ImagePicker.pickImage(
source: ImageSource.camera,
);
setState(() {
if (imageFile != null) imagePath = imageFile.path;
});
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('AvatarScreen'),
),
resizeToAvoidBottomPadding: false,
body: ListView(children: <Widget>[
Container(
child: Form(
child: Column(children: <Widget>[
SizedBox(
height: 30,
),
IconButton(
iconSize: 150,
icon: CircleAvatar(
backgroundImage: AssetImage(imagePath),
radius: 150,
),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
title: Text('Choise a method to save a image'),
actions: <Widget>[
FlatButton(
child: Text('Make a photo'),
onPressed: () {
Navigator.of(context).pop();
imageSelectorCamera();
},
),
FlatButton(
child: Text('Photo from gallery'),
onPressed: () {
Navigator.of(context).pop();
imageSelectorGallery();
},
),
],
));
}),
]),
),
),
File pubspeck.yaml
dependencies:
http: ^0.12.0
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
image_picker:
url_launcher: ^4.0.3
dev_dependencies:
flutter_test:
sdk: flutter
Provide permissions on the AndroidManifest.xml file.
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
I am using a WebviewScaffold. It works well, but now I want to hide the BottomNavigationBar and the AppBar on Scroll up. OnScroll down it should show the AppBar and BottomNavigationBar. Like it works in Chrome on iOS.
As I know I cant use a Sliver because
"Warning: The webview is not integrated in the widget tree, it is a native view on top of the flutter view. you won't be able to use snackbars, dialogs ..."
It would be Nice if somebody could help me.
Thanks in advance!
I found how to get ScrollParams.... But now I have to hide/show the AppBar and the BottomNavigationBar.
#override
void initState() {
// TODO: implement initState
super.initState();
_onScrollYChanged =
flutterWebViewPlugin.onScrollYChanged.listen((double x) {
if (mounted) {
print(_onScrollYChanged.toString());
setState(() {
if (_posY < x) {
_showBar = false;
print("DOWN");
} else {
_showBar = true;
print("UP");
}
_posY = x;
print("Scroll in Y Direction: $x");
});
}
});
}
My Build in my APP looks like this:
#override
Widget build(BuildContext context) {
return WebviewScaffold(
url: "https://www.domain.de",
appBar: AppBar(
toolbarOpacity: _showBar ? 1.0 : 0.0,
title: const Text('Widget WebView'),
leading: IconButton(
icon: Icon(Icons.apps),
onPressed: () {
flutterWebViewPlugin.goBack();
},
),
),
bottomNavigationBar: BottomAppBar(
color: Colors.blue,
child: Row(
children: <Widget>[
IconButton(
icon: const Icon(Icons.arrow_back_ios),
onPressed: () {
flutterWebViewPlugin.goBack();
},
),
],
),
),
withZoom: true,
withLocalStorage: true,
hidden: true,
headers: _HTMLheaders,
);
}
}
I need floating action button like this:
.
Are there standard tools for implementation? I watched both the standard version of the button and the extended one, but did not find anything
You don't need to use an external library because it will grow the size of your bundle.
This is the code:
FloatingActionButton.extended(
onPressed: () {
// Add your onPressed code here!
},
label: Text('Approve'),
icon: Icon(Icons.thumb_up),
backgroundColor: Colors.pink,
)
You can use this flutter package flutter_fab
Or you can refer from this article Create Animated FAB in flutter.
You can also use this flutter_speed_dial
https://pub.dev/packages/flutter_speed_dial#-readme-tab-
You can use FloatingActionButton.Extended.
just copy and paste the code and see the result itself
import 'package:flutter/material.dart';
class TestClass extends StatefulWidget {
#override
_TestClassState createState() => _TestClassState();
}
class _TestClassState extends State<TestClass> {
bool floatExtended = false;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
width: 272,
height: 168,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20), color: Colors.indigo),
)),
floatingActionButton: FloatingActionButton.extended(
tooltip: 'Create Card',
label: Row(
children: [
IconButton(onPressed: () {}, icon: Icon(Icons.save)),
IconButton(onPressed: () {}, icon: Icon(Icons.library_add_check)),
// Text('1'),
// Text('2'),
// Text('3'),
],
),
isExtended: floatExtended,
icon: Icon(
floatExtended == true ? Icons.close : Icons.radio_button_on,
color: floatExtended == true ? Colors.red : Colors.black,
),
onPressed: () {
setState(() {
floatExtended = !floatExtended;
});
},
backgroundColor: floatExtended == true
? Colors.blueGrey
: Colors.white.withOpacity(.7),
),
);
}
}
Add a Text("YourText") widget in child of FloatingActionButton. Then it will work.
FloatingActionButton.extended(
child: Text('Login'),
backgroundColor: Colors.pink,
onPressed: null,)
Use Flow class. It's built-in flutter No need for an external package. The flow was built for this kind of feature.
Here is the doc link
https://api.flutter.dev/flutter/widgets/Flow-class.html
I am currently making an app with lists of a Card widgets. This is a code snippet:
new GestureDetector(
onLongPress: () {
showAlert();
//pops up an AlertDialog
},
child: new Card(child: new Text("Hello"))
)
Is it possible to make the Card widget touchable, so the user can feel/see that the card is (long)tapped? I am searching for an 'InkWell-something result'.
Edit: I want to have a splash effect on my Card widgets when I longpress them.
An example of the splash effect that I mean is given in the following GIF:
Use this
return Card(
child: InkWell(
onTap: () {},
onLongPress: () {}
child: Container(),
));