content.tsx 1.9 KB

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