Skip to content

Update main.dart #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 21 additions & 92 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import 'package:codelessly_sdk/codelessly_sdk.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:storybook_flutter/storybook_flutter.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();

Codelessly.instance.initialize(
config: CodelesslyConfig(
authToken: "cSlMIT93cj1lXkBuYk5QNmImSTUsTHw2MDQ4VkdlOCZFLHc7",
authToken: "cSlMIT93cj1lXkBuYk5QNmImSTUsTHw2MDQ4VkdlOCZFLHc7", // Replace with yours
isPreview: kDebugMode,
preload: true,
),
Expand All @@ -18,101 +16,32 @@ void main() async {
runApp(const MyApp());
}

class MyApp extends StatefulWidget {
class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
State<MyApp> createState() => _MyAppState();
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: CodelesslyLayoutScreen(),
);
}
}

class _MyAppState extends State<MyApp> {
Map<String, dynamic> licenseData = {'license': 'FREE'};
class CodelesslyLayoutScreen extends StatelessWidget {
const CodelesslyLayoutScreen({super.key});

@override
Widget build(BuildContext context) => Storybook(
initialStory: 'Hello World',
showPanel: true,
wrapperBuilder: (context, child) {
return MaterialApp(
home: Container(color: Colors.white, child: child),
);
},
stories: [
Story(
name: 'Hello World',
builder: (context) {
return CodelesslyWidget(
layoutID: "0R0yRfzR23SQfDGrbg3h",
loadingBuilder: (context) {
return const CupertinoActivityIndicator();
},
);
},
Widget build(BuildContext context) {
return const Scaffold(
body: SafeArea(
child: CodelesslyWidget(
layoutID: "0Rxvyp379pTkaqMd0xRj", // Your actual layout ID
loadingBuilder: (context) => Center(
child: CircularProgressIndicator(),
),
Story(
name: 'License UI',
builder: (context) {
return CodelesslyWidget(
layoutID: "0R0yeUx1iGDe9kgW5xwn",
data: licenseData,
functions: {
'onFreeSelected': (context, reference, params) {
licenseData['license'] = 'FREE';
setState(() {});
},
'onProSelected': (context, reference, params) {
licenseData['license'] = 'PRO';
setState(() {});
},
'onBusinessSelected': (context, reference, params) {
licenseData['license'] = 'BUSINESS';
setState(() {});
},
},
loadingBuilder: (context) {
return const CupertinoActivityIndicator();
},
);
}),
Story(
name: 'Pricing UI',
builder: (context) {
return CodelesslyWidget(
layoutID: "0R0yedXWbqOrI_W7PBlo",
loadingBuilder: (context) {
return const CupertinoActivityIndicator();
},
);
}),
Story(
name: 'Pricing Card',
builder: (context) {
return CodelesslyWidget(
layoutID: '0R1xmqF5lXMr6LpLA9h5',
loadingBuilder: (context) {
return const CupertinoActivityIndicator();
},
);
},
),
Story(
name: 'Fruit Product Card',
builder: (context) {
return CodelesslyWidget(
layoutID: '0R5hf4ABTQmzDb6e8XyR',
data: const {
'name': 'Mango',
'price': 5.99,
'count': 1,
'description':
'Mangos are versatile fruits that can be enjoyed in many ways. You can eat them fresh as a snack or dessert, or add them to salads, smoothies, salsas, curries, cakes, pies, and more. You can also make mango juice, jam, chutney, or pickle.\n\nMangos are a great way to add some tropical flavor and nutrition to your diet.'
},
loadingBuilder: (context) {
return const CupertinoActivityIndicator();
},
);
},
),
],
);
),
),
);
}
}