I am creating a webview app by modifying the example source file in the flutter book. When you run the app, the splash screen turns on and then moves to the web view, but there are no splash-related comments or explanations, so I don’t know where the code is.
The code is here
main.dart
import 'package:ch_08/screen/home_screen.dart';
import 'package:flutter/material.dart';
void main() {
// 플러터 프레임워크가 앱을 실행할 준비가 될때까지
// 기다림
WidgetsFlutterBinding.ensureInitialized();
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: HomeScreen(),
),
);
}
home_screen.dart
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:webview_flutter/webview_flutter.dart';
class HomeScreen extends StatefulWidget {
//uri = 불러올 홈페이지 주소
final uri = Uri.parse('https://google.com');
HomeScreen({Key? key}) : super(key: key);
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
List<DateTime> clicked = [];
final clickWaitTime = const Duration(seconds: 1);
final controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(NavigationDelegate(onPageFinished: (String url) {
}));
@override
void initState() {
controller.loadRequest(widget.uri);
super.initState();
}
@override
Widget build(BuildContext context) {
return PopScope(
canPop: false,
onPopInvoked: (didPop) {
clicked.add(DateTime.now());
//마지막 클릭이 마지막 클릭 1초 후인 경우.
//카운터를 재설정하려면 목록을 지웁니다.
if (clicked.length > 1 &&
clicked[clicked.length - 1]
.difference(clicked[clicked.length - 2]) >
clickWaitTime) {
clicked.removeAt(clicked.length - 2);
}
//목록의 모든 클릭이 "2회 이상" 클릭이고 총 3번의 클릭이 있는 경우
//사용자가 세 번 클릭했음을 의미합니다.
if (clicked.length == 3) {
clicked.clear();
SystemNavigator.pop();
exit(0);
return;
}
//사용자가 더 많은 클릭을 원하는지 확인하기 위해 1초 동안 기다립니다.
Future.delayed(const Duration(seconds: 1), () {
if (clicked.length == 1) {
controller?.goBack();
} else if (clicked.length == 2) {
showMessage("뒤로가기를 3번 연속으로 누르면 종료됩니다.");
}
clicked.clear();
});
},
child: Scaffold(
body: SafeArea(
child: WebViewWidget(controller: controller),
),
),
);
}
void showMessage(String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(message)),
);
}
}
2
Answers
I solved it myself. If you've never made a splash screen before, it might not be what you're looking for.
I contacted the author of the book and got the answer.
Basically, Flutter runs the app icon while enlarging it when you run the app in the simulator.
It can make you mistake it for a splash screen.
If you need to, you can create a splash screen using the flutter_native_splash package instead of the default settings.
its appears that your project
androidappsrcmainresdrawablelaunch_background.xml
file. you can edit this file like this and put logo image in your app.And add your logo image to the
androidappsrcmainresdrawable
folder. thank you.