How to stop ListView from scrolling automatically in Flutter? - flutter

Very trivial problem.
Super simple code.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return ListView(
children: [
Container(color: Colors.red, height: 1000),
Container(color: Colors.blue, height: 1000),
],
);
}
}
It keeps snapping to the item instead of scrolling organically; any ideas?

There seems to be a scrollbug bug with Flutter + iOS Simulator 14.4.
Logged a bug with Flutter here:
https://github.com/flutter/flutter/issues/79641

Related

keyboard is not showing when auto focus is true in flutter textfield

When I restart this code in Visual Studio autofocus is working as well as keyboard is showing. When I close the visual studio and re open the app in android emulator the keyboard is not showing but auto focus is working (Cursor is showing).
But its work in android 5 perfectly.
My code:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: TextField(
autofocus: true,
)
),
);
}
}
Can anyone fix this? Thank you.
Try the following code:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final FocusNode focusNode = FocusNode();
#override
void initState() {
super.initState();
focusNode.requestFocus();
}
#override
void dispose() {
focusNode.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: TextField(
focusNode: focusNode,
autofocus: true,
),
),
);
}
}

InAppWebView is not working in flutter web app - Desktop

I have used InAppWebView plugin to load webview. It works fine in android and iOS. But in flutter web app, it throws error as plugin not supported.
Kindly suggest some solution or an plugin that works fine in all platforms.
InAppWebview or Webview isn't supported in Flutter Web.
Check this package out: https://pub.dev/packages/webviewx
This is an example:
import 'package:flutter/material.dart';
import 'package:webviewx/webviewx.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return const Scaffold(
body: WebViewX(
initialContent: "https://flutter.dev/",
width: double.maxFinite,
height: double.maxFinite,
),
);
}
}

how can i play rtsp video stream in flutter?

this is my code thats i m trying by using flutter vlc player but its not working so any can help me to solving the issue or i can show stream with another way?
so you guys can give me any suggestion or give any little example. i m trying to solve this issue from last two hours but its not going
import 'package:flutter/material.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
import 'package:flutter_vlc_player/vlc_player.dart';
import 'package:flutter_vlc_player/vlc_player_controller.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
VlcPlayerController _videoPlayerController;
#override
void initState() {
super.initState();
_videoPlayerController = VlcPlayerController.network(
'rtsp://viewer:aeDoPhiucees3gohshie#173.249.14.110:27954/axis-media/media.amp?videocodec=h264&fps=15&audio=1&resolution=640x480',
hwAcc: HwAcc.FULL,
autoPlay: false,
options: VlcPlayerOptions(),
);
}
#override
void dispose() async {
super.dispose();
await _videoPlayerController.stopRendererScanning();
await _videoPlayerController.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: VlcPlayer(
controller: _videoPlayerController,
aspectRatio: 16 / 9,
placeholder: Center(child: CircularProgressIndicator()),
),
),
);
}
}
Here is a small example that works for me. I think the problem is that in the newer versions the Controller must be initialized immediately.
The only problems I have with this code is that the advanced options take no effect. Unfortunately it is hard to find some good information
import 'package:flutter/material.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
import 'package:flutter_vlc_player/src/vlc_player_controller.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
VlcPlayerController _vlcViewController = new VlcPlayerController.network(
"rtsp://192.72.1.1/liveRTSP/av4",
autoPlay: true,
);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new VlcPlayer(
controller: _vlcViewController,
aspectRatio: 16 / 9,
placeholder: Text("Hello World"),
),
],
),
),
);
}
}
Check out this lib: https://pub.dev/packages/flutter_playout. It does support HLS.

How to get rid of address bar and bottom bar in Flutter 'WebBrowser' Plugin?

My App is a Flutter WEB app.
This is the plugin I am using to display some HTML coming from the server:
https://pub.dev/packages/web_browser
Here is the code I am using:
WebBrowser(
initialUrl: 'https://${Provider.of<CP>(context).getPaymentURL()+Provider.of<CP>(context).getPaymentPATH()}?O=${Provider.of<CP>(context).getOrder().orderUID}&Ro=${Provider.of<CP>(context).getOrder().res_key}',
),
My screen looks like below:
I would like to rid of the address bar and bottom bar but not sure how. Can someone help please?
You can copy paste run full code below
You can use attribute interactionSettings and set WebBrowserInteractionSettings's topBar and bottomBar to SizedBox.shrink()
code snippet
return WebBrowser(
initialUrl: 'https://dart.dev/',
interactionSettings: WebBrowserInteractionSettings(
topBar: SizedBox.shrink(), bottomBar: SizedBox.shrink()));
working demo
full code
import 'package:flutter/material.dart';
import 'package:web_browser/web_browser.dart';
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return WebBrowser(
initialUrl: 'https://dart.dev/',
interactionSettings: WebBrowserInteractionSettings(
topBar: SizedBox.shrink(), bottomBar: SizedBox.shrink()));
}
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text("Demo"),
),
body: MyWidget()),
);
}
}

trying to make call from IOS

I'm trying to use url_launcher so that through a button it takes me to the dialer of my phone to make a call. In android it works perfectly but when I run it in IOS it does not work, it does nothing, I don't know if something is missing in the code, I appreciate your help
This is the code I am using:
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final String _phoneNumber = '318654378';
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: RaisedButton(
child: Text('Call Number'),
onPressed: () {
if (Platform.isAndroid) {
// _callNumber();
launch('tel://$_phoneNumber');
} else if (Platform.isIOS) {
launch('tel://$_phoneNumber');
}
}),
),
);
}
}
Any idea what is going on