#flutter #scrollview
Вопрос:
В демо-версии, даже если я не использую ящик или панель приложений, это не имеет значения. Любой вид прокрутки не останавливается посередине. Даже если это представление списка или столбец в представлении Singlechildscroll, это не имеет значения. Я не могу прокручивать нормально. Он внезапно отскакивает к другому краю.
Причина, по которой я использую опцию shift, заключается в том, чтобы показывать, когда я отпускаю мышь.
https://www.youtube.com/watch?v=GqlQL_rl3Xc
Тестовая Демонстрация:
import 'xxxx/widgets/app-bar.dart';
import 'xxxx/widgets/drawer.dart';
import 'package:flutter/material.dart';
class PageHome extends StatefulWidget {
PageHome({Key? key}) : super(key: key);
@override
_PageHomeState createState() => _PageHomeState();
}
class _PageHomeState extends State<PageHome> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: IAppBar(
title: "Home",
),
drawer: AppDrawer(
index: AppDrawer.DRAWER_INDEX_HOME,
),
body: SingleChildScrollView(
controller: ScrollController(),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.yellow,
Colors.teal,
Colors.purple,
Colors.blue,
Colors.red
])),
child: Column(
children: [
Container(height: 3000),
],
),
),
),
);
} f
}
Главный дротик:
class MyApp extends StatefulWidget {
MyApp();
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'CT',
theme: ThemeData(
brightness: Brightness.light,
backgroundColor: backgroundColor,
primaryColor: primaryColor,
accentColor: accentColor,
textTheme: GoogleFonts.ubuntuTextTheme().copyWith(
headline1: GoogleFonts.ubuntuTextTheme().headline1?.copyWith(
fontSize: 24,
fontWeight: FontWeight.w900,
color: Colors.black)),
),
onGenerateRoute: ARouter.generateRoute);
}
}
class Splash extends StatefulWidget {
const Splash({Key? key}) : super(key: key);
@override
_SplashState createState() => _SplashState();
}
class _SplashState extends State<Splash> {
@override
void initState() {
super.initState();
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) async {
if ((!await FlutterSecureStorage().containsKey(key: "intro"))) {
Navigator.pushReplacementNamed(context, ARouter.routeIntro);
return;
}
if (await getJWT() == null) {
Navigator.pushReplacementNamed(context, ARouter.routeAuth);
return;
}
if (await validateToken())
Navigator.pushReplacementNamed(context, ARouter.routeHome);
else
Navigator.pushReplacementNamed(context, ARouter.routeAuth);
});
}
@override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: Stack(
children: [
Image.asset("assets/images/bg.png"),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(
strokeWidth: 6,
),
Container(height: 24),
Center(
child: Text(
"Loading",
style: TextStyle(
fontSize: 24,
color: Colors.black,
decoration: TextDecoration.none),
)),
],
),
],
),
);
}
}
Комментарии:
1. Вы пробовали запустить приложение на реальном устройстве? Я заметил такое же поведение при использовании эмулятора, но при тестировании на устройстве все в порядке.
2. Он действует так же на Flutter 2.0.6, 2.2.0, 2.2.1. Но, как вы сказали, проблема возникает на симуляторах. Когда я запускаю его на своем физическом устройстве, он работает безупречно. Все виды прокрутки моих проектов набирают скорость, когда я немного перетаскиваю на симуляторе.