feat: Initialize project
This commit is contained in:
25
lib/app/app.bottomsheets.dart
Normal file
25
lib/app/app.bottomsheets.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// StackedBottomsheetGenerator
|
||||
// **************************************************************************
|
||||
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import 'app.locator.dart';
|
||||
import '../ui/bottom_sheets/notice/notice_sheet.dart';
|
||||
|
||||
enum BottomSheetType {
|
||||
notice,
|
||||
}
|
||||
|
||||
void setupBottomSheetUi() {
|
||||
final bottomsheetService = locator<BottomSheetService>();
|
||||
|
||||
final Map<BottomSheetType, SheetBuilder> builders = {
|
||||
BottomSheetType.notice: (context, request, completer) =>
|
||||
NoticeSheet(request: request, completer: completer),
|
||||
};
|
||||
|
||||
bottomsheetService.setCustomSheetBuilders(builders);
|
||||
}
|
||||
30
lib/app/app.dart
Normal file
30
lib/app/app.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:bahla_front/ui/bottom_sheets/notice/notice_sheet.dart';
|
||||
import 'package:bahla_front/ui/dialogs/info_alert/info_alert_dialog.dart';
|
||||
import 'package:bahla_front/ui/views/home/home_view.dart';
|
||||
import 'package:bahla_front/ui/views/startup/startup_view.dart';
|
||||
import 'package:stacked/stacked_annotations.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
// @stacked-import
|
||||
|
||||
@StackedApp(
|
||||
routes: [
|
||||
MaterialRoute(page: HomeView),
|
||||
MaterialRoute(page: StartupView),
|
||||
// @stacked-route
|
||||
],
|
||||
dependencies: [
|
||||
LazySingleton(classType: BottomSheetService),
|
||||
LazySingleton(classType: DialogService),
|
||||
LazySingleton(classType: NavigationService),
|
||||
// @stacked-service
|
||||
],
|
||||
bottomsheets: [
|
||||
StackedBottomsheet(classType: NoticeSheet),
|
||||
// @stacked-bottom-sheet
|
||||
],
|
||||
dialogs: [
|
||||
StackedDialog(classType: InfoAlertDialog),
|
||||
// @stacked-dialog
|
||||
],
|
||||
)
|
||||
class App {}
|
||||
25
lib/app/app.dialogs.dart
Normal file
25
lib/app/app.dialogs.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// StackedDialogGenerator
|
||||
// **************************************************************************
|
||||
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import 'app.locator.dart';
|
||||
import '../ui/dialogs/info_alert/info_alert_dialog.dart';
|
||||
|
||||
enum DialogType {
|
||||
infoAlert,
|
||||
}
|
||||
|
||||
void setupDialogUi() {
|
||||
final dialogService = locator<DialogService>();
|
||||
|
||||
final Map<DialogType, DialogBuilder> builders = {
|
||||
DialogType.infoAlert: (context, request, completer) =>
|
||||
InfoAlertDialog(request: request, completer: completer),
|
||||
};
|
||||
|
||||
dialogService.registerCustomDialogBuilders(builders);
|
||||
}
|
||||
28
lib/app/app.locator.dart
Normal file
28
lib/app/app.locator.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// StackedLocatorGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// ignore_for_file: public_member_api_docs, implementation_imports, depend_on_referenced_packages
|
||||
|
||||
import 'package:stacked_services/src/bottom_sheet/bottom_sheet_service.dart';
|
||||
import 'package:stacked_services/src/dialog/dialog_service.dart';
|
||||
import 'package:stacked_services/src/navigation/navigation_service.dart';
|
||||
import 'package:stacked_shared/stacked_shared.dart';
|
||||
|
||||
final locator = StackedLocator.instance;
|
||||
|
||||
Future<void> setupLocator({
|
||||
String? environment,
|
||||
EnvironmentFilter? environmentFilter,
|
||||
}) async {
|
||||
// Register environments
|
||||
locator.registerEnvironment(
|
||||
environment: environment, environmentFilter: environmentFilter);
|
||||
|
||||
// Register dependencies
|
||||
locator.registerLazySingleton(() => BottomSheetService());
|
||||
locator.registerLazySingleton(() => DialogService());
|
||||
locator.registerLazySingleton(() => NavigationService());
|
||||
}
|
||||
116
lib/app/app.router.dart
Normal file
116
lib/app/app.router.dart
Normal file
@@ -0,0 +1,116 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// StackedNavigatorGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'package:bahla_front/ui/views/home/home_view.dart' as _i2;
|
||||
import 'package:bahla_front/ui/views/startup/startup_view.dart' as _i3;
|
||||
import 'package:flutter/material.dart' as _i4;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart' as _i1;
|
||||
import 'package:stacked_services/stacked_services.dart' as _i5;
|
||||
|
||||
class Routes {
|
||||
static const homeView = '/home-view';
|
||||
|
||||
static const startupView = '/startup-view';
|
||||
|
||||
static const all = <String>{
|
||||
homeView,
|
||||
startupView,
|
||||
};
|
||||
}
|
||||
|
||||
class StackedRouter extends _i1.RouterBase {
|
||||
final _routes = <_i1.RouteDef>[
|
||||
_i1.RouteDef(
|
||||
Routes.homeView,
|
||||
page: _i2.HomeView,
|
||||
),
|
||||
_i1.RouteDef(
|
||||
Routes.startupView,
|
||||
page: _i3.StartupView,
|
||||
),
|
||||
];
|
||||
|
||||
final _pagesMap = <Type, _i1.StackedRouteFactory>{
|
||||
_i2.HomeView: (data) {
|
||||
return _i4.MaterialPageRoute<dynamic>(
|
||||
builder: (context) => const _i2.HomeView(),
|
||||
settings: data,
|
||||
);
|
||||
},
|
||||
_i3.StartupView: (data) {
|
||||
return _i4.MaterialPageRoute<dynamic>(
|
||||
builder: (context) => const _i3.StartupView(),
|
||||
settings: data,
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
@override
|
||||
List<_i1.RouteDef> get routes => _routes;
|
||||
|
||||
@override
|
||||
Map<Type, _i1.StackedRouteFactory> get pagesMap => _pagesMap;
|
||||
}
|
||||
|
||||
extension NavigatorStateExtension on _i5.NavigationService {
|
||||
Future<dynamic> navigateToHomeView([
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
]) async {
|
||||
return navigateTo<dynamic>(Routes.homeView,
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
transition: transition);
|
||||
}
|
||||
|
||||
Future<dynamic> navigateToStartupView([
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
]) async {
|
||||
return navigateTo<dynamic>(Routes.startupView,
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
transition: transition);
|
||||
}
|
||||
|
||||
Future<dynamic> replaceWithHomeView([
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
]) async {
|
||||
return replaceWith<dynamic>(Routes.homeView,
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
transition: transition);
|
||||
}
|
||||
|
||||
Future<dynamic> replaceWithStartupView([
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
]) async {
|
||||
return replaceWith<dynamic>(Routes.startupView,
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
transition: transition);
|
||||
}
|
||||
}
|
||||
30
lib/main.dart
Normal file
30
lib/main.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:bahla_front/app/app.bottomsheets.dart';
|
||||
import 'package:bahla_front/app/app.dialogs.dart';
|
||||
import 'package:bahla_front/app/app.locator.dart';
|
||||
import 'package:bahla_front/app/app.router.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await setupLocator();
|
||||
setupDialogUi();
|
||||
setupBottomSheetUi();
|
||||
runApp(const MainApp());
|
||||
}
|
||||
|
||||
class MainApp extends StatelessWidget {
|
||||
const MainApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
initialRoute: Routes.startupView,
|
||||
onGenerateRoute: StackedRouter().onGenerateRoute,
|
||||
navigatorKey: StackedService.navigatorKey,
|
||||
navigatorObservers: [
|
||||
StackedService.routeObserver,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
56
lib/ui/bottom_sheets/notice/notice_sheet.dart
Normal file
56
lib/ui/bottom_sheets/notice/notice_sheet.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:bahla_front/ui/common/app_colors.dart';
|
||||
import 'package:bahla_front/ui/common/ui_helpers.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import 'notice_sheet_model.dart';
|
||||
|
||||
class NoticeSheet extends StackedView<NoticeSheetModel> {
|
||||
final Function(SheetResponse)? completer;
|
||||
final SheetRequest request;
|
||||
const NoticeSheet({
|
||||
Key? key,
|
||||
required this.completer,
|
||||
required this.request,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget builder(
|
||||
BuildContext context,
|
||||
NoticeSheetModel viewModel,
|
||||
Widget? child,
|
||||
) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(10),
|
||||
topRight: Radius.circular(10),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
request.title!,
|
||||
style: const TextStyle(fontSize: 25, fontWeight: FontWeight.w900),
|
||||
),
|
||||
verticalSpaceTiny,
|
||||
Text(
|
||||
request.description!,
|
||||
style: const TextStyle(fontSize: 14, color: kcMediumGrey),
|
||||
maxLines: 3,
|
||||
softWrap: true,
|
||||
),
|
||||
verticalSpaceLarge,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
NoticeSheetModel viewModelBuilder(BuildContext context) => NoticeSheetModel();
|
||||
}
|
||||
3
lib/ui/bottom_sheets/notice/notice_sheet_model.dart
Normal file
3
lib/ui/bottom_sheets/notice/notice_sheet_model.dart
Normal file
@@ -0,0 +1,3 @@
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
class NoticeSheetModel extends BaseViewModel {}
|
||||
9
lib/ui/common/app_colors.dart
Normal file
9
lib/ui/common/app_colors.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
const Color kcPrimaryColor = Color(0xFF9600FF);
|
||||
const Color kcPrimaryColorDark = Color(0xFF300151);
|
||||
const Color kcDarkGreyColor = Color(0xFF1A1B1E);
|
||||
const Color kcMediumGrey = Color(0xFF474A54);
|
||||
const Color kcLightGrey = Color.fromARGB(255, 187, 187, 187);
|
||||
const Color kcVeryLightGrey = Color(0xFFE3E3E3);
|
||||
const Color kcBackgroundColor = kcDarkGreyColor;
|
||||
3
lib/ui/common/app_strings.dart
Normal file
3
lib/ui/common/app_strings.dart
Normal file
@@ -0,0 +1,3 @@
|
||||
const String ksHomeBottomSheetTitle = 'Build Great Apps!';
|
||||
const String ksHomeBottomSheetDescription =
|
||||
'Stacked is built to help you build better apps. Give us a chance and we\'ll prove it to you. Check out stacked.filledstacks.com to learn more';
|
||||
78
lib/ui/common/ui_helpers.dart
Normal file
78
lib/ui/common/ui_helpers.dart
Normal file
@@ -0,0 +1,78 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
const double _tinySize = 5.0;
|
||||
const double _smallSize = 10.0;
|
||||
const double _mediumSize = 25.0;
|
||||
const double _largeSize = 50.0;
|
||||
const double _massiveSize = 120.0;
|
||||
|
||||
const Widget horizontalSpaceTiny = SizedBox(width: _tinySize);
|
||||
const Widget horizontalSpaceSmall = SizedBox(width: _smallSize);
|
||||
const Widget horizontalSpaceMedium = SizedBox(width: _mediumSize);
|
||||
const Widget horizontalSpaceLarge = SizedBox(width: _largeSize);
|
||||
|
||||
const Widget verticalSpaceTiny = SizedBox(height: _tinySize);
|
||||
const Widget verticalSpaceSmall = SizedBox(height: _smallSize);
|
||||
const Widget verticalSpaceMedium = SizedBox(height: _mediumSize);
|
||||
const Widget verticalSpaceLarge = SizedBox(height: _largeSize);
|
||||
const Widget verticalSpaceMassive = SizedBox(height: _massiveSize);
|
||||
|
||||
Widget spacedDivider = const Column(
|
||||
children: <Widget>[
|
||||
verticalSpaceMedium,
|
||||
Divider(color: Colors.blueGrey, height: 5.0),
|
||||
verticalSpaceMedium,
|
||||
],
|
||||
);
|
||||
|
||||
Widget verticalSpace(double height) => SizedBox(height: height);
|
||||
|
||||
double screenWidth(BuildContext context) => MediaQuery.of(context).size.width;
|
||||
double screenHeight(BuildContext context) => MediaQuery.of(context).size.height;
|
||||
|
||||
double screenHeightFraction(BuildContext context,
|
||||
{int dividedBy = 1, double offsetBy = 0, double max = 3000}) =>
|
||||
min((screenHeight(context) - offsetBy) / dividedBy, max);
|
||||
|
||||
double screenWidthFraction(BuildContext context,
|
||||
{int dividedBy = 1, double offsetBy = 0, double max = 3000}) =>
|
||||
min((screenWidth(context) - offsetBy) / dividedBy, max);
|
||||
|
||||
double halfScreenWidth(BuildContext context) =>
|
||||
screenWidthFraction(context, dividedBy: 2);
|
||||
|
||||
double thirdScreenWidth(BuildContext context) =>
|
||||
screenWidthFraction(context, dividedBy: 3);
|
||||
|
||||
double quarterScreenWidth(BuildContext context) =>
|
||||
screenWidthFraction(context, dividedBy: 4);
|
||||
|
||||
double getResponsiveHorizontalSpaceMedium(BuildContext context) =>
|
||||
screenWidthFraction(context, dividedBy: 10);
|
||||
double getResponsiveSmallFontSize(BuildContext context) =>
|
||||
getResponsiveFontSize(context, fontSize: 14, max: 15);
|
||||
|
||||
double getResponsiveMediumFontSize(BuildContext context) =>
|
||||
getResponsiveFontSize(context, fontSize: 16, max: 17);
|
||||
|
||||
double getResponsiveLargeFontSize(BuildContext context) =>
|
||||
getResponsiveFontSize(context, fontSize: 21, max: 31);
|
||||
|
||||
double getResponsiveExtraLargeFontSize(BuildContext context) =>
|
||||
getResponsiveFontSize(context, fontSize: 25);
|
||||
|
||||
double getResponsiveMassiveFontSize(BuildContext context) =>
|
||||
getResponsiveFontSize(context, fontSize: 30);
|
||||
|
||||
double getResponsiveFontSize(BuildContext context,
|
||||
{double? fontSize, double? max}) {
|
||||
max ??= 100;
|
||||
|
||||
var responsiveSize = min(
|
||||
screenWidthFraction(context, dividedBy: 10) * ((fontSize ?? 100) / 100),
|
||||
max);
|
||||
|
||||
return responsiveSize;
|
||||
}
|
||||
108
lib/ui/dialogs/info_alert/info_alert_dialog.dart
Normal file
108
lib/ui/dialogs/info_alert/info_alert_dialog.dart
Normal file
@@ -0,0 +1,108 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:bahla_front/ui/common/app_colors.dart';
|
||||
import 'package:bahla_front/ui/common/ui_helpers.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import 'info_alert_dialog_model.dart';
|
||||
|
||||
const double _graphicSize = 60;
|
||||
|
||||
class InfoAlertDialog extends StackedView<InfoAlertDialogModel> {
|
||||
final DialogRequest request;
|
||||
final Function(DialogResponse) completer;
|
||||
|
||||
const InfoAlertDialog({
|
||||
Key? key,
|
||||
required this.request,
|
||||
required this.completer,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget builder(
|
||||
BuildContext context,
|
||||
InfoAlertDialogModel viewModel,
|
||||
Widget? child,
|
||||
) {
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
backgroundColor: Colors.white,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
request.title!,
|
||||
style: const TextStyle(
|
||||
fontSize: 16, fontWeight: FontWeight.w900),
|
||||
),
|
||||
verticalSpaceTiny,
|
||||
Text(
|
||||
request.description!,
|
||||
style:
|
||||
const TextStyle(fontSize: 14, color: kcMediumGrey),
|
||||
maxLines: 3,
|
||||
softWrap: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: _graphicSize,
|
||||
height: _graphicSize,
|
||||
decoration: const BoxDecoration(
|
||||
color: Color(0xffF6E7B0),
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(_graphicSize / 2),
|
||||
),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: const Text(
|
||||
'⭐️',
|
||||
style: TextStyle(fontSize: 30),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
verticalSpaceMedium,
|
||||
GestureDetector(
|
||||
onTap: () => completer(DialogResponse(
|
||||
confirmed: true,
|
||||
)),
|
||||
child: Container(
|
||||
height: 50,
|
||||
width: double.infinity,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Text(
|
||||
'Got it',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
InfoAlertDialogModel viewModelBuilder(BuildContext context) =>
|
||||
InfoAlertDialogModel();
|
||||
}
|
||||
3
lib/ui/dialogs/info_alert/info_alert_dialog_model.dart
Normal file
3
lib/ui/dialogs/info_alert/info_alert_dialog_model.dart
Normal file
@@ -0,0 +1,3 @@
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
class InfoAlertDialogModel extends BaseViewModel {}
|
||||
85
lib/ui/views/home/home_view.dart
Normal file
85
lib/ui/views/home/home_view.dart
Normal file
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:bahla_front/ui/common/app_colors.dart';
|
||||
import 'package:bahla_front/ui/common/ui_helpers.dart';
|
||||
|
||||
import 'home_viewmodel.dart';
|
||||
|
||||
class HomeView extends StackedView<HomeViewModel> {
|
||||
const HomeView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget builder(
|
||||
BuildContext context,
|
||||
HomeViewModel viewModel,
|
||||
Widget? child,
|
||||
) {
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 25.0),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
verticalSpaceLarge,
|
||||
Column(
|
||||
children: [
|
||||
const Text(
|
||||
'Hello, STACKED!',
|
||||
style: TextStyle(
|
||||
fontSize: 35,
|
||||
fontWeight: FontWeight.w900,
|
||||
),
|
||||
),
|
||||
verticalSpaceMedium,
|
||||
MaterialButton(
|
||||
color: Colors.black,
|
||||
onPressed: viewModel.incrementCounter,
|
||||
child: Text(
|
||||
viewModel.counterLabel,
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
MaterialButton(
|
||||
color: kcDarkGreyColor,
|
||||
onPressed: viewModel.showDialog,
|
||||
child: const Text(
|
||||
'Show Dialog',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
MaterialButton(
|
||||
color: kcDarkGreyColor,
|
||||
onPressed: viewModel.showBottomSheet,
|
||||
child: const Text(
|
||||
'Show Bottom Sheet',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
HomeViewModel viewModelBuilder(
|
||||
BuildContext context,
|
||||
) =>
|
||||
HomeViewModel();
|
||||
}
|
||||
36
lib/ui/views/home/home_viewmodel.dart
Normal file
36
lib/ui/views/home/home_viewmodel.dart
Normal file
@@ -0,0 +1,36 @@
|
||||
import 'package:bahla_front/app/app.bottomsheets.dart';
|
||||
import 'package:bahla_front/app/app.dialogs.dart';
|
||||
import 'package:bahla_front/app/app.locator.dart';
|
||||
import 'package:bahla_front/ui/common/app_strings.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
class HomeViewModel extends BaseViewModel {
|
||||
final _dialogService = locator<DialogService>();
|
||||
final _bottomSheetService = locator<BottomSheetService>();
|
||||
|
||||
String get counterLabel => 'Counter is: $_counter';
|
||||
|
||||
int _counter = 0;
|
||||
|
||||
void incrementCounter() {
|
||||
_counter++;
|
||||
rebuildUi();
|
||||
}
|
||||
|
||||
void showDialog() {
|
||||
_dialogService.showCustomDialog(
|
||||
variant: DialogType.infoAlert,
|
||||
title: 'Stacked Rocks!',
|
||||
description: 'Give stacked $_counter stars on Github',
|
||||
);
|
||||
}
|
||||
|
||||
void showBottomSheet() {
|
||||
_bottomSheetService.showCustomSheet(
|
||||
variant: BottomSheetType.notice,
|
||||
title: ksHomeBottomSheetTitle,
|
||||
description: ksHomeBottomSheetDescription,
|
||||
);
|
||||
}
|
||||
}
|
||||
56
lib/ui/views/startup/startup_view.dart
Normal file
56
lib/ui/views/startup/startup_view.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:bahla_front/ui/common/ui_helpers.dart';
|
||||
|
||||
import 'startup_viewmodel.dart';
|
||||
|
||||
class StartupView extends StackedView<StartupViewModel> {
|
||||
const StartupView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget builder(
|
||||
BuildContext context,
|
||||
StartupViewModel viewModel,
|
||||
Widget? child,
|
||||
) {
|
||||
return const Scaffold(
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'STACKED',
|
||||
style: TextStyle(fontSize: 40, fontWeight: FontWeight.w900),
|
||||
),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('Loading ...', style: TextStyle(fontSize: 16)),
|
||||
horizontalSpaceSmall,
|
||||
SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.black,
|
||||
strokeWidth: 6,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
StartupViewModel viewModelBuilder(
|
||||
BuildContext context,
|
||||
) =>
|
||||
StartupViewModel();
|
||||
|
||||
@override
|
||||
void onViewModelReady(StartupViewModel viewModel) => SchedulerBinding.instance
|
||||
.addPostFrameCallback((timeStamp) => viewModel.runStartupLogic());
|
||||
}
|
||||
18
lib/ui/views/startup/startup_viewmodel.dart
Normal file
18
lib/ui/views/startup/startup_viewmodel.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:bahla_front/app/app.locator.dart';
|
||||
import 'package:bahla_front/app/app.router.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
class StartupViewModel extends BaseViewModel {
|
||||
final _navigationService = locator<NavigationService>();
|
||||
|
||||
// Place anything here that needs to happen before we get into the application
|
||||
Future runStartupLogic() async {
|
||||
await Future.delayed(const Duration(seconds: 3));
|
||||
|
||||
// This is where you can make decisions on where your app should navigate when
|
||||
// you have custom startup logic
|
||||
|
||||
_navigationService.replaceWithHomeView();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user