Flutter_Webview showing blank screen - flutter

i tried to use the Flutter_webview library, But i can't seem to get it to work. All i see is blank screen and in the Debug i see Asynchronous suspension
Can anyone help me what could be the issue?
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class NewPageClicked extends StatelessWidget {
final Completer<WebViewController> _controller =
Completer<WebViewController>();
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Test"),
),
body: WebView(
initialUrl: 'https://www.google.com/',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
),
);
}
}
And this is the debug console
E/flutter (31283): #0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:597
E/flutter (31283): #1 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:158
E/flutter (31283): <asynchronous suspension>
E/flutter (31283): #2 TextureAndroidViewController._sendCreateMessage
package:flutter/…/services/platform_views.dart:1043
E/flutter (31283): <asynchronous suspension>
E/flutter (31283): #3 AndroidViewController.create
package:flutter/…/services/platform_views.dart:748
E/flutter (31283): <asynchronous suspension>
E/flutter (31283): #4 RenderAndroidView._sizePlatformView
package:flutter/…/rendering/platform_view.dart:193
E/flutter (31283): <asynchronous suspension>
E/flutter (31283):

Related

How to play sound with package audioplayers in flutter

I'm doing course on flutter. I was trying to play sound in flutter.
Sadly, I'm having below error code
Here is my complete code
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
void main() => runApp(XylophoneApp());
class XylophoneApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Center(
child: TextButton(
onPressed: () async {
final player=AudioPlayer();
await player.play(AssetSource('sounds/note1.wav'));
},
child: const Text('Click Me'))),
),
),
);
}
}
Here is my pubspec.yaml file settings
dependencies:
audioplayers: ^1.1.1
assets:
- sounds/
Here is my errors:
****[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Unable to load asset: assets/sounds/note1.wav
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:258:7)
<asynchronous suspension>
#1 AudioCache.fetchToMemory (package:audioplayers/src/audio_cache.dart:75:22)
<asynchronous suspension>
#2 AudioCache.load (package:audioplayers/src/audio_cache.dart:101:31)
<asynchronous suspension>
#3 AudioPlayer.setSourceAsset (package:audioplayers/src/audioplayer.dart:237:17)
<asynchronous suspension>
#4 AudioPlayer.play (package:audioplayers/src/audioplayer.dart:123:5)
<asynchronous suspension>
#5 XylophoneApp.build.<anonymous closure> (package:xylophone1/main.dart:16:21)
<asynchronous suspension>****
I just need to play sound with this audio player package.
I've changed pubspec.yaml settings and folder name "assets"
I also changed source this line to await "player.play(AssetSource('note1.wav'));"

Unhandled Exception: type 'Null' is not a subtype of type 'int' in type cast error when trying to call function with no int

Hello I was calling a startelection function from my flutter app on a button click and I got this error
the startelection function connects my flutter app with my solidity smart contract and starts the election through infura
I don't know why I am getting this error it was running fine before
error:
E/flutter (31094): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: type 'Null' is not a subtype of type 'int' in type cast
E/flutter (31094): #0 JsonRPC.call (package:web3dart/json_rpc.dart:53:27)
E/flutter (31094): <asynchronous suspension>
E/flutter (31094): #1 Web3Client._makeRPCCall (package:web3dart/src/core/client.dart:54:20)
E/flutter (31094): <asynchronous suspension>
E/flutter (31094): #2 Web3Client.getGasPrice (package:web3dart/src/core/client.dart:175:18)
E/flutter (31094): <asynchronous suspension>
E/flutter (31094): #3 _fillMissingData (package:web3dart/src/core/transaction_signer.dart:36:16)
E/flutter (31094): <asynchronous suspension>
E/flutter (31094): #4 Web3Client.signTransaction (package:web3dart/src/core/client.dart:316:26)
E/flutter (31094): <asynchronous suspension>
E/flutter (31094): #5 Web3Client.sendTransaction (package:web3dart/src/core/client.dart:285:18)
E/flutter (31094): <asynchronous suspension>
E/flutter (31094): #6 startElection (package:election/services/functions.dart:29:18)
E/flutter (31094): <asynchronous suspension>
E/flutter (31094): #7 _HomeState.build.<anonymous closure> (package:election/pages/home.dart:53:25)
E/flutter (31094): <asynchronous suspension>
E/flutter (31094):
home.dart :
import 'package:election/utils/Constants.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:web3dart/web3dart.dart';
import '../services/functions.dart';
import 'Electioninfo.dart';
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
#override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
late Client? httpClient;
late Web3Client? ethclient;
TextEditingController controller = TextEditingController();
#override
void initState() {
httpClient = Client();
ethclient = Web3Client(infura_url, httpClient!);
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Start Election'),
),
body: Container(
padding: const EdgeInsets.all(14),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
controller: controller,
decoration: const InputDecoration(
filled: true, hintText: 'Enter election name'),
),
const SizedBox(
height: 10,
),
Container(
width: double.infinity,
height: 45,
child: ElevatedButton(
onPressed: () async {
if (controller.text.isNotEmpty) {
await startElection(controller.text, ethclient!);
if(!mounted)return;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ElectionInfo(
ethClient: ethclient!,
electionName: controller.text,
)));
}
},
child: const Text('Start Election')))
],
),
),
);
}
}
function.dart :
Future<String> startElection(String name,Web3Client ethclient) async{
var response = await callFunction('startElection', [name], ethclient, owner_private_key);
print("election started successfully");
return response;
}
Future<String> callFunction(String funcname,List<dynamic>args,Web3Client ethClient,String privateKey) async{
EthPrivateKey credentials = EthPrivateKey.fromHex(privateKey);
DeployedContract contract = await loadcontract();
final ethfunction = contract.function(funcname);
final result = ethClient.sendTransaction(
credentials,Transaction.callContract(contract: contract, function: ethfunction, parameters: args),
chainId: null,fetchChainIdFromNetworkId: true);
return result;
}
Please try with addding dart_web3: ^0.0.3 dependencies

Flutter Error: Unhandled Exception: NoSuchMethodError: The method 'findAncestorStateOfType' was called on null

Every time I log in I get the below error.
I see there is some issue with my Navigator.pushReplacement, which gives error in the console but still allows me to Navigate.
Not sure how to fix this error.
The following code is what I am using. Please let me know if there is any I can get this error fixed.
class WelcomeScreen extends StatefulWidget {
#override
_WelcomeScreenState createState() => _WelcomeScreenState();
}
class _WelcomeScreenState extends State<WelcomeScreen>
with SingleTickerProviderStateMixin {
startTime() async {
var _duration = Duration(seconds: 5);
return Timer(_duration, navigationPage);
}
void navigationPage() {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => FirstTimeUserOnly(),
),
);
}
#override
void initState() {
super.initState();
startTime();
}
final int delayedAmount = 100;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Welcome'),
Logo(),
],
),
),
);
}
}
Here is the error I get
E/flutter (16323): Tried calling: findAncestorStateOfType<NavigatorState>()
E/flutter (16323): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
E/flutter (16323): #1 Navigator.of (package:flutter/src/widgets/navigator.dart:2115:19)
E/flutter (16323): #2 Navigator.pushReplacement (package:flutter/src/widgets/navigator.dart:1781:22)
E/flutter (16323): #3 _WelcomeScreenState.navigationPage (package:/welcome_screen.dart:23:15)
E/flutter (16323): #4 _rootRun (dart:async/zone.dart:1180:38)
E/flutter (16323): #5 _CustomZone.run (dart:async/zone.dart:1077:19)
E/flutter (16323): #6 _CustomZone.runGuarded (dart:async/zone.dart:979:7)
E/flutter (16323): #7 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)
E/flutter (16323): #8 _rootRun (dart:async/zone.dart:1184:13)
E/flutter (16323): #9 _CustomZone.run (dart:async/zone.dart:1077:19)
E/flutter (16323): #10 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1003:23)
E/flutter (16323): #11 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:23:15)
E/flutter (16323): #12 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
E/flutter (16323): #13 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
E/flutter (16323): #14 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter (16323):
try this, the timer is giving you the error
class WelcomeScreen extends StatefulWidget {
#override
_WelcomeScreenState createState() => _WelcomeScreenState();
}
class _WelcomeScreenState extends State<WelcomeScreen>
with SingleTickerProviderStateMixin {
Timer _timer;
void startTime() async{
_timer = Timer(new Duration(seconds: 5), navigationPage);
}
void navigationPage() {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => FirstTimeUserOnly(),
),
);
}
#override
void initState() {
super.initState();
startTime();
}
#override
void dispose() {
super.dispose();
_timer.cancel();
}
final int delayedAmount = 100;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Welcome'),
Logo(),
],
),
),
);
}
}

VideoPlayerController.network() ran into source error

Im trying to play a video from the internet using VideoPlayerController.network() method but every single url that i try face with an error which is specified below :
Source error.
E/flutter ( 4250): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4, null)
E/flutter ( 4250): #0 ChewieController._initialize (package:chewie/src/chewie_player.dart:291:7)
E/flutter ( 4250): <asynchronous suspension>
E/flutter ( 4250): #1 new ChewieController (package:chewie/src/chewie_player.dart:197:5)
E/flutter ( 4250): #2 _ChewieListState.initState (package:flutterappvideoandshit/screens/chewie_list.dart:20:25)
E/flutter ( 4250): #3 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4640:58)
E/flutter ( 4250): #4 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #5 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #6 Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #7 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5830:14)
E/flutter ( 4250): #8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #9 Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #10 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5830:14)
E/flutter ( 4250): #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #12 Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #13 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #14 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #15 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #16 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #17 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #18 Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #19 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #20 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #21 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #22 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #23 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #24 Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #25 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #26 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
E/flutter ( 4250): #27 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #28 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #29 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4666:11)
E/flutter ( 4250): #30 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #31 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #32 Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #33 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #34 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #35 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #36 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #37 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #38 Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #39 SliverMultiBoxAdaptorElement.updateChild (package:flutter/src/widgets/sliver.dart:1147:36)
E/flutter ( 4250): #40 SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1132:20)
E/flutter ( 4250): #41 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2607:19)
and here is my code :
import 'package:video_player/video_player.dart';
import 'package:chewie/chewie.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Video Player"),
),
body: ListView(
children: <Widget>[
ChewieList(
videoPlayerController: VideoPlayerController.asset('assets/videos/soccer.mp4'),
looping: true,
),
ChewieList(
videoPlayerController: VideoPlayerController.network(
'https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'),
),
/*
ChewieList(
videoPlayerController: VideoPlayerController.network(
'http://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'),
)
*/
],
),
);
}
}
class ChewieList extends StatefulWidget {
ChewieList({#required this.videoPlayerController,this.looping,Key key,}) : super(key:key);
final VideoPlayerController videoPlayerController;
final bool looping;
#override
_ChewieListState createState() => _ChewieListState();
}
class _ChewieListState extends State<ChewieList> {
ChewieController _chewieController;
#override
void initState() {
// TODO: implement initState
super.initState();
_chewieController = ChewieController(
videoPlayerController: widget.videoPlayerController,
aspectRatio: 16/9,
autoInitialize: true,
looping: widget.looping,
errorBuilder: (context,errMsg){
return Center(
child:Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.warning,color: Colors.yellowAccent,),
Text("!خطایی در برقراری ارتباط رخ داده است",style: TextStyle(color: Colors.white),)
],
),
);
}
);
}
#override
void dispose() {
// TODO: implement dispose
super.dispose();
widget.videoPlayerController.dispose();
_chewieController.dispose();
}
#override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.all(8.0),
child: Chewie(
controller: _chewieController,
),
);
}
}
it's driving me crazy!!!!
guys please help me .
You are using the wrong url. The url you posted is not the real video url but is only a redirect url.
Try with:
VideoPlayerController.network('https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'),
(Remember that iOS simulators and other does not always support video playing.)

Error Using flare_splash_screen in Flutter

I created an animation using Flare for my Flutter project. But, I got an error when trying to Run it. The animation doesn't work and only a black screen with the logo i used shows.
Here is my code:
import 'package:flare_splash_screen/flare_splash_screen.dart';
import 'package:flutter/material.dart';
void main () {
runApp(MaterialApp(
home: SplashScreen(
'assets/splash.flr',
(context) => SplashTela(),
startAnimation: 'intro',
backgroundColor: Color(0xff3333),
),
));
}
class SplashTela extends StatefulWidget {
#override
_SplashTelaState createState() => _SplashTelaState();
}
class _SplashTelaState extends State<SplashTela> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: null,
body: Container(
color: Colors.redAccent,
),
);
}
}
And here is the error:
E/flutter (25496): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception:
'package:flare_splash_screen/flare_splash_screen.dart': Failed assertion: line 113 pos 16: '!
(isLoading == null && until == null)': isLoading and until are null, pick one ;)
E/flutter (25496): #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:40:39)
E/flutter (25496): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
E/flutter (25496): #2 new SplashScreen
(package:flare_splash_screen/flare_splash_screen.dart:113:16)
E/flutter (25496): #3 main (package:leagueuniverse/main.dart:6:11)
E/flutter (25496): #4 _runMainZoned.<anonymous closure>.<anonymous closure>
(dart:ui/hooks.dart:229:25)
E/flutter (25496): #5 _rootRun (dart:async/zone.dart:1124:13)
E/flutter (25496): #6 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (25496): #7 _runZoned (dart:async/zone.dart:1516:10)
E/flutter (25496): #8 runZoned (dart:async/zone.dart:1500:12)
E/flutter (25496): #9 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:221:5)
E/flutter (25496): #10 _startIsolate.<anonymous closure> (dart:isolate-
patch/isolate_patch.dart:305:19)
E/flutter (25496): #11 _RawReceivePortImpl._handleMessage (dart:isolate-
patch/isolate_patch.dart:172:12)
E/flutter (25496):
you need to pass until: () => Future.delayed(Duration(seconds: 5)),
or use isLoading demo code for isLoading https://github.com/jaumard/flare_splash_screen/blob/master/example/lib/isLoading.dart
an use SplashScreen.navigate
I use official example to test your case
code snippet
void main() {
runApp(MaterialApp(
home: SplashScreen.navigate(
name: 'assets/intro.flr',
next: (context) => SplashTela(),
startAnimation: '1',
backgroundColor: Color(0xff3333),
until: () => Future.delayed(Duration(seconds: 5)),
),
));
}
full test code work without error
import 'package:flare_splash_screen/flare_splash_screen.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: SplashScreen.navigate(
name: 'assets/intro.flr',
next: (context) => SplashTela(),
startAnimation: '1',
backgroundColor: Color(0xff3333),
until: () => Future.delayed(Duration(seconds: 5)),
),
));
}
class SplashTela extends StatefulWidget {
#override
_SplashTelaState createState() => _SplashTelaState();
}
class _SplashTelaState extends State<SplashTela> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: null,
body: Container(
color: Colors.redAccent,
),
);
}
}