-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
742 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
abstract class Config { | ||
/// 请求url | ||
String baseUrl = | ||
"https://d6579fc5-c18b-443b-a2ef-01c2b6be51d5.bspapp.com/http"; | ||
} | ||
|
||
/// 开发环境 | ||
class ConfigDebug extends Config {} | ||
|
||
/// 预发布环境 | ||
class ConfigPreview extends Config {} | ||
|
||
/// 生产环境 | ||
class ConfigProduct extends Config {} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:web_demo/config/config.dart'; | ||
import 'package:web_demo/services/platform/platform.dart'; | ||
|
||
GetIt locator = GetIt.instance; | ||
|
||
setupLocator() { | ||
// 配置项目环境 | ||
locator.registerSingleton<Config>(ConfigProduct()); | ||
locator.registerFactory<PlatformRepository>(() => PlatformRepositoryImpl()); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:web_demo/locator.dart'; | ||
import 'package:web_demo/pages/home_page.dart'; | ||
import 'package:router_impl/router_impl.dart'; | ||
import 'package:web_demo/services/router/router.dart'; | ||
|
||
void main() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
await setupLocator(); | ||
|
||
void main() { | ||
runApp(MyApp()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'OldBirds', | ||
RouterImpl impl = RouterImpl( | ||
parser: LocationParserImpl(homeRouteBuilder: _homeRouteBuilder), | ||
homeRouteBuilder: _homeRouteBuilder); | ||
|
||
return MaterialApp.router( | ||
debugShowCheckedModeBanner: false, | ||
theme: ThemeData( | ||
primarySwatch: Colors.blue, | ||
), | ||
home: HomePage(), | ||
routeInformationParser: impl.routeInformationParser, | ||
routerDelegate: impl.routerDelegate, | ||
); | ||
} | ||
|
||
HomeRoute _homeRouteBuilder() { | ||
return HomeRoute(builder: () { | ||
return HomePage(); | ||
}); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class UnknownPage extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Container(); | ||
} | ||
} |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'dart:io' as dart; | ||
import 'package:flutter/foundation.dart'; | ||
|
||
enum Platform { | ||
android, | ||
fuchsia, | ||
ios, | ||
linux, | ||
macos, | ||
web, | ||
windows, | ||
} | ||
|
||
extension PlatformExtension on Platform { | ||
bool get isAndroid => this == Platform.android; | ||
bool get isFuchsia => this == Platform.fuchsia; | ||
bool get isIOS => this == Platform.ios; | ||
bool get isLinux => this == Platform.linux; | ||
bool get isMacos => this == Platform.macos; | ||
bool get isWeb => this == Platform.web; | ||
bool get isWindows => this == Platform.windows; | ||
} | ||
|
||
abstract class PlatformRepository { | ||
Platform getPlatform(); | ||
} | ||
|
||
class PlatformRepositoryImpl extends PlatformRepository { | ||
Platform getPlatform() { | ||
if (kIsWeb) { | ||
return Platform.web; | ||
} | ||
if (dart.Platform.isAndroid) { | ||
return Platform.android; | ||
} else if (dart.Platform.isFuchsia) { | ||
return Platform.fuchsia; | ||
} else if (dart.Platform.isIOS) { | ||
return Platform.ios; | ||
} else if (dart.Platform.isLinux) { | ||
return Platform.linux; | ||
} else if (dart.Platform.isMacOS) { | ||
return Platform.macos; | ||
} else if (dart.Platform.isWindows) { | ||
return Platform.windows; | ||
} else { | ||
throw UnimplementedError(); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:web_demo/pages/unknown_page.dart'; | ||
import 'package:router_impl/router_impl.dart'; | ||
|
||
class LocationParserImpl extends LocationParser { | ||
final HomeRoute Function() homeRouteBuilder; | ||
|
||
LocationParserImpl({ | ||
@required this.homeRouteBuilder, | ||
}); | ||
|
||
@override | ||
AppRoute parse(String location) { | ||
Uri uri = Uri.parse(location); | ||
|
||
if (uri.pathSegments.isEmpty) { | ||
return homeRouteBuilder(); | ||
} | ||
|
||
return UnknownRoute(); | ||
} | ||
} | ||
|
||
class UnknownRoute extends AppRoute { | ||
@override | ||
Widget get child => UnknownPage(); | ||
|
||
@override | ||
String get location => '/404'; | ||
} |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
build/ | ||
|
||
# Android related | ||
**/android/**/gradle-wrapper.jar | ||
**/android/.gradle | ||
**/android/captures/ | ||
**/android/gradlew | ||
**/android/gradlew.bat | ||
**/android/local.properties | ||
**/android/**/GeneratedPluginRegistrant.java | ||
|
||
# iOS/XCode related | ||
**/ios/**/*.mode1v3 | ||
**/ios/**/*.mode2v3 | ||
**/ios/**/*.moved-aside | ||
**/ios/**/*.pbxuser | ||
**/ios/**/*.perspectivev3 | ||
**/ios/**/*sync/ | ||
**/ios/**/.sconsign.dblite | ||
**/ios/**/.tags* | ||
**/ios/**/.vagrant/ | ||
**/ios/**/DerivedData/ | ||
**/ios/**/Icon? | ||
**/ios/**/Pods/ | ||
**/ios/**/.symlinks/ | ||
**/ios/**/profile | ||
**/ios/**/xcuserdata | ||
**/ios/.generated/ | ||
**/ios/Flutter/App.framework | ||
**/ios/Flutter/Flutter.framework | ||
**/ios/Flutter/Flutter.podspec | ||
**/ios/Flutter/Generated.xcconfig | ||
**/ios/Flutter/app.flx | ||
**/ios/Flutter/app.zip | ||
**/ios/Flutter/flutter_assets/ | ||
**/ios/Flutter/flutter_export_environment.sh | ||
**/ios/ServiceDefinitions.json | ||
**/ios/Runner/GeneratedPluginRegistrant.* | ||
|
||
# Exceptions to above rules. | ||
!**/ios/**/default.mode1v3 | ||
!**/ios/**/default.mode2v3 | ||
!**/ios/**/default.pbxuser | ||
!**/ios/**/default.perspectivev3 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: 60bd88df915880d23877bfc1602e8ddcf4c4dd2a | ||
channel: stable | ||
|
||
project_type: package |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## [0.0.1] - TODO: Add release date. | ||
|
||
* TODO: Describe initial release. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TODO: Add your license here. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# router_impl | ||
|
||
A new Flutter package. | ||
|
||
## Getting Started | ||
|
||
This project is a starting point for a Dart | ||
[package](https://flutter.dev/developing-packages/), | ||
a library module containing code that can be shared easily across | ||
multiple Flutter or Dart projects. | ||
|
||
For help getting started with Flutter, view our | ||
[online documentation](https://flutter.dev/docs), which offers tutorials, | ||
samples, guidance on mobile development, and a full API reference. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
|
||
abstract class AppRoute { | ||
const AppRoute(); | ||
|
||
String get location; | ||
Widget get child; | ||
|
||
Page<T> createPage<T>({Key key}) { | ||
return AdaptivePage.create( | ||
child: child, | ||
key: key ?? UniqueKey(), | ||
name: location, | ||
); | ||
} | ||
} | ||
|
||
class HomeRoute extends AppRoute { | ||
final Widget Function() builder; | ||
|
||
HomeRoute({@required this.builder}); | ||
|
||
@override | ||
String get location => "/"; | ||
|
||
@override | ||
Widget get child => builder(); | ||
} | ||
|
||
class AdaptivePage { | ||
static Page<T> create<T>({ | ||
@required Widget child, | ||
bool maintainState = true, | ||
bool fullscreenDialog = false, | ||
LocalKey key, | ||
String name, | ||
Object arguments, | ||
String title, | ||
}) { | ||
assert(child != null); | ||
assert(maintainState != null); | ||
assert(fullscreenDialog != null); | ||
|
||
if (kIsWeb) { | ||
return MaterialPage<T>( | ||
key: key, | ||
child: Builder( | ||
builder: (context) => WillPopScope( | ||
onWillPop: () async { | ||
if (Navigator.of(context).userGestureInProgress) { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
}, | ||
child: child, | ||
), | ||
), | ||
maintainState: maintainState, | ||
fullscreenDialog: fullscreenDialog, | ||
name: name, | ||
arguments: arguments, | ||
); | ||
} else if (Platform.isIOS) { | ||
return CupertinoPage<T>( | ||
key: key, | ||
child: child, | ||
maintainState: maintainState, | ||
fullscreenDialog: fullscreenDialog, | ||
name: name, | ||
arguments: arguments, | ||
title: title, | ||
); | ||
} else { | ||
return MaterialPage<T>( | ||
key: key, | ||
child: child, | ||
maintainState: maintainState, | ||
fullscreenDialog: fullscreenDialog, | ||
name: name, | ||
arguments: arguments, | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.