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