我开发了一个android应用程序,它在模拟器中可以正常工作。但是,当我尝试在移动设备上启动它时,无论是在调试模式还是发行版中,它都崩溃了。为什么会这样?
main.dart
:
import 'dart:async';
import 'dart:math';
import 'dart:ui';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:flutter/services.dart' show SystemChrome, DeviceOrientation;
import 'package:intl/intl.dart' show DateFormat;
// Vertretungsplan Montag
class VPMontag extends StatelessWidget {
String url;
VPMontag(this.url);
final Completer<WebViewController> _controller =
Completer<WebViewController>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Vertretungsplan Montag'),
),
body: Builder(builder: (BuildContext context) {
return WebView(
initialUrl: url,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
navigationDelegate: (NavigationRequest request) {
if (request.url.startsWith('https://www.youtube.com/')) {
print('blocking navigation to $request}');
return NavigationDecision.prevent;
}
print('allowing navigation to $request');
return NavigationDecision.navigate;
},
onPageStarted: (String url) {
print('Page started loading: $url');
},
onPageFinished: (String url) {
print('Page finished loading: $url');
},
gestureNavigationEnabled: true,
);
}));
}
}
// VP Dienstag
class VPDienstag extends StatelessWidget {
String url;
VPDienstag(this.url);
final Completer<WebViewController> _controller =
Completer<WebViewController>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Vertretungsplan Dienstag'),
),
body: Builder(builder: (BuildContext context) {
return WebView(
initialUrl: url,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
navigationDelegate: (NavigationRequest request) {
if (request.url.startsWith('https://www.youtube.com/')) {
print('blocking navigation to $request}');
return NavigationDecision.prevent;
}
print('allowing navigation to $request');
return NavigationDecision.navigate;
},
onPageStarted: (String url) {
print('Page started loading: $url');
},
onPageFinished: (String url) {
print('Page finished loading: $url');
},
gestureNavigationEnabled: true,
);
}));
}
}
// VP Mittwoch
class VPMittwoch extends StatelessWidget {
String url;
VPMittwoch(this.url);
final Completer<WebViewController> _controller =
Completer<WebViewController>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Vertretungsplan Mittwoch'),
),
body: Builder(builder: (BuildContext context) {
return WebView(
initialUrl: url,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
navigationDelegate: (NavigationRequest request) {
if (request.url.startsWith('https://www.youtube.com/')) {
print('blocking navigation to $request}');
return NavigationDecision.prevent;
}
print('allowing navigation to $request');
return NavigationDecision.navigate;
},
onPageStarted: (String url) {
print('Page started loading: $url');
},
onPageFinished: (String url) {
print('Page finished loading: $url');
},
gestureNavigationEnabled: true,
);
}));
}
}
// VP Donnerstag
class VPDonnerstag extends StatelessWidget {
String url;
VPDonnerstag(this.url);
final Completer<WebViewController> _controller =
Completer<WebViewController>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Vertretungsplan Donnerstag'),
),
body: Builder(builder: (BuildContext context) {
return WebView(
initialUrl: url,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
navigationDelegate: (NavigationRequest request) {
if (request.url.startsWith('https://www.youtube.com/')) {
print('blocking navigation to $request}');
return NavigationDecision.prevent;
}
print('allowing navigation to $request');
return NavigationDecision.navigate;
},
onPageStarted: (String url) {
print('Page started loading: $url');
},
onPageFinished: (String url) {
print('Page finished loading: $url');
},
gestureNavigationEnabled: true,
);
}));
}
}
// VP Freitag
class VPFreitag extends StatelessWidget {
String url;
VPFreitag(this.url);
final Completer<WebViewController> _controller =
Completer<WebViewController>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Vertretungsplan Freitag'),
),
body: Builder(builder: (BuildContext context) {
return WebView(
initialUrl: url,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
navigationDelegate: (NavigationRequest request) {
if (request.url.startsWith('https://www.youtube.com/')) {
print('blocking navigation to $request}');
return NavigationDecision.prevent;
}
print('allowing navigation to $request');
return NavigationDecision.navigate;
},
onPageStarted: (String url) {
print('Page started loading: $url');
},
onPageFinished: (String url) {
print('Page finished loading: $url');
},
gestureNavigationEnabled: true,
);
}));
}
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'VP App',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'VP App'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
vpmontag() {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VPMontag(
'myurl')));
}
vpdienstag() {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VPDienstag(
'myurl')));
}
vpmittwoch() {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VPMittwoch(
'myurl')));
}
vpdonnerstag() {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VPDonnerstag(
'myurl')));
}
vpfreitag() {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VPFreitag(
'myurl')));
}
int _selectedIndex = 0;
List<Widget> _widgetOptions = [];
@override
static TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
void initState() {
_widgetOptions = <Widget>[
Center(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Image.asset('images/uzw.jpg'),
],
)),
),
Center(
child: Container(
padding: EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
RaisedButton(
onPressed: vpmontag,
child: Text('Montag'),
padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 50.0),
),
RaisedButton(
onPressed: vpdienstag,
child: Text('Dienstag'),
padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 50.0),
),
RaisedButton(
onPressed: vpmittwoch,
child: Text('Mittwoch'),
padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 50.0),
),
RaisedButton(
onPressed: vpdonnerstag,
child: Text('Donnerstag'),
padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 50.0),
),
RaisedButton(
onPressed: vpfreitag,
child: Text('Freitag'),
padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 50.0),
)
],
),
),
),
WebView(
initialUrl:
'myurl',
javascriptMode: JavascriptMode.unrestricted,
),
Text('Einstellungen')
];
super.initState();
}
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('VP App'),
),
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Startseite'),
),
BottomNavigationBarItem(
icon: Icon(Icons.view_headline),
title: Text('Vertretungspläne'),
),
BottomNavigationBarItem(
icon: Icon(Icons.calendar_today),
title: Text('Stundenpläne'),
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
title: Text('Einstellungen'),
),
],
showUnselectedLabels: true,
currentIndex: _selectedIndex,
unselectedItemColor: Colors.grey,
selectedItemColor: Colors.blue[800],
onTap: _onItemTapped,
),
);
}
}
希望您能帮助我。我不知道为什么它可以在模拟器上工作。
答案 0 :(得分:0)
根据您的扑打医生显示的问题,可能是因为您不接受Android许可证。
主要步骤是:
flutter doctor --android-licenses
并接受所有许可证; flutter doctor -v
来检查问题是否已解决; flutter doctor -v