mirror of
https://github.com/smmarty/friflex_flutter_starter.git
synced 2025-12-22 09:30:45 +00:00
refactor(full refactor): Рефакторинг стартера (#8)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:friflex_starter/features/main/presentation/screens/main_detail_screen.dart';
|
||||
import 'package:friflex_starter/features/main/presentation/screens/main_screen.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
@@ -6,9 +7,15 @@ abstract final class MainRoutes {
|
||||
/// Название роута главной страницы
|
||||
static const String mainScreenName = 'main_screen';
|
||||
|
||||
/// Название роута экрана с деталями
|
||||
static const String mainDetailScreenName = 'main_detail_screen';
|
||||
|
||||
/// Путь роута страницы профиля пользователя
|
||||
static const String _mainScreenPath = '/main';
|
||||
|
||||
/// Путь роута экрана с деталями
|
||||
static const String _mainDetailScreenPath = '/main/detail';
|
||||
|
||||
/// Метод для построения ветки роутов по фиче профиля пользователя
|
||||
///
|
||||
/// Принимает:
|
||||
@@ -21,11 +28,19 @@ abstract final class MainRoutes {
|
||||
initialLocation: _mainScreenPath,
|
||||
observers: observers,
|
||||
routes: [
|
||||
...routes,
|
||||
GoRoute(
|
||||
path: _mainScreenPath,
|
||||
name: mainScreenName,
|
||||
builder: (context, state) => const MainScreen(),
|
||||
routes: routes,
|
||||
routes: [
|
||||
// Пример вложенного роута для главного экрана
|
||||
GoRoute(
|
||||
path: _mainDetailScreenPath,
|
||||
name: mainDetailScreenName,
|
||||
builder: (context, state) => const MainDetailScreen(),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// {@template MainDetailScreen}
|
||||
/// Вложенный экран для главного экрана приложения
|
||||
/// {@endtemplate}
|
||||
class MainDetailScreen extends StatelessWidget {
|
||||
/// {@macro MainDetailScreen}
|
||||
const MainDetailScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Main Detail Screen'),
|
||||
),
|
||||
body: const Center(
|
||||
child: Text('Вложенный экран'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:friflex_starter/app/app_box.dart';
|
||||
import 'package:friflex_starter/features/main/presentation/main_routes.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
/// {@template MainScreen}
|
||||
/// Главный экран приложения
|
||||
/// {@endtemplate}
|
||||
class MainScreen extends StatelessWidget {
|
||||
/// {@macro MainScreen}
|
||||
const MainScreen({super.key});
|
||||
|
||||
@override
|
||||
@@ -12,20 +18,16 @@ class MainScreen extends StatelessWidget {
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('Главный экран приложения'),
|
||||
const HBox(16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
context.push('/profile');
|
||||
// Переход на экран с деталями
|
||||
context.pushNamed(MainRoutes.mainDetailScreenName);
|
||||
},
|
||||
child: const Text('Открыть профиль'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
context.push('/profile_scope');
|
||||
},
|
||||
child: const Text('Открыть профиль с областью видимости'),
|
||||
child: const Text('Переход на экран с деталями'),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user