Skip to content

Commit

Permalink
Merge pull request #33 from technogise/release.0.0.2
Browse files Browse the repository at this point in the history
Release.0.0.2
  • Loading branch information
burhanrashid52 authored Mar 30, 2020
2 parents 93a9c27 + 9a536d4 commit aa55fd9
Show file tree
Hide file tree
Showing 32 changed files with 410 additions and 324 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## [0.0.1] - TODO: Add release date.
## [0.0.2] - 30 March 2020.

* TODO: Describe initial release.
- This is alpha version of the library. The API are subjected to changed
21 changes: 11 additions & 10 deletions form_builder_sample/lib/database_impl.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import 'package:formbuilder/helpers/database.dart';
import 'package:formbuilder/helpers/data_storage.dart';
import 'package:formbuilder/redux/models/store_view_model.dart';
import 'package:flow_form/helpers/data_storage.dart';
import 'package:flow_form/helpers/database.dart';
import 'package:hive/hive.dart';

class DatabaseImpl implements Database {
///Function to save data
void saveData({StoreViewModel viewModel, dynamic answer}) {
DataStorage.saveData(viewModel: viewModel, answer: answer);
var dataKey = viewModel.currentNode.dataKey;
void saveData({String dataKey, dynamic answer}) {
DataStorage.saveData(
dataKey: dataKey,
answer: answer,
);
var box = Hive.box('DataBox');
box.put(dataKey, answer);
}


///Function to upload image to fireBase
void uploadImage() {
}
void uploadImage() {}

String getData(String dataKey){
String getData(String dataKey) {
var box = Hive.box('DataBox');
String data = box.get(dataKey);
DataStorage.updateData(dataKey, data);
return data;
}
}
}
47 changes: 33 additions & 14 deletions form_builder_sample/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,40 +1,58 @@
import 'package:flow_form/flow_form.dart';
import 'package:flow_form/form.dart';
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:formbuilder/redux/actions/actions.dart';
import 'package:formbuilder/redux/app_state.dart';
import 'package:formbuilder/redux/store.dart';
import 'package:formbuildersample/database_impl.dart';
import 'package:formbuildersample/widgets/screens/dashboard.dart';
import 'package:formbuildersample/widgets/screens/date_picker_screen.dart';
import 'package:formbuildersample/widgets/screens/file_upload_screen.dart';
import 'package:formbuildersample/widgets/screens/section_screen.dart';
import 'package:formbuildersample/widgets/screens/select_screen.dart';
import 'package:formbuildersample/widgets/screens/text_input_screen.dart';
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart' as path_provider;

import 'styles/theme.dart';
import 'widgets/screens/main_screen.dart';
import 'package:path_provider/path_provider.dart' as path_provider;

void main() async {
WidgetsFlutterBinding.ensureInitialized();
initHiveDB();
var flowPath = "assets/json/flow.json";
var dataPath = "assets/json/screen_data.json";
setFlowAndDataPath(flowPath, dataPath);
setupDB(DatabaseImpl());
runApp(MyApp());

final flowFormBuilder = FlowFormBuilder("assets/json/flow.json")
..screenMetaPath = "assets/json/screen_data.json"
..database = DatabaseImpl()
..registerWidgets = {
SelectScreen.type: SelectScreen(),
DatePickerScreen.type: DatePickerScreen(),
Dashboard.type: Dashboard(),
TextInputScreen.type: TextInputScreen(),
RenderSection.type: RenderSection(),
FileUploadScreen.type: FileUploadScreen()
};

runApp(MyApp(flowFormBuilder.build()));
}

///MyApp entry of form builder sample
class MyApp extends StatelessWidget {
/// Static variable to refer this class in routes
static const id = '/';

final FlowForm flowForm;

MyApp(this.flowForm);

@override
Widget build(BuildContext context) {
return StoreProvider<AppState>(
store: store,
return FlowFormProvider(
flowForm: flowForm,
child: MaterialApp(
theme: appTheme,
home: Scaffold(
appBar: AppBar(
leading: BackButton(onPressed: () {
store.dispatch(NodeActions.prevNode);
var questionNavigation = FlowFormProvider.navigatorOf(context);
questionNavigation.gotoPrevious();
}),
),
body: SafeArea(child: Center(child: MainScreen())),
Expand All @@ -46,7 +64,8 @@ class MyApp extends StatelessWidget {
}

void initHiveDB() async {
final appDocumentDirectory = await path_provider.getApplicationDocumentsDirectory();
final appDocumentDirectory =
await path_provider.getApplicationDocumentsDirectory();
Hive.init(appDocumentDirectory.path);
await Hive.openBox("DataBox");
}
5 changes: 2 additions & 3 deletions form_builder_sample/lib/mappers/screen_mapper.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:formbuilder/redux/models/abstract_view_model.dart';

import '../widgets/screens/dashboard.dart';
import '../widgets/screens/date_picker_screen.dart';
Expand All @@ -11,14 +10,14 @@ import '../widgets/screens/text_input_screen.dart';
///Class for mapping component names from json to component
class ScreenMapper {
///Function to provide requested screen
static Widget getScreen(String type, ViewModel viewModel) {
static Widget getScreen(String type) {
var mapper = {
SelectScreen.type: SelectScreen(),
DatePickerScreen.type: DatePickerScreen(),
Dashboard.type: Dashboard(),
TextInputScreen.type: TextInputScreen(),
RenderSection.type: RenderSection(),
FileUploadScreen.type: FileUploadScreen(viewModel)
FileUploadScreen.type: FileUploadScreen()
};

return mapper[type];
Expand Down
2 changes: 1 addition & 1 deletion form_builder_sample/lib/mappers/select_type_mapper.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:formbuilder/redux/models/store_view_model.dart';
import 'package:flow_form/redux/models/store_view_model.dart';

import '../widgets/components/select/multi_options.dart';
import '../widgets/components/select/options.dart';
Expand Down
34 changes: 11 additions & 23 deletions form_builder_sample/lib/widgets/screens/dashboard.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:formbuilder/redux/actions/actions.dart';
import 'package:formbuilder/redux/app_state.dart';
import 'package:formbuilder/redux/models/abstract_view_model.dart';
import 'package:formbuilder/redux/models/dashboard_view_model.dart';
import 'package:flow_form/flow_form.dart';
import 'package:flow_form/question_navigation.dart';

import '../square_box.dart';

///Class for dashboard component
Expand All @@ -13,36 +11,26 @@ class Dashboard extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Container(
child: StoreConnector<AppState, ViewModel>(
onInit: (store) {
var dashBoardNode = store.state.dashBoardNode;
store.dispatch(SetCurrentNode(dashBoardNode));
},
converter: DashboardViewModel.fromStore,
builder: (context, view) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: getButtonList(view),
);
},
),
var questionNavigation = FlowFormProvider.navigatorOf(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: getButtonList(questionNavigation),
);
}

/// Function to get all category name buttons
List<Widget> getButtonList(DashboardViewModel viewModel) {
List<Widget> getButtonList(QuestionNavigation questionNavigation) {
var widgets = [].cast<Widget>();
widgets.add(Expanded(flex: 1, child: SizedBox()));

for (var categoryName in viewModel.categoryNames) {
for (var categoryName in questionNavigation.getCategoryNames()) {
widgets.add(
Expanded(
flex: 1,
child: SquareBox(
label: categoryName,
onPressed: viewModel.goToCategory,
onPressed: questionNavigation.gotoCategory,
),
),
);
Expand Down
32 changes: 13 additions & 19 deletions form_builder_sample/lib/widgets/screens/date_picker_screen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:formbuilder/redux/app_state.dart';
import 'package:formbuilder/redux/models/store_view_model.dart';
import 'package:flow_form/flow_form.dart';

import '../components/comment.dart';
import '../components/date_picker/date_picker.dart';
Expand All @@ -24,22 +22,18 @@ class _DatePickerState extends State<DatePickerScreen> {

@override
Widget build(BuildContext context) {
return StoreConnector<AppState, StoreViewModel>(
converter: StoreViewModel.fromStore,
builder: (context, viewModel) {
var selectScreenMeta = viewModel.getSelectScreenMeta();
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Comment(text: selectScreenMeta.comment),
DatePicker(),
Options(
options: selectScreenMeta.options,
onPressed: viewModel.moveToNextNode,
),
],
);
},
var questionNavigation = FlowFormProvider.navigatorOf(context);
var selectScreenMeta = questionNavigation.getSelectScreenMeta();
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Comment(text: selectScreenMeta.comment),
DatePicker(),
Options(
options: selectScreenMeta.options,
onPressed: questionNavigation.submitAnswer,
),
],
);
}
}
46 changes: 17 additions & 29 deletions form_builder_sample/lib/widgets/screens/file_upload_screen.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:formbuilder/helpers/data_storage.dart';
import 'package:formbuilder/redux/app_state.dart';
import 'package:formbuilder/redux/models/store_view_model.dart';
import 'package:flow_form/flow_form.dart';
import 'package:flow_form/helpers/data_storage.dart';

import '../components/comment.dart';
import '../components/file_uploader/uploader.dart';
Expand All @@ -13,38 +11,28 @@ class FileUploadScreen extends StatefulWidget {
///Static variable to represent the screen type
static String type = 'file-upload';

///Instance variable to store the view model
final StoreViewModel viewModel;

///Constructor to instantiate File Uploader
FileUploadScreen(this.viewModel);

@override
_FileUploadScreenState createState() => _FileUploadScreenState();
}

class _FileUploadScreenState extends State<FileUploadScreen> {
@override
Widget build(BuildContext context) {
return StoreConnector<AppState, StoreViewModel>(
converter: StoreViewModel.fromStore,
builder: (context, viewModel) {
var selectScreenMeta = viewModel.getSelectScreenMeta();
final String nextNode = selectScreenMeta.options.first;
return Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Comment(text: selectScreenMeta.comment),
QuestionCard(text: selectScreenMeta.question),
FileUploader(onSubmit: (file) {
DataStorage.uploadImage(viewModel, file);
viewModel.moveToNextNode(nextNode);
}),
],
);
},
var questionNavigation = FlowFormProvider.navigatorOf(context);
var selectScreenMeta = questionNavigation.getSelectScreenMeta();
final String nextNode = selectScreenMeta.options.first;
return Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Comment(text: selectScreenMeta.comment),
QuestionCard(text: selectScreenMeta.question),
FileUploader(onSubmit: (file) {
DataStorage.uploadImage(questionNavigation, file);
questionNavigation.submitAnswer(nextNode);
}),
],
);
}
}
23 changes: 8 additions & 15 deletions form_builder_sample/lib/widgets/screens/main_screen.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import 'package:flow_form/flow_form.dart';
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:formbuilder/redux/app_state.dart';
import 'package:formbuilder/redux/models/store_view_model.dart';
import 'package:formbuildersample/mappers/screen_mapper.dart';

///Class for main screen component
class MainScreen extends StatelessWidget {
Expand All @@ -11,16 +8,12 @@ class MainScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
return StoreConnector<AppState, StoreViewModel>(
converter: StoreViewModel.fromStore,
builder: (context, viewModel) {
if (viewModel.currentNode != null) {
return ScreenMapper.getScreen(
viewModel.currentNode.type,
viewModel,
);
}
return Container();
});
var formProvider = FlowFormProvider.of(context);
return FlowFormNotifier(builder: (formMetadata) {
if (formMetadata != null) {
return formProvider.getScreen(formMetadata.screenType);
}
return Container();
});
}
}
Loading

0 comments on commit aa55fd9

Please sign in to comment.