content.tsx93 lines · main
| 1 | import { SimpleCodeBlock } from 'ui-patterns/SimpleCodeBlock' |
| 2 | |
| 3 | import type { ContentFileProps } from '@/components/interfaces/Connect/Connect.types' |
| 4 | import { |
| 5 | ConnectTabContent, |
| 6 | ConnectTabs, |
| 7 | ConnectTabTrigger, |
| 8 | ConnectTabTriggers, |
| 9 | } from '@/components/interfaces/Connect/ConnectTabs' |
| 10 | |
| 11 | const ContentFile = ({ projectKeys }: ContentFileProps) => { |
| 12 | return ( |
| 13 | <ConnectTabs> |
| 14 | <ConnectTabTriggers> |
| 15 | <ConnectTabTrigger value="lib/main.dart" /> |
| 16 | <ConnectTabTrigger value="lib/main.dart (app)" /> |
| 17 | </ConnectTabTriggers> |
| 18 | |
| 19 | <ConnectTabContent value="lib/main.dart"> |
| 20 | <SimpleCodeBlock className="dart" parentClassName="min-h-72"> |
| 21 | {` |
| 22 | import 'package:briven_flutter/briven_flutter.dart'; |
| 23 | |
| 24 | Future<void> main() async { |
| 25 | await Briven.initialize( |
| 26 | url: '${projectKeys.apiUrl ?? 'your-project-url'}', |
| 27 | anonKey: '${projectKeys.publishableKey ?? '<prefer publishable key instead of anon key for mobile and desktop apps>'}', |
| 28 | ); |
| 29 | runApp(MyApp()); |
| 30 | } |
| 31 | `} |
| 32 | </SimpleCodeBlock> |
| 33 | </ConnectTabContent> |
| 34 | |
| 35 | <ConnectTabContent value="lib/main.dart (app)"> |
| 36 | <SimpleCodeBlock className="dart" parentClassName="min-h-72"> |
| 37 | {` |
| 38 | class MyApp extends StatelessWidget { |
| 39 | const MyApp({super.key}); |
| 40 | |
| 41 | @override |
| 42 | Widget build(BuildContext context) { |
| 43 | return const MaterialApp( |
| 44 | title: 'Todos', |
| 45 | home: HomePage(), |
| 46 | ); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | class HomePage extends StatefulWidget { |
| 51 | const HomePage({super.key}); |
| 52 | |
| 53 | @override |
| 54 | State<HomePage> createState() => _HomePageState(); |
| 55 | } |
| 56 | |
| 57 | class _HomePageState extends State<HomePage> { |
| 58 | final _future = Briven.instance.client |
| 59 | .from('todos') |
| 60 | .select(); |
| 61 | |
| 62 | @override |
| 63 | Widget build(BuildContext context) { |
| 64 | return Scaffold( |
| 65 | body: FutureBuilder( |
| 66 | future: _future, |
| 67 | builder: (context, snapshot) { |
| 68 | if (!snapshot.hasData) { |
| 69 | return const Center(child: CircularProgressIndicator()); |
| 70 | } |
| 71 | final todos = snapshot.data!; |
| 72 | return ListView.builder( |
| 73 | itemCount: todos.length, |
| 74 | itemBuilder: ((context, index) { |
| 75 | final todo = todos[index]; |
| 76 | return ListTile( |
| 77 | title: Text(todo['name']), |
| 78 | ); |
| 79 | }), |
| 80 | ); |
| 81 | }, |
| 82 | ), |
| 83 | ); |
| 84 | } |
| 85 | } |
| 86 | `} |
| 87 | </SimpleCodeBlock> |
| 88 | </ConnectTabContent> |
| 89 | </ConnectTabs> |
| 90 | ) |
| 91 | } |
| 92 | |
| 93 | export default ContentFile |