It doesn't work as shown in the ReadMe.
Closed this issue · 1 comments
darkstarx commented
If you don't set a ScrollController to the widget, you'll get the assertion:
dependOnInheritedWidgetOfExactType<PrimaryScrollController>() or dependOnInheritedElement() was called before _ScrollShadowState.initState() completed.
import 'package:flutter/material.dart';
import 'package:flutter_scroll_shadow/flutter_scroll_shadow.dart';
void main()
{
runApp(const MyApp());
}
class MyApp extends StatelessWidget
{
const MyApp({ super.key });
@override
Widget build(final BuildContext context)
{
return MaterialApp(
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
themeMode: ThemeMode.dark,
routes: {
'/page1': (context) => const Page1(),
},
initialRoute: '/page1',
);
}
}
class Page1 extends StatefulWidget
{
const Page1({ super.key });
@override
State<Page1> createState() => _Page1State();
}
class _Page1State extends State<Page1>
{
@override
Widget build(final BuildContext context)
{
return Scaffold(
appBar: AppBar(title: const Text('Page1')),
body: const MyScrollView(),
);
}
}
class MyScrollView extends StatelessWidget
{
const MyScrollView({ super.key });
@override
Widget build(final BuildContext context)
{
return ScrollShadow(
color: Colors.grey,
child: SingleChildScrollView(
child: Column(
children: List
.generate(20, (i) => SizedBox(height: 100, child: Text('Item #$i')))
.toList()
),
),
);
}
}
darkstarx commented
You can't use PrimaryScrollController.of(context)
or any other dependOnInheritedWidgetOfExactType until the initState is completed.