Giter Site home page Giter Site logo

kevinzhang19870314 / flutter_getx_boilerplate Goto Github PK

View Code? Open in Web Editor NEW
310.0 9.0 124.0 6.03 MB

A flutter boilerplate project with GetX state management.

License: MIT License

Kotlin 0.16% Swift 0.45% Objective-C 0.04% Dart 96.16% HTML 1.70% Ruby 1.50%
flutter boilerplate dart starter getx get state-management flutter-ui

flutter_getx_boilerplate's Introduction

flutter_getx_boilerplate

master branch: Fluter 3.0.5 version

Flutter-2.x branch: Flutter 2.x version

Languages: English (this file), 中文. , KR

Introduction

During my study of Flutter, I have been using the flutter_bloc state management framework. I accidentally saw the GetX state management framework. Through ReadMe, I found that the GetX framework is very easy to get started. So I want to write a GetX Starter project while learning, which can not only help myself Learning can also help others quickly build a boilerplate. Before building this boilerplate, I searched many similar projects, and found that they were relatively simple, and none of them covered the common things that the project should have, so I sprouted the idea of ​​writing one by myself. Let me introduce them one by one below.

Technology & Project Introduction

Use Flutter 2.x to build a set of features containing predefined folder structure, style themes, API access, state management, routing & dependencies, etc. The project structure is clear and can be easily used as a Flutter template project. Technologies used include but are not limited to Flutter, Dart, GetX, etc.

Installation & Use

Step 1:

Fork this project to your own warehouse:

git clone https://github.com/KevinZhang19870314/flutter_getx_boilerplate.git

Step 2:

Open the project folder with VS Code and execute the following command to install the dependency package:

flutter pub get

Step 3:

Open the main.dart file in the lib folder, F5 or Ctrl + F5 to run the project, and then you can start developing and debugging.

Folder structure

The following is the project folder structure (only the folders under lib are introduced)

lib/
|- api - Global Restful api requests, including interceptors, etc.
   |- interceptors - Interceptors, including auth, request, and response interceptors.
   |- api.dart - Restful api export file.
|- lang - Internationalization, including translation files, translation service files, etc.
   |- lang.dart - Language export file.
|- models - Various structured entity classes, divided into request and response entities.
   |- models.dart - Entity class export file.
|- modules - Business module folder.
   |- auth - Login & Registration Module.
   |- home - Home module.
   |- splash - Splash module.
   |- modules.dart - Module export file.
|- routes - Routing module.
   |- app_pages.dart - Routing page configuration.
   |- app_routes.dart - Route names.
   |- routes.dart - Route export file.
|- Shared - Global shared folders, including static variables, global services, utils, global Widgets, etc.
   |- shared.dart - Global shared export file.
|- theme - Theme folder.
|- app_bindings.dart - Services started before the app runs, such as Restful api.
|- di.dart - Global dependency injection objects, such as SharedPreferences, etc.
|- main.dart - Main entry.

Other

In the writing process, because it involves the call of Restful api, here I used the free test api provided by REQ|RES.

Test User as below:

email: "[email protected]",
password: "pistol"

flutter_getx_boilerplate's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flutter_getx_boilerplate's Issues

can you help me?

i have been custom your code

response_interceptor.dart

void handleErrorStatus(Response response) {
switch (response.statusCode) {
case 400:
final message = ErrorResponse.fromJson(response.body);
CommonWidget.toast(message.message);
break;
case 403:
final message = ErrorResponse.fromJson(response.body);
print(message.message);
//CommonWidget.toast(message.message);
Get.toNamed(Routes.VERIFY_EMAIL);
break;
default:
}

==============================
api_repository.dart

Future<UserResponse?> getUser() async {
final res = await apiProvider.getUser('/api/user');
if (res.statusCode == 200) {
return UserResponse.fromJson(res.body);
}
}

when iam run, i am get this error, in file api_repository.dart

Exception has occurred.
_CastError (type 'Null' is not a subtype of type 'Response' in type cast)

Dublicate Globalkey error

after Sign In and log off at me page. If you again try to click sign In button you get error

Launching lib\main.dart on Chrome in debug mode...
Debug service listening on ws://127.0.0.1:62522/bnQE7F-YJxU=/ws
Running with sound null safety
Connecting to VM Service at ws://127.0.0.1:62522/bnQE7F-YJxU=/ws
�[38;5;244m[GETX] �[39;49mInstance "SharedPreferences" has been created
�[38;5;244m[GETX] �[39;49mInstance "ApiProvider" has been created
�[38;5;244m[GETX] �[39;49mInstance "ApiProvider" has been initialized
�[38;5;244m[GETX] �[39;49mInstance "ApiRepository" has been created
�[38;5;244m[GETX] �[39;49mInstance "GetMaterialController" has been created
�[38;5;244m[GETX] �[39;49mInstance "GetMaterialController" has been initialized
�[38;5;244m[GETX] �[39;49mGOING TO ROUTE /
�[38;5;244m[GETX] �[39;49mInstance "SplashController" has been created
�[38;5;244m[GETX] �[39;49mInstance "SplashController" has been initialized
�[38;5;244m[GETX] �[39;49mGOING TO ROUTE /auth
�[38;5;244m[GETX] �[39;49mInstance "AuthController" has been created
�[38;5;244m[GETX] �[39;49mInstance "AuthController" has been initialized
�[38;5;244m[GETX] �[39;49mGOING TO ROUTE /auth/login
�[38;5;244m[GETX] �[39;49mGOING TO ROUTE /home
�[38;5;244m[GETX] �[39;49mInstance "HomeController" has been created
�[38;5;244m[GETX] �[39;49mInstance "HomeController" has been initialized
�[38;5;244m[GETX] �[39;49mGOING TO ROUTE /auth
�[38;5;244m[GETX] �[39;49mGOING TO ROUTE /auth/login

�[38;5;248m════════ Exception caught by widgets library ═══════════════════════════════════�[39;49m
�[38;5;244mThe following assertion was thrown building Form-[LabeledGlobalKey#2aaf7](state: FormState#ba874):�[39;49m
�[38;5;248mAssertion failed:�[39;49m
_route == ModalRoute.of(context)
is not true

�[38;5;244mThe relevant error-causing widget was�[39;49m
�[38;5;248mForm-[LabeledGlobalKey#2aaf7]�[39;49m
�[38;5;244mWhen the exception was thrown, this was the stack�[39;49m
�[38;5;248mC:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 236:49 throw_�[39;49m
�[38;5;248mC:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3 assertFailed�[39;49m
�[38;5;248mpackages/flutter/src/widgets/will_pop_scope.dart 135:36 didUpdateWidget�[39;49m
�[38;5;248mpackages/flutter/src/widgets/framework.dart 4754:57 update�[39;49m
�[38;5;248mpackages/flutter/src/widgets/framework.dart 3345:14 updateChild�[39;49m
�[38;5;244m...�[39;49m
�[38;5;248m════════════════════════════════════════════════════════════════════════════════�[39;49m

�[38;5;248m════════ Exception caught by widgets library ═══════════════════════════════════�[39;49m
Duplicate GlobalKey detected in widget tree.
�[38;5;248m════════════════════════════════════════════════════════════════════════════════�[39;49m

request_interceptor error when i'm uncomment

request_interceptor.dart

==============

import 'dart:async';

import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get_connect/http/src/request/request.dart';
import 'package:flutter_getx_boilerplate/shared/shared.dart';

FutureOr requestInterceptor(request) async {
final token = StorageService.box.pull(StorageItems.accessToken);

request.headers['X-Requested-With'] = 'XMLHttpRequest';
request.headers['Authorization'] = 'Bearer $token';

EasyLoading.show(status: 'loading...');
return request;
}

storage_service.dart

import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';

class StorageService extends GetxService {
Future init() async {
return await SharedPreferences.getInstance();
}
}

can you help me please

Changing tabs makes the view keeps refreshing.

When we change tab, the view keeps refreshing. For ex, at the first tab, you scroll the view to bottom, then switch to another tab and then get back to the first tab. This time the view refreshes and scroll up again. It should be the same state. Please fix. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.