This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future _loadSampleJson() async { | |
String jsonString = await rootBundle.loadString("assets/sample.json"); | |
final jsonData = json.decode(jsonString); | |
if (jsonData['status'] == 0) { | |
final formatA = FormatA.fromJson(jsonData); | |
} else if (jsonData['status'] == 1) { | |
final formatB = FormatB.fromJson(jsonData); | |
} else { | |
print('Format json tidak diketahui'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'dart:math'; | |
import 'dart:typed_data'; | |
import 'package:crypto/crypto.dart'; | |
import 'package:tuple/tuple.dart'; | |
import 'package:encrypt/encrypt.dart' as encrypt; | |
// Thanks to https://medium.com/@chingsuehok/cryptojs-aes-encryption-decryption-for-flutter-dart-7ca123bd7464 | |
class AES { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final mediaSize = MediaQuery.of(context).size; | |
final scale = 1 / (controller.value.aspectRatio * mediaSize.aspectRatio); | |
return ClipRect( | |
clipper: _MediaSizeClipper(mediaSize), | |
child: Transform.scale( | |
scale: scale, | |
alignment: Alignment.topCenter, | |
child: CameraPreview(controller), | |
), | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
import 'package:flutter_crud_cubit/cubit/profile_cubit.dart'; | |
import 'package:flutter_crud_cubit/cubit/profile_state.dart'; | |
import 'package:flutter_crud_cubit/helper/dio_helper.dart'; | |
import 'package:flutter_crud_cubit/model/profile_data.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
import 'cubit/profile_cubit.dart'; | |
import 'cubit/profile_state.dart'; | |
import 'dio_helper.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter_bloc/flutter_bloc.dart'; | |
import 'package:flutter_crud_cubit/model/profile_data.dart'; | |
import '../helper/dio_helper.dart'; | |
import 'profile_state.dart'; | |
class ProfileCubit extends Cubit<ProfileState> { | |
final DioHelper dioHelper; | |
ProfileCubit(this.dioHelper) : super(InitialProfileState()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter_crud_cubit/model/profile_data.dart'; | |
abstract class ProfileState {} | |
class InitialProfileState extends ProfileState {} | |
class LoadingProfileState extends ProfileState {} | |
class FailureLoadAllProfileState extends ProfileState { | |
final String errorMessage; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:dartz/dartz.dart'; | |
import 'package:dio/dio.dart'; | |
import 'package:flutter_crud_cubit/model/profile_data.dart'; | |
class DioHelper { | |
Dio _dio; | |
DioHelper() { | |
_dio = Dio( | |
BaseOptions( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: flutter_crud_cubit | |
description: A new Flutter project. | |
publish_to: 'none' # Remove this line if you wish to publish to pub.dev | |
version: 1.0.0+1 | |
environment: | |
sdk: ">=2.7.0 <3.0.0" | |
dependencies: | |
flutter: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:json_annotation/json_annotation.dart'; | |
part 'profile_data.g.dart'; | |
@JsonSerializable() | |
class ProfileData { | |
@JsonKey(name: 'id') | |
final int id; | |
@JsonKey(name: 'name') | |
final String name; |
NewerOlder