Skip to content

Commit

Permalink
V1.0:项目框架搭建
Browse files Browse the repository at this point in the history
  • Loading branch information
PGzxc committed May 16, 2022
1 parent d976bcd commit 8fc1334
Show file tree
Hide file tree
Showing 34 changed files with 907 additions and 116 deletions.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
# flutter_wanandroid
## 一 项目介绍
* 本项目基于:GetX开发
* 本项目所使用的API均来自:WanAndroid官网(https://www.wanandroid.com/blog/show/2)

## 一 开发工具及版本
* 开发工具:macos 12.3.1

## 二 开发工具及版本
* 开发系统:macos 12.3.1
* 开发工具:Intellij IDEA Community 2021.1
* Flutter:3.0.0
* Dart: 2.17.0
* .gitignore:使用的Dart类型

## 三 项目预览

## 四 版本
### v1.0
* 项目框架搭建(抽屉+BottomBar)
* 抽屉显示快捷信息
* BottomBar:显示导航信息

## 五 开源库
* Getx:https://github.com/jonataslaw/getx
* logger: https://pub:flutter-io:cn/packages/logger
* flutter_zoom_drawer:https://pub.flutter-io.cn/packages/flutter_zoom_drawer



Expand Down
37 changes: 37 additions & 0 deletions lib/config/get_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../utils/logger/logger_util.dart';

class GetConfig extends GetxService{

Future<GetConfig> init() async{

Get.config(
defaultOpaqueRoute: Get.isOpaqueRouteDefault,
enableLog: false,
defaultPopGesture: true,
defaultTransition: Transition.leftToRightWithFade,
logWriterCallback: localLogWriter,
);
const GetMaterialApp(
debugShowCheckedModeBanner: false,
);
return this;
}

@override
void onInit(){
super.onInit();
}

void localLogWriter(String text, {bool isError = false}) {
LoggerUtil.d(text);
//Logger.write(text);

// pass the message to your favourite logging package here
// please note that even if enableLog: false log messages will be pushed in this callback
// you get check the flag if you want through GetConfig.isLogEnable
}

}
25 changes: 25 additions & 0 deletions lib/config/global_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_wanandroid/config/get_config.dart';
import 'package:flutter_wanandroid/pages/main/controllers/drawer_controller.dart';
import 'package:flutter_wanandroid/utils/logger/logger_utils.dart';
import 'package:flutter_zoom_drawer/config.dart';
import 'package:get/get.dart';
import '../utils/logger/logger_util.dart';

class Config {
static const isDebug = true;

static Future init() async {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark,
),
);
await Get.putAsync(() => GetConfig().init());
Get.put(() => AppDrawerController());
}
}
11 changes: 11 additions & 0 deletions lib/i18n/i18n_en.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter_wanandroid/i18n/i18n_keys.dart';

class I18nEn {
static const enKey='en_US';
static const Map<String, String> enValues = {
Keys.home: 'Home',
Keys.tree: 'Tree',
Keys.navigation: 'Navigation',
Keys.me: 'Me'
};
}
10 changes: 10 additions & 0 deletions lib/i18n/i18n_keys.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
abstract class Keys{

static const String home='home';
static const String tree='tree';
static const String navigation='navigation';
static const String project='project';
static const String me='me';


}
11 changes: 11 additions & 0 deletions lib/i18n/i18n_message.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter_wanandroid/i18n/i18n_en.dart';
import 'package:flutter_wanandroid/i18n/i18n_zh.dart';
import 'package:get/get.dart';

class Message extends Translations {
@override
Map<String, Map<String, String>> get keys => {
I18nZH.zhKey: I18nZH.zhValues,
I18nEn.enKey: I18nEn.enValues
};
}
11 changes: 11 additions & 0 deletions lib/i18n/i18n_zh.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'i18n_keys.dart';

class I18nZH {
static const zhKey='zh_CN';
static const Map<String, String> zhValues = {
Keys.home: '首页',
Keys.tree: '体系树',
Keys.navigation: '导航',
Keys.me: '我'
};
}
131 changes: 19 additions & 112 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,115 +1,22 @@
import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
import 'package:flutter_wanandroid/config/global_config.dart';
import 'package:flutter_wanandroid/i18n/i18n_message.dart';
import 'package:flutter_wanandroid/routes/app_pages.dart';
import 'package:get/get.dart';
import 'package:get/route_manager.dart';

/// 日期:2022-05-15
/// 描述:项目入口文件
/// 说明:Config.init();启动前配置项
Future<void> main() async {
await Config.init();
runApp(GetMaterialApp(
debugShowCheckedModeBanner: false,
translations: Message(),
unknownRoute: AppPages.unknownRoute,
initialRoute: AppPages.init,
getPages: AppPages.routes,
));
}

class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.

// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String title;

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
8 changes: 8 additions & 0 deletions lib/pages/home/controllers/home_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

import 'package:get/get_state_manager/src/simple/get_controllers.dart';

/// 日期:2022-05-15
/// 描述:主页-主屏页面-Body-home-控制器
/// 说明:
class HomeController extends GetxController {
}
14 changes: 14 additions & 0 deletions lib/pages/home/views/home_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get/get.dart';

/// 日期:2022-05-15
/// 描述:主页-主屏页面-Body-home-页面
/// 说明:
class HomeView extends GetView {
@override
Widget build(BuildContext context) {
//return Scaffold(appBar: AppBar(title: Text('Main'),),
return Center(child: Text('Home'));
}
}
26 changes: 26 additions & 0 deletions lib/pages/main/bindings/main_binding.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter_wanandroid/pages/home/controllers/home_controller.dart';
import 'package:flutter_wanandroid/pages/main/controllers/drawer_controller.dart';
import 'package:flutter_wanandroid/pages/main/controllers/main_controller.dart';
import 'package:flutter_wanandroid/pages/me/controllers/me_controller.dart';
import 'package:flutter_wanandroid/pages/navigation/controllers/navigation_controller.dart';
import 'package:flutter_wanandroid/pages/project/controllers/project_controller.dart';
import 'package:flutter_wanandroid/pages/tree/controllers/tree_controller.dart';
import 'package:get/instance_manager.dart';

/// 日期:2022-05-16
/// 描述:主页-页面绑定
/// 说明:包含:MainScreen(主屏页面)+MenuScreen(抽屉页面)
class MainBinding extends Bindings{
@override
void dependencies() {
Get.lazyPut(() => AppDrawerController());
Get.lazyPut(() => MainController());

Get.lazyPut(() => HomeController());
Get.lazyPut(() => TreeController());
Get.lazyPut(() => NavigationController());
Get.lazyPut(() => ProjectController());
Get.lazyPut(() => MeController());
}
}
18 changes: 18 additions & 0 deletions lib/pages/main/controllers/drawer_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:flutter_zoom_drawer/config.dart';
import 'package:get/get.dart';

/// 日期:2022-05-16
/// 描述:主页-抽屉-控制器
/// 说明:包含:MainScreen(主屏页面)+MenuScreen(抽屉页面)
class AppDrawerController extends GetxController{

final zoomDrawerController = ZoomDrawerController();

void toggleDrawer() {
print("Toggle drawer");
zoomDrawerController.toggle?.call();
update();
}

}
Loading

0 comments on commit 8fc1334

Please sign in to comment.