我最近一直在研究 Flutter ShadCN 组件,但一直无法将文档中的Tabs示例代码集成到这里提供给我们的样板 ShadCN 样板代码中
我只是采取了
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown building ShadTabs<String>(dirty, dependencies:
[UnmanagedRestorationScope], state: ShadTabsState<String>#57a89):
ShadTheme.of() called with a context that does not contain a ShadTheme.
No ShadTheme ancestor could be found starting from the context that was passed to
ShadTheme.of().
This can happen because you do not have a ShadApp widget (which introduces a ShadTheme),
or it can happen if the context you use comes from a widget above this widget.
The context used was: ShadTabs<String>(dirty, dependencies: [UnmanagedRestorationScope],
state: ShadTabsState<String>#57a89)
我从样板代码中更改的唯一一行是我注释掉了Padding of
child 并将其替换为const TabsExample()
(我的小部件直接从TabsTabsExample
示例文档中复制粘贴)
import 'package:flutter/services.dart';
import 'package:flutter_test_1/screens/home_tabs.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(systemNavigationBarColor: Colors.transparent));
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return ShadcnApp(
title: 'My App',
home: const TabsExample(),
theme: ThemeData(
colorScheme: ColorSchemes.darkZinc(),
radius: 0.7,
),
);
}
}
class CounterPage extends StatefulWidget {
const CounterPage({super.key});
@override
_CounterPageState createState() => _CounterPageState();
}
class _CounterPageState extends State<CounterPage> {
int _counter = 0;
int _selected = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
NavigationItem _buildButton(String label, IconData icon) {
return NavigationItem(
label: Text(label),
child: Icon(icon),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
headers: [
AppBar(
title: const Text('Counter App'),
subtitle: const Text('Testing features'),
leading: [
GhostButton(
onPressed: () {
openDrawer(
context: context,
builder: (context) {
return Container(
alignment: Alignment.center,
constraints: const BoxConstraints(
maxWidth: 300,
),
child: const Text('Drawer'),
);
},
position: OverlayPosition.left,
);
},
density: ButtonDensity.icon,
child: const Icon(Icons.menu),
),
],
trailing: [
GhostButton(
density: ButtonDensity.icon,
onPressed: () {
openSheet(
context: context,
builder: (context) {
return Container(
alignment: Alignment.center,
constraints: const BoxConstraints(
maxWidth: 200,
),
child: const Text('Sheet'),
);
},
position: OverlayPosition.right,
);
},
child: const Icon(Icons.search),
),
],
),
const Divider(),
],
footers: [
const Divider(),
NavigationBar(
onSelected: (i) {
setState(() {
_selected = i;
});
},
index: _selected,
children: [
_buildButton('Home', Icons.home),
_buildButton('Explore', Icons.explore),
_buildButton('Library', Icons.library_music),
],
),
],
child:
const TabsExample()
// Padding(
// padding: const EdgeInsets.all(32.0),
// child: Center(
// child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
// children: <Widget>[
// const Text(
// 'You have pushed the button this many times:',
// textAlign: TextAlign.center,
// ).p(),
// Text(
// '$_counter',
// ).h1(),
// PrimaryButton(
// onPressed: _incrementCounter,
// density: ButtonDensity.icon,
// child: const Icon(Icons.add),
// ).p(),
// ],
// ),
// ),
// ),
);
}
}
出了什么问题?