Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
838d6aa668 | ||
|
|
be554094cd | ||
|
|
7b16b52761 | ||
|
|
2ceed8b9b5 | ||
|
|
6e8d926693 | ||
|
|
8de38299e2 | ||
|
|
5396712cf9 | ||
|
|
8fb4bf57d6 | ||
|
|
88cd6fb3b4 | ||
|
|
8ef81ddb33 | ||
|
|
a1a70fae78 | ||
|
|
95e510d814 | ||
|
|
39c38ca975 | ||
|
|
9c91d7d7f3 | ||
|
|
9313882748 | ||
|
|
0b3126182e | ||
|
|
8a95ed4417 | ||
|
|
e26099ac18 | ||
|
|
bcba7ebae2 |
@@ -1,27 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'pages/home_page.dart';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const MyApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
title: 'Flutter Demo',
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
theme: ThemeData(
|
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
|
||||||
useMaterial3: true,
|
|
||||||
),
|
|
||||||
home: const HomePage(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class ColorAddPage extends StatefulWidget {
|
|
||||||
const ColorAddPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<ColorAddPage> createState() => _ColorAddPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ColorAddPageState extends State<ColorAddPage> {
|
|
||||||
late Color _color;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_color = randomColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
String text = '# ${_color.value.toRadixString(16)}';
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text('添加颜色'),
|
|
||||||
actions: [IconButton(onPressed: _selectColor, icon: Icon(Icons.check ))],
|
|
||||||
),
|
|
||||||
body: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0,vertical: 20),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(child: Text(text,style: TextStyle(color: _color,fontSize: 24,letterSpacing: 4),)),
|
|
||||||
Container(
|
|
||||||
margin: EdgeInsets.only(left: 10),
|
|
||||||
width: 40,
|
|
||||||
height: 40,
|
|
||||||
child: Icon(
|
|
||||||
Icons.sell_outlined,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: _color,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Random _random = Random();
|
|
||||||
|
|
||||||
Color get randomColor {
|
|
||||||
return Color.fromARGB(
|
|
||||||
255,
|
|
||||||
_random.nextInt(256),
|
|
||||||
_random.nextInt(256),
|
|
||||||
_random.nextInt(256),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _selectColor() {
|
|
||||||
Navigator.of(context).pop(_color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'color_add_page.dart';
|
|
||||||
|
|
||||||
import '../../../common/components/colors_panel.dart';
|
|
||||||
import '../../../common/pages/stl_color_page.dart';
|
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<HomePage> createState() => _HomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _HomePageState extends State<HomePage> {
|
|
||||||
final List<Color> _colors = [
|
|
||||||
Colors.red, Colors.black, Colors.blue, Colors.green, Colors.orange,
|
|
||||||
Colors.pink, Colors.purple, Colors.indigo, Colors.amber, Colors.cyan,
|
|
||||||
Colors.redAccent, Colors.grey, Colors.blueAccent, Colors.greenAccent, Colors.orangeAccent,
|
|
||||||
Colors.pinkAccent, Colors.purpleAccent, Colors.indigoAccent, Colors.amberAccent, Colors.cyanAccent,
|
|
||||||
];
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(title:const Text('颜色主页')),
|
|
||||||
floatingActionButton: FloatingActionButton(
|
|
||||||
onPressed: _toAddPage,
|
|
||||||
child: const Icon(Icons.add),
|
|
||||||
),
|
|
||||||
body: ColorsPanel(
|
|
||||||
colors: _colors,
|
|
||||||
onSelect: _selectColor,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _selectColor(Color color){
|
|
||||||
Route route = MaterialPageRoute(builder: (ctx) => StlColorPage(color: color));
|
|
||||||
Navigator.of(context).push(route);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _toAddPage() async {
|
|
||||||
Route<Color> route = MaterialPageRoute<Color>(builder: (ctx) => const ColorAddPage());
|
|
||||||
Color? color = await Navigator.of(context).push(route);
|
|
||||||
if (color != null) {
|
|
||||||
setState(() {
|
|
||||||
_colors.add(color);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'pages/color_add_page.dart';
|
|
||||||
import '../../common/pages/stl_color_page.dart';
|
|
||||||
import 'pages/empty_page.dart';
|
|
||||||
import 'pages/home_page.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const MyApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
title: 'Flutter Demo',
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
theme: ThemeData(
|
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
|
||||||
useMaterial3: true,
|
|
||||||
),
|
|
||||||
routes: routeMap,
|
|
||||||
// initialRoute: '/add_color',
|
|
||||||
onUnknownRoute: _onUnknownRoute,
|
|
||||||
onGenerateRoute: _onGenerateRoute,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 路由映射 [字符串 --> 组件构造器]
|
|
||||||
Map<String, WidgetBuilder> get routeMap => {
|
|
||||||
'/': (ctx) => const HomePage(),
|
|
||||||
'/add_color': (ctx) => const ColorAddPage(),
|
|
||||||
};
|
|
||||||
|
|
||||||
/// 根据路由配置 [settings] 创建路由
|
|
||||||
Route? _onGenerateRoute(RouteSettings settings) {
|
|
||||||
String? name = settings.name;
|
|
||||||
Widget? child;
|
|
||||||
if (name == '/color_detail') {
|
|
||||||
Color color = settings.arguments as Color;
|
|
||||||
child = StlColorPage(color: color);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (child != null) {
|
|
||||||
return MaterialPageRoute(
|
|
||||||
builder: (ctx) => child!,
|
|
||||||
settings: settings,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Route? _onUnknownRoute(RouteSettings settings) {
|
|
||||||
return MaterialPageRoute(
|
|
||||||
builder: (ctx) => const EmptyPage(),
|
|
||||||
settings: settings,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class ColorAddPage extends StatefulWidget {
|
|
||||||
const ColorAddPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<ColorAddPage> createState() => _ColorAddPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ColorAddPageState extends State<ColorAddPage> {
|
|
||||||
late Color _color;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_color = randomColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
String text = '# ${_color.value.toRadixString(16)}';
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text('添加颜色'),
|
|
||||||
actions: [IconButton(onPressed: _selectColor, icon: Icon(Icons.check ))],
|
|
||||||
),
|
|
||||||
body: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0,vertical: 20),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(child: Text(text,style: TextStyle(color: _color,fontSize: 24,letterSpacing: 4),)),
|
|
||||||
Container(
|
|
||||||
margin: EdgeInsets.only(left: 10),
|
|
||||||
width: 40,
|
|
||||||
height: 40,
|
|
||||||
child: Icon(
|
|
||||||
Icons.sell_outlined,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: _color,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Random _random = Random();
|
|
||||||
|
|
||||||
Color get randomColor {
|
|
||||||
return Color.fromARGB(
|
|
||||||
255,
|
|
||||||
_random.nextInt(256),
|
|
||||||
_random.nextInt(256),
|
|
||||||
_random.nextInt(256),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _selectColor() {
|
|
||||||
Navigator.of(context).pop(_color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'color_add_page.dart';
|
|
||||||
|
|
||||||
import '../../../common/components/colors_panel.dart';
|
|
||||||
import '../../../common/pages/stl_color_page.dart';
|
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<HomePage> createState() => _HomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _HomePageState extends State<HomePage> {
|
|
||||||
final List<Color> _colors = [
|
|
||||||
Colors.red, Colors.black, Colors.blue, Colors.green, Colors.orange,
|
|
||||||
Colors.pink, Colors.purple, Colors.indigo, Colors.amber, Colors.cyan,
|
|
||||||
Colors.redAccent, Colors.grey, Colors.blueAccent, Colors.greenAccent, Colors.orangeAccent,
|
|
||||||
Colors.pinkAccent, Colors.purpleAccent, Colors.indigoAccent, Colors.amberAccent, Colors.cyanAccent,
|
|
||||||
];
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(title:const Text('颜色主页 V2')),
|
|
||||||
floatingActionButton: FloatingActionButton(
|
|
||||||
onPressed: _toAddPage,
|
|
||||||
child: const Icon(Icons.add),
|
|
||||||
),
|
|
||||||
body: ColorsPanel(
|
|
||||||
colors: _colors,
|
|
||||||
onSelect: _selectColor,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _selectColor(Color color){
|
|
||||||
Navigator.of(context).pushNamed('/color_detail1',arguments: color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _toAddPage() async {
|
|
||||||
dynamic color = await Navigator.of(context).pushNamed('/add_color');
|
|
||||||
if (color != null) {
|
|
||||||
setState(() {
|
|
||||||
_colors.add(color);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'router1/router1.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const MyApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
title: 'Flutter Demo',
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
theme: ThemeData(
|
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
|
||||||
useMaterial3: true,
|
|
||||||
),
|
|
||||||
|
|
||||||
routes: Router1.routeMap,
|
|
||||||
navigatorKey: Router1.globalNavKey,
|
|
||||||
onUnknownRoute: Router1.onUnknownRoute,
|
|
||||||
initialRoute: Router1.initialRoute,
|
|
||||||
onGenerateRoute: Router1.onGenerateRoute,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class ColorAddPage extends StatefulWidget {
|
|
||||||
const ColorAddPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<ColorAddPage> createState() => _ColorAddPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ColorAddPageState extends State<ColorAddPage> {
|
|
||||||
late Color _color;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_color = randomColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
String text = '# ${_color.value.toRadixString(16)}';
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text('添加颜色'),
|
|
||||||
actions: [IconButton(onPressed: _selectColor, icon: Icon(Icons.check ))],
|
|
||||||
),
|
|
||||||
body: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0,vertical: 20),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(child: Text(text,style: TextStyle(color: _color,fontSize: 24,letterSpacing: 4),)),
|
|
||||||
Container(
|
|
||||||
margin: EdgeInsets.only(left: 10),
|
|
||||||
width: 40,
|
|
||||||
height: 40,
|
|
||||||
child: Icon(
|
|
||||||
Icons.sell_outlined,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: _color,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Random _random = Random();
|
|
||||||
|
|
||||||
Color get randomColor {
|
|
||||||
return Color.fromARGB(
|
|
||||||
255,
|
|
||||||
_random.nextInt(256),
|
|
||||||
_random.nextInt(256),
|
|
||||||
_random.nextInt(256),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _selectColor() {
|
|
||||||
Navigator.of(context).pop(_color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import '../router1/router1.dart';
|
|
||||||
|
|
||||||
import '../../../common/components/colors_panel.dart';
|
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<HomePage> createState() => _HomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _HomePageState extends State<HomePage> {
|
|
||||||
final List<Color> _colors = [
|
|
||||||
Colors.red, Colors.black, Colors.blue, Colors.green, Colors.orange,
|
|
||||||
Colors.pink, Colors.purple, Colors.indigo, Colors.amber, Colors.cyan,
|
|
||||||
Colors.redAccent, Colors.grey, Colors.blueAccent, Colors.greenAccent, Colors.orangeAccent,
|
|
||||||
Colors.pinkAccent, Colors.purpleAccent, Colors.indigoAccent, Colors.amberAccent, Colors.cyanAccent,
|
|
||||||
];
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(title:const Text('颜色主页 V3')),
|
|
||||||
floatingActionButton: FloatingActionButton(
|
|
||||||
onPressed: _toAddPage,
|
|
||||||
child: const Icon(Icons.add),
|
|
||||||
),
|
|
||||||
body: ColorsPanel(
|
|
||||||
colors: _colors,
|
|
||||||
onSelect: _selectColor,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _selectColor(Color color){
|
|
||||||
|
|
||||||
Router1.nav.pushNamed(Router1.kColorDetail,arguments: color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _toAddPage() async {
|
|
||||||
dynamic color = await Router1.nav.pushNamed(Router1.kAddColor);
|
|
||||||
if (color != null) {
|
|
||||||
setState(() {
|
|
||||||
_colors.add(color);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import '../../../common/pages/stl_color_page.dart';
|
|
||||||
import '../pages/color_add_page.dart';
|
|
||||||
import '../pages/empty_page.dart';
|
|
||||||
import '../pages/home_page.dart';
|
|
||||||
|
|
||||||
class Router1 {
|
|
||||||
|
|
||||||
/// 主页面 [HomePage]
|
|
||||||
static const String kHome = '/';
|
|
||||||
|
|
||||||
/// 颜色详情页 [StlColorPage]
|
|
||||||
static const String kColorDetail = '${kHome}color_detail';
|
|
||||||
|
|
||||||
/// 添加颜色页 [ColorAddPage]
|
|
||||||
static const String kAddColor = '${kHome}add_color';
|
|
||||||
|
|
||||||
|
|
||||||
static String get initialRoute => kHome;
|
|
||||||
|
|
||||||
static final GlobalKey<NavigatorState> globalNavKey = GlobalKey();
|
|
||||||
|
|
||||||
static NavigatorState get nav => globalNavKey.currentState!;
|
|
||||||
|
|
||||||
/// 路由映射 [字符串 --> 组件构造器]
|
|
||||||
static Map<String, WidgetBuilder> get routeMap => {
|
|
||||||
kHome: (ctx) => const HomePage(),
|
|
||||||
kAddColor: (ctx) => const ColorAddPage(),
|
|
||||||
};
|
|
||||||
|
|
||||||
/// 根据路由配置 [settings] 创建路由
|
|
||||||
static Route? onGenerateRoute(RouteSettings settings) {
|
|
||||||
String? name = settings.name;
|
|
||||||
Widget? child;
|
|
||||||
if (name == kColorDetail) {
|
|
||||||
Color color = settings.arguments as Color;
|
|
||||||
child = StlColorPage(color: color);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (child != null) {
|
|
||||||
return MaterialPageRoute(
|
|
||||||
builder: (ctx) => child!,
|
|
||||||
settings: settings,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Route? onUnknownRoute(RouteSettings settings) {
|
|
||||||
return MaterialPageRoute(
|
|
||||||
builder: (ctx) => const EmptyPage(),
|
|
||||||
settings: settings,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const OverlayPage());
|
|
||||||
}
|
|
||||||
|
|
||||||
class OverlayPage extends StatelessWidget{
|
|
||||||
const OverlayPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final OverlayEntry home = OverlayEntry(builder: (BuildContext context) => const HomePage());
|
|
||||||
|
|
||||||
return Directionality(
|
|
||||||
textDirection: TextDirection.ltr,
|
|
||||||
child: Overlay(
|
|
||||||
initialEntries: [home],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class HomePage extends StatelessWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return const ColoredBox(
|
|
||||||
color: Colors.white,
|
|
||||||
child: Align(
|
|
||||||
child: FlutterLogo(size: 60,),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const OverlayPage());
|
|
||||||
}
|
|
||||||
|
|
||||||
class OverlayPage extends StatelessWidget{
|
|
||||||
const OverlayPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final OverlayEntry home = OverlayEntry(builder: (BuildContext context) => const HomePage());
|
|
||||||
final OverlayEntry circle = OverlayEntry(builder: (BuildContext context) => const Center(child: Circle()));
|
|
||||||
|
|
||||||
return Directionality(
|
|
||||||
textDirection: TextDirection.ltr,
|
|
||||||
child: Overlay(
|
|
||||||
initialEntries: [home,circle],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class HomePage extends StatelessWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return const ColoredBox(
|
|
||||||
color: Colors.white,
|
|
||||||
child: Align(
|
|
||||||
child: FlutterLogo(
|
|
||||||
size: 60,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Circle extends StatelessWidget {
|
|
||||||
const Circle({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
decoration: const BoxDecoration(
|
|
||||||
color: Colors.redAccent,
|
|
||||||
shape: BoxShape.circle
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const OverlayPage());
|
|
||||||
}
|
|
||||||
|
|
||||||
class OverlayPage extends StatelessWidget{
|
|
||||||
const OverlayPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final OverlayEntry home =
|
|
||||||
OverlayEntry(builder: (BuildContext context) => const HomePage());
|
|
||||||
|
|
||||||
final OverlayEntry circle = OverlayEntry(
|
|
||||||
builder: (BuildContext context) => Positioned(
|
|
||||||
top: 50,
|
|
||||||
left: 50,
|
|
||||||
child: const Circle(),
|
|
||||||
));
|
|
||||||
|
|
||||||
return Directionality(
|
|
||||||
textDirection: TextDirection.ltr,
|
|
||||||
child: Overlay(
|
|
||||||
initialEntries: [home, circle],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class HomePage extends StatelessWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return const ColoredBox(
|
|
||||||
color: Colors.white,
|
|
||||||
child: Align(
|
|
||||||
child: FlutterLogo(
|
|
||||||
size: 60,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Circle extends StatelessWidget {
|
|
||||||
const Circle({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
decoration:
|
|
||||||
const BoxDecoration(color: Colors.redAccent, shape: BoxShape.circle),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const OverlayPage());
|
|
||||||
}
|
|
||||||
|
|
||||||
class OverlayPage extends StatefulWidget {
|
|
||||||
const OverlayPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<OverlayPage> createState() => _OverlayPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _OverlayPageState extends State<OverlayPage> {
|
|
||||||
double _left = 0;
|
|
||||||
double _top = 0;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final OverlayEntry home =
|
|
||||||
OverlayEntry(builder: (BuildContext context) => const HomePage());
|
|
||||||
|
|
||||||
final OverlayEntry circle = OverlayEntry(
|
|
||||||
builder: (BuildContext context) => Positioned(
|
|
||||||
top: 50,
|
|
||||||
left: 50,
|
|
||||||
child: GestureDetector(
|
|
||||||
onPanUpdate: _updatePosition,
|
|
||||||
child: const Circle(),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
|
|
||||||
return Directionality(
|
|
||||||
textDirection: TextDirection.ltr,
|
|
||||||
child: Overlay(
|
|
||||||
initialEntries: [home, circle],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _updatePosition(DragUpdateDetails details) {
|
|
||||||
setState(() {
|
|
||||||
_top += details.delta.dy;
|
|
||||||
_left += details.delta.dx;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class HomePage extends StatelessWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return const ColoredBox(
|
|
||||||
color: Colors.white,
|
|
||||||
child: Align(
|
|
||||||
child: FlutterLogo(
|
|
||||||
size: 60,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Circle extends StatelessWidget {
|
|
||||||
const Circle({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
decoration:
|
|
||||||
const BoxDecoration(color: Colors.redAccent, shape: BoxShape.circle),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const OverlayPage());
|
|
||||||
}
|
|
||||||
|
|
||||||
class OverlayPage extends StatefulWidget {
|
|
||||||
const OverlayPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<OverlayPage> createState() => _OverlayPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _OverlayPageState extends State<OverlayPage> {
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final OverlayEntry home = OverlayEntry(builder: (BuildContext context) => const HomePage());
|
|
||||||
return Directionality(
|
|
||||||
textDirection: TextDirection.ltr,
|
|
||||||
child: Overlay(
|
|
||||||
initialEntries: [home],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<HomePage> createState() => _HomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _HomePageState extends State<HomePage> {
|
|
||||||
|
|
||||||
OverlayEntry? entry;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return ColoredBox(
|
|
||||||
color: Colors.white,
|
|
||||||
child: Align(
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: _toggle,
|
|
||||||
child: const FlutterLogo(
|
|
||||||
size: 60,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _toggle() {
|
|
||||||
if(entry==null){
|
|
||||||
entry = _createPoint();
|
|
||||||
Overlay.of(context).insert(entry!);
|
|
||||||
}else{
|
|
||||||
entry!.remove();
|
|
||||||
entry = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
OverlayEntry _createPoint() {
|
|
||||||
return OverlayEntry(
|
|
||||||
builder: (BuildContext context) => Positioned(
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
left: 20,
|
|
||||||
top: 20,
|
|
||||||
child: GestureDetector(child: const Circle()),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ClickShowPage extends StatefulWidget {
|
|
||||||
const ClickShowPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<ClickShowPage> createState() => _ClickShowPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ClickShowPageState extends State<ClickShowPage> {
|
|
||||||
Offset _position = Offset.zero;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: _addPoint,
|
|
||||||
onTapDown: _onTapDown,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _addPoint() {
|
|
||||||
OverlayEntry entry = _createPoint();
|
|
||||||
Overlay.of(context).insert(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
OverlayEntry _createPoint() {
|
|
||||||
return OverlayEntry(
|
|
||||||
builder: (BuildContext context) => Positioned(
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
left: _position.dx - 10,
|
|
||||||
top: _position.dy - 10,
|
|
||||||
child: Circle()),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onTapDown(TapDownDetails details) {
|
|
||||||
_position = details.localPosition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Circle extends StatelessWidget {
|
|
||||||
const Circle({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
decoration:
|
|
||||||
const BoxDecoration(color: Colors.redAccent, shape: BoxShape.circle),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'pages/home_page.dart';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const MyApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
title: 'Flutter Demo',
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
theme: ThemeData(
|
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
|
||||||
useMaterial3: true,
|
|
||||||
),
|
|
||||||
home: const HomePage(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class ColorAddPage extends StatefulWidget {
|
|
||||||
const ColorAddPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<ColorAddPage> createState() => _ColorAddPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ColorAddPageState extends State<ColorAddPage> {
|
|
||||||
late Color _color;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_color = randomColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
String text = '# ${_color.value.toRadixString(16)}';
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text('添加颜色'),
|
|
||||||
actions: [IconButton(onPressed: _selectColor, icon: Icon(Icons.check ))],
|
|
||||||
),
|
|
||||||
body: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0,vertical: 20),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(child: Text(text,style: TextStyle(color: _color,fontSize: 24,letterSpacing: 4),)),
|
|
||||||
Container(
|
|
||||||
margin: EdgeInsets.only(left: 10),
|
|
||||||
width: 40,
|
|
||||||
height: 40,
|
|
||||||
child: Icon(
|
|
||||||
Icons.sell_outlined,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: _color,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Random _random = Random();
|
|
||||||
|
|
||||||
Color get randomColor {
|
|
||||||
return Color.fromARGB(
|
|
||||||
255,
|
|
||||||
_random.nextInt(256),
|
|
||||||
_random.nextInt(256),
|
|
||||||
_random.nextInt(256),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _selectColor() {
|
|
||||||
Navigator.of(context).pop(_color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'color_add_page.dart';
|
|
||||||
|
|
||||||
import '../../../common/components/colors_panel.dart';
|
|
||||||
import '../../../common/pages/stl_color_page.dart';
|
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<HomePage> createState() => _HomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _HomePageState extends State<HomePage> {
|
|
||||||
final List<Color> _colors = [
|
|
||||||
Colors.red, Colors.black, Colors.blue, Colors.green, Colors.orange,
|
|
||||||
Colors.pink, Colors.purple, Colors.indigo, Colors.amber, Colors.cyan,
|
|
||||||
Colors.redAccent, Colors.grey, Colors.blueAccent, Colors.greenAccent, Colors.orangeAccent,
|
|
||||||
Colors.pinkAccent, Colors.purpleAccent, Colors.indigoAccent, Colors.amberAccent, Colors.cyanAccent,
|
|
||||||
];
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(title:const Text('颜色主页')),
|
|
||||||
floatingActionButton: FloatingActionButton(
|
|
||||||
onPressed: _toAddPage,
|
|
||||||
child: const Icon(Icons.add),
|
|
||||||
),
|
|
||||||
body: ColorsPanel(
|
|
||||||
colors: _colors,
|
|
||||||
onSelect: _selectColor,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _selectColor(Color color){
|
|
||||||
Route route = MaterialPageRoute(builder: (ctx) => StlColorPage(color: color));
|
|
||||||
Navigator.of(context).push(route);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _toAddPage() async {
|
|
||||||
Route<Color> route = MaterialPageRoute<Color>(builder: (ctx) => const ColorAddPage());
|
|
||||||
Color? color = await Navigator.of(context).push(route);
|
|
||||||
if (color != null) {
|
|
||||||
setState(() {
|
|
||||||
_colors.add(color);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'pages/home_page.dart';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const MyApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
title: 'Flutter Demo',
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
theme: ThemeData(
|
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
|
||||||
useMaterial3: true,
|
|
||||||
),
|
|
||||||
home: const HomePage(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class ColorAddPage extends StatefulWidget {
|
|
||||||
const ColorAddPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<ColorAddPage> createState() => _ColorAddPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ColorAddPageState extends State<ColorAddPage> {
|
|
||||||
late Color _color;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_color = randomColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
String text = '# ${_color.value.toRadixString(16)}';
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text('添加颜色'),
|
|
||||||
actions: [IconButton(onPressed: _selectColor, icon: Icon(Icons.check ))],
|
|
||||||
),
|
|
||||||
body: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0,vertical: 20),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(child: Text(text,style: TextStyle(color: _color,fontSize: 24,letterSpacing: 4),)),
|
|
||||||
Container(
|
|
||||||
margin: EdgeInsets.only(left: 10),
|
|
||||||
width: 40,
|
|
||||||
height: 40,
|
|
||||||
child: Icon(
|
|
||||||
Icons.sell_outlined,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: _color,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Random _random = Random();
|
|
||||||
|
|
||||||
Color get randomColor {
|
|
||||||
return Color.fromARGB(
|
|
||||||
255,
|
|
||||||
_random.nextInt(256),
|
|
||||||
_random.nextInt(256),
|
|
||||||
_random.nextInt(256),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _selectColor() {
|
|
||||||
Navigator.of(context).pop(_color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'color_add_page.dart';
|
|
||||||
|
|
||||||
import '../../../common/components/colors_panel.dart';
|
|
||||||
import '../../../common/pages/stl_color_page.dart';
|
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<HomePage> createState() => _HomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _HomePageState extends State<HomePage> {
|
|
||||||
final List<Color> _colors = [
|
|
||||||
Colors.red, Colors.black, Colors.blue, Colors.green, Colors.orange,
|
|
||||||
Colors.pink, Colors.purple, Colors.indigo, Colors.amber, Colors.cyan,
|
|
||||||
Colors.redAccent, Colors.grey, Colors.blueAccent, Colors.greenAccent, Colors.orangeAccent,
|
|
||||||
Colors.pinkAccent, Colors.purpleAccent, Colors.indigoAccent, Colors.amberAccent, Colors.cyanAccent,
|
|
||||||
];
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(title:const Text('颜色主页')),
|
|
||||||
floatingActionButton: FloatingActionButton(
|
|
||||||
onPressed: _toAddPage,
|
|
||||||
child: const Icon(Icons.add),
|
|
||||||
),
|
|
||||||
body: ColorsPanel(
|
|
||||||
colors: _colors,
|
|
||||||
onSelect: _selectColor,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _selectColor(Color color){
|
|
||||||
Route route = MaterialPageRoute(builder: (ctx) => StlColorPage(color: color));
|
|
||||||
Navigator.of(context).push(route);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _toAddPage() async {
|
|
||||||
Route<Color> route = MaterialPageRoute<Color>(builder: (ctx) => const ColorAddPage());
|
|
||||||
Color? color = await Navigator.of(context).push(route);
|
|
||||||
if (color != null) {
|
|
||||||
setState(() {
|
|
||||||
_colors.add(color);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'pages/page_a.dart';
|
|
||||||
import 'pages/page_b.dart';
|
|
||||||
import 'pages/home_page.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const MyApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
title: 'Flutter Demo',
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
theme: ThemeData(
|
|
||||||
appBarTheme: AppBarTheme(
|
|
||||||
elevation: 0,
|
|
||||||
iconTheme: IconThemeData(color: Colors.black),
|
|
||||||
titleTextStyle: TextStyle(color: Colors.black,fontSize: 18,fontWeight: FontWeight.bold)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
initialRoute: '/a/b',
|
|
||||||
onGenerateRoute: _onGenerateRoute,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Route? _onGenerateRoute(RouteSettings settings) {
|
|
||||||
String? name = settings.name;
|
|
||||||
Widget? page ;
|
|
||||||
if(name=='/'){
|
|
||||||
page = const HomePage();
|
|
||||||
}
|
|
||||||
if(name=='/a'){
|
|
||||||
page = const PageA();
|
|
||||||
}
|
|
||||||
if(name=='/a/b'){
|
|
||||||
page = const PageB();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(page!=null){
|
|
||||||
return MaterialPageRoute(builder: (_)=> page!,settings: settings);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class HomePage extends StatelessWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffFFE6CD);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('主页面'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageA(context),
|
|
||||||
child: const Text('Push A'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageA(BuildContext context){
|
|
||||||
Navigator.of(context).pushNamed('/a');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'page_b.dart';
|
|
||||||
|
|
||||||
class PageA extends StatelessWidget {
|
|
||||||
const PageA({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCFFFF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(title: const Text('A'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageB(context),
|
|
||||||
child: const Text('Push B'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageB(BuildContext context){
|
|
||||||
Navigator.of(context).push(MaterialPageRoute(builder: (_)=> const PageB()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'home_page.dart';
|
|
||||||
|
|
||||||
class PageB extends StatelessWidget {
|
|
||||||
const PageB({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCE5FF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(title: const Text('B',),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageC(context),
|
|
||||||
child: const Text('回到主界面'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageC(BuildContext context){
|
|
||||||
Navigator.of(context).popUntil(ModalRoute.withName('/'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'pages/page_a.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const MyApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
title: 'Flutter Demo',
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
theme: ThemeData(
|
|
||||||
appBarTheme: AppBarTheme(
|
|
||||||
elevation: 0,
|
|
||||||
iconTheme: IconThemeData(color: Colors.black),
|
|
||||||
titleTextStyle: TextStyle(color: Colors.black,fontSize: 18,fontWeight: FontWeight.bold)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
home: const PageA(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'page_b.dart';
|
|
||||||
|
|
||||||
class PageA extends StatelessWidget {
|
|
||||||
const PageA({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCFFFF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(title: const Text('A'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageB(context),
|
|
||||||
child: const Text('Push B'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageB(BuildContext context){
|
|
||||||
Navigator.of(context).push(MaterialPageRoute(builder: (_)=> const PageB()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'page_c.dart';
|
|
||||||
|
|
||||||
class PageB extends StatelessWidget {
|
|
||||||
const PageB({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCE5FF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(title: const Text('B',),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageC(context),
|
|
||||||
child: const Text('Push C'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageC(BuildContext context){
|
|
||||||
Navigator.of(context).push(MaterialPageRoute(builder: (_)=> const PageC()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class PageC extends StatelessWidget {
|
|
||||||
const PageC({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffFFE6CD);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('C'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: const Center(
|
|
||||||
child: Text('到达终点'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
01: 分析 push 方法。
|
|
||||||
A、B、C 三个界面跳转。
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'pages/page_a.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const MyApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
title: 'Flutter Demo',
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
theme: ThemeData(
|
|
||||||
appBarTheme: AppBarTheme(
|
|
||||||
elevation: 0,
|
|
||||||
iconTheme: IconThemeData(color: Colors.black),
|
|
||||||
titleTextStyle: TextStyle(color: Colors.black,fontSize: 18,fontWeight: FontWeight.bold)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
home: const PageA(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'page_b.dart';
|
|
||||||
|
|
||||||
class PageA extends StatelessWidget {
|
|
||||||
const PageA({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCFFFF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(title: const Text('A'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageB(context),
|
|
||||||
child: const Text('Push B'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageB(BuildContext context){
|
|
||||||
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_)=> const PageB()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'page_c.dart';
|
|
||||||
|
|
||||||
class PageB extends StatelessWidget {
|
|
||||||
const PageB({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCE5FF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(title: const Text('B',),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageC(context),
|
|
||||||
child: const Text('Push C'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageC(BuildContext context){
|
|
||||||
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_)=> const PageC()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class PageC extends StatelessWidget {
|
|
||||||
const PageC({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffFFE6CD);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('C'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: const Center(
|
|
||||||
child: Text('到达终点'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'pages/page_a.dart';
|
|
||||||
import 'pages/page_b.dart';
|
|
||||||
import 'pages/page_c.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const MyApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
title: 'Flutter Demo',
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
theme: ThemeData(
|
|
||||||
appBarTheme: AppBarTheme(
|
|
||||||
elevation: 0,
|
|
||||||
iconTheme: IconThemeData(color: Colors.black),
|
|
||||||
titleTextStyle: TextStyle(color: Colors.black,fontSize: 18,fontWeight: FontWeight.bold)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
home: const HomePage(),
|
|
||||||
onUnknownRoute: _onUnknownRoute,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Route? _onUnknownRoute(RouteSettings settings) {
|
|
||||||
String? name = settings.name;
|
|
||||||
Widget? page ;
|
|
||||||
if(name=='/a'){
|
|
||||||
page = const PageA();
|
|
||||||
}
|
|
||||||
if(name=='/b'){
|
|
||||||
page = const PageB();
|
|
||||||
}
|
|
||||||
if(name=='/c'){
|
|
||||||
page = const PageC();
|
|
||||||
}
|
|
||||||
if(page!=null){
|
|
||||||
return MaterialPageRoute(builder: (_)=> page!,settings: settings);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class HomePage extends StatelessWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCFFFF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(title: const Text('主页'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageA(context),
|
|
||||||
child: const Text('Push A'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageA(BuildContext context){
|
|
||||||
Navigator.of(context).pushNamed('/a');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'page_b.dart';
|
|
||||||
|
|
||||||
class PageA extends StatelessWidget {
|
|
||||||
const PageA({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCFFFF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(title: const Text('A'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageB(context),
|
|
||||||
child: const Text('Push B'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageB(BuildContext context){
|
|
||||||
Navigator.of(context).pushNamed('/b');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'page_c.dart';
|
|
||||||
|
|
||||||
class PageB extends StatelessWidget {
|
|
||||||
const PageB({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCE5FF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(title: const Text('B',),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageC(context),
|
|
||||||
child: const Text('Push C'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageC(BuildContext context){
|
|
||||||
Navigator.of(context).pushNamed('/c');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'page_d.dart';
|
|
||||||
|
|
||||||
class PageC extends StatelessWidget {
|
|
||||||
const PageC({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffFFE6CD);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('C'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageD(context),
|
|
||||||
child: const Text('Push D Remove Until A'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageD(BuildContext context){
|
|
||||||
Navigator.of(context).pushAndRemoveUntil(
|
|
||||||
MaterialPageRoute<void>(builder: (BuildContext context) => const PageD()),
|
|
||||||
ModalRoute.withName('/a'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:iroute/06/02/pages/page_a.dart';
|
|
||||||
|
|
||||||
class PageD extends StatelessWidget {
|
|
||||||
const PageD({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffFFCCFF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('D'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: const Text('到达终点'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
01: 分析 pushReplacement 方法。
|
|
||||||
A、B、C 三个界面跳转。
|
|
||||||
|
|
||||||
02: 分析 pushAndRemoveUntil 方法。
|
|
||||||
A、B、C、D 四个界面跳转。
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'pages/page_a.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const MyApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
title: 'Flutter Demo',
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
theme: ThemeData(
|
|
||||||
appBarTheme: AppBarTheme(
|
|
||||||
elevation: 0,
|
|
||||||
iconTheme: IconThemeData(color: Colors.black),
|
|
||||||
titleTextStyle: TextStyle(color: Colors.black,fontSize: 18,fontWeight: FontWeight.bold)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
home: const PageA(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'page_b.dart';
|
|
||||||
|
|
||||||
class PageA extends StatelessWidget {
|
|
||||||
const PageA({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCFFFF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(title: const Text('A'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageB(context),
|
|
||||||
child: const Text('Push B'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageB(BuildContext context){
|
|
||||||
Navigator.of(context).push(MaterialPageRoute(builder: (_)=> const PageB()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'page_c.dart';
|
|
||||||
|
|
||||||
class PageB extends StatelessWidget {
|
|
||||||
const PageB({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCE5FF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(title: const Text('B',),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageC(context),
|
|
||||||
child: const Text('Push C'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageC(BuildContext context){
|
|
||||||
Navigator.of(context).push(MaterialPageRoute(builder: (_)=> const PageC()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class PageC extends StatelessWidget {
|
|
||||||
const PageC({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffFFE6CD);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('C'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
leading: BackButton(
|
|
||||||
onPressed: (){
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
body: const Center(
|
|
||||||
child: Text('到达终点'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'pages/page_a.dart';
|
|
||||||
import 'pages/page_b.dart';
|
|
||||||
import 'pages/page_c.dart';
|
|
||||||
import 'pages/home_page.dart';
|
|
||||||
void main() {
|
|
||||||
runApp(const MyApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
title: 'Flutter Demo',
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
theme: ThemeData(
|
|
||||||
appBarTheme: AppBarTheme(
|
|
||||||
elevation: 0,
|
|
||||||
iconTheme: IconThemeData(color: Colors.black),
|
|
||||||
titleTextStyle: TextStyle(color: Colors.black,fontSize: 18,fontWeight: FontWeight.bold)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
onUnknownRoute: _onUnknownRoute,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Route? _onUnknownRoute(RouteSettings settings) {
|
|
||||||
String? name = settings.name;
|
|
||||||
Widget? page ;
|
|
||||||
if(name=='/'){
|
|
||||||
page = const HomePage();
|
|
||||||
}
|
|
||||||
if(name=='/a'){
|
|
||||||
page = const PageA();
|
|
||||||
}
|
|
||||||
if(name=='/b'){
|
|
||||||
page = const PageB();
|
|
||||||
}
|
|
||||||
if(name=='/c'){
|
|
||||||
page = const PageC();
|
|
||||||
}
|
|
||||||
if(page!=null){
|
|
||||||
return MaterialPageRoute(builder: (_)=> page!,settings: settings);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:iroute/06/02/pages/page_a.dart';
|
|
||||||
|
|
||||||
class HomePage extends StatelessWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffFFCCFF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('起点'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageA(context),
|
|
||||||
child: const Text('Push A'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageA(BuildContext context){
|
|
||||||
Navigator.of(context).pushNamed('/a');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'page_b.dart';
|
|
||||||
|
|
||||||
class PageA extends StatelessWidget {
|
|
||||||
const PageA({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCFFFF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(title: const Text('A'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageB(context),
|
|
||||||
child: const Text('Push B'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageB(BuildContext context){
|
|
||||||
Navigator.of(context).pushNamed('/b');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'page_c.dart';
|
|
||||||
|
|
||||||
class PageB extends StatelessWidget {
|
|
||||||
const PageB({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCE5FF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(title: const Text('B',),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageC(context),
|
|
||||||
child: const Text('Push C'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageC(BuildContext context){
|
|
||||||
Navigator.of(context).pushNamed('/c');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
|
|
||||||
class PageC extends StatelessWidget {
|
|
||||||
const PageC({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffFFE6CD);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('C'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: ()=>toPageD(context),
|
|
||||||
child: const Text('pop Until A'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageD(BuildContext context){
|
|
||||||
Navigator.of(context).popUntil(
|
|
||||||
ModalRoute.withName('/a')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
01: 分析 pop 方法。
|
|
||||||
A、B、C 三个界面跳转。
|
|
||||||
|
|
||||||
02: 分析 popUntil 方法。
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class AppInfo extends StatelessWidget {
|
|
||||||
const AppInfo({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const String msg = 'FlutterUnit 是一个辅助开发者,了解 Flutter 组件和编程技术的开源项目。 ';
|
|
||||||
const String msg2 = '由张风捷特烈维护,开源地址:\n https://github.com/toly1994328/FlutterUnit ';
|
|
||||||
|
|
||||||
double height = MediaQuery.of(context).size.height;
|
|
||||||
return SizedBox(
|
|
||||||
height: height*(1-0.618),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
AppBar(
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
automaticallyImplyLeading: false,
|
|
||||||
centerTitle: true,
|
|
||||||
leading: Align(child: FlutterLogo()),
|
|
||||||
actions: [
|
|
||||||
CloseButton()
|
|
||||||
],
|
|
||||||
title: Column(
|
|
||||||
children: [
|
|
||||||
Text('FlutterUnit',style: TextStyle(fontSize: 16,fontWeight: FontWeight.bold)),
|
|
||||||
Text('v2.9.3',style: TextStyle(fontSize: 12,),),
|
|
||||||
],
|
|
||||||
),),
|
|
||||||
const Padding(
|
|
||||||
padding: EdgeInsets.symmetric(horizontal: 20.0,vertical: 10),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
// direction: Axis.vertical,
|
|
||||||
children: [
|
|
||||||
Text(msg,style: TextStyle(color: Colors.grey),),
|
|
||||||
const SizedBox(height: 8,),
|
|
||||||
Text(msg2,style: TextStyle(color: Colors.grey),),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
/// Flutter code sample for [CupertinoContextMenu].
|
|
||||||
|
|
||||||
final DecorationTween _tween = DecorationTween(
|
|
||||||
begin: BoxDecoration(
|
|
||||||
color: CupertinoColors.systemPurple,
|
|
||||||
boxShadow: const <BoxShadow>[],
|
|
||||||
borderRadius: BorderRadius.circular(20.0),
|
|
||||||
),
|
|
||||||
end: BoxDecoration(
|
|
||||||
color: CupertinoColors.systemPurple,
|
|
||||||
boxShadow: CupertinoContextMenu.kEndBoxShadow,
|
|
||||||
borderRadius: BorderRadius.circular(20.0),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
class CupertinoContextMenuDemo extends StatelessWidget {
|
|
||||||
const CupertinoContextMenuDemo({super.key});
|
|
||||||
|
|
||||||
// Or just do this inline in the builder below?
|
|
||||||
static Animation<Decoration> _boxDecorationAnimation(
|
|
||||||
Animation<double> animation) {
|
|
||||||
return _tween.animate(
|
|
||||||
CurvedAnimation(
|
|
||||||
parent: animation,
|
|
||||||
curve: Interval(
|
|
||||||
0.0,
|
|
||||||
CupertinoContextMenu.animationOpensAt,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return CupertinoPageScaffold(
|
|
||||||
navigationBar: const CupertinoNavigationBar(
|
|
||||||
middle: Text('CupertinoContextMenu 案例'),
|
|
||||||
),
|
|
||||||
child: Center(
|
|
||||||
child: SizedBox(
|
|
||||||
width: 100,
|
|
||||||
height: 100,
|
|
||||||
child: CupertinoContextMenu.builder(
|
|
||||||
actions: <Widget>[
|
|
||||||
CupertinoContextMenuAction(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
isDefaultAction: true,
|
|
||||||
trailingIcon: CupertinoIcons.doc_on_clipboard_fill,
|
|
||||||
child: const Text('Copy'),
|
|
||||||
),
|
|
||||||
CupertinoContextMenuAction(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
trailingIcon: CupertinoIcons.share,
|
|
||||||
child: const Text('Share'),
|
|
||||||
),
|
|
||||||
CupertinoContextMenuAction(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
trailingIcon: CupertinoIcons.heart,
|
|
||||||
child: const Text('Favorite'),
|
|
||||||
),
|
|
||||||
CupertinoContextMenuAction(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
isDestructiveAction: true,
|
|
||||||
trailingIcon: CupertinoIcons.delete,
|
|
||||||
child: const Text('Delete'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
builder: (BuildContext context, Animation<double> animation) {
|
|
||||||
final Animation<Decoration> boxDecorationAnimation =
|
|
||||||
_boxDecorationAnimation(animation);
|
|
||||||
|
|
||||||
return Container(
|
|
||||||
decoration:
|
|
||||||
animation.value < CupertinoContextMenu.animationOpensAt
|
|
||||||
? boxDecorationAnimation.value
|
|
||||||
: null,
|
|
||||||
child: Container(
|
|
||||||
padding: EdgeInsets.all(20),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: CupertinoColors.systemPurple,
|
|
||||||
borderRadius: BorderRadius.circular(20.0),
|
|
||||||
),
|
|
||||||
child: const FlutterLogo(size: 250.0),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
/// Flutter code sample for [DropdownButton.selectedItemBuilder].
|
|
||||||
|
|
||||||
const Map<String, Color> kColors = <String, Color>{
|
|
||||||
'红色': Colors.red,
|
|
||||||
'黄色': Colors.yellowAccent,
|
|
||||||
'蓝色': Colors.blue,
|
|
||||||
'绿色': Colors.greenAccent,
|
|
||||||
'橙色': Colors.orange,
|
|
||||||
'紫色': Colors.purple,
|
|
||||||
};
|
|
||||||
|
|
||||||
class DropdownButtonColor extends StatefulWidget {
|
|
||||||
const DropdownButtonColor({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<DropdownButtonColor> createState() => _DropdownButtonColorState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _DropdownButtonColorState extends State<DropdownButtonColor> {
|
|
||||||
String selectedItem = kColors.keys.first;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: <Widget>[
|
|
||||||
Text('选择颜色:', style: Theme.of(context).textTheme.bodyLarge),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
||||||
child: DropdownButton<String>(
|
|
||||||
value: selectedItem,
|
|
||||||
onChanged: (String? value) {
|
|
||||||
setState(() => selectedItem = value!);
|
|
||||||
},
|
|
||||||
selectedItemBuilder: _buildSelectItem,
|
|
||||||
items: _buildItems(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<DropdownMenuItem<String>> _buildItems(){
|
|
||||||
return kColors.keys.map<DropdownMenuItem<String>>((String key) {
|
|
||||||
return DropdownMenuItem<String>(
|
|
||||||
value: key,
|
|
||||||
child: Wrap(
|
|
||||||
spacing: 4,
|
|
||||||
crossAxisAlignment: WrapCrossAlignment.center,
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
width: 14,
|
|
||||||
height: 14,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: kColors[key],
|
|
||||||
borderRadius: BorderRadius.circular(2)),
|
|
||||||
),
|
|
||||||
Text(key),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Widget> _buildSelectItem(BuildContext context) {
|
|
||||||
return kColors.values.map<Widget>((Color color) {
|
|
||||||
return Align(
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: color,
|
|
||||||
borderRadius: BorderRadius.circular(2)),
|
|
||||||
constraints: const BoxConstraints(minWidth: 24,maxHeight: 24),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}).toList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
137
lib/10/main.dart
137
lib/10/main.dart
@@ -1,137 +0,0 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
||||||
|
|
||||||
import 'app_info.dart';
|
|
||||||
import 'cupertino_context_menu_demo.dart';
|
|
||||||
import 'dropdown_button_color.dart';
|
|
||||||
import 'more_pop_icon.dart';
|
|
||||||
import 'search_anchor_demo.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const MyApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
title: 'Flutter Demo',
|
|
||||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
|
||||||
supportedLocales: const [
|
|
||||||
Locale('zh', 'CN'),
|
|
||||||
],
|
|
||||||
locale: const Locale('zh', 'CN'),
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
theme: ThemeData(
|
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
|
||||||
useMaterial3: true,
|
|
||||||
),
|
|
||||||
home: const HomePage(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<HomePage> createState() => _HomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _HomePageState extends State<HomePage> {
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text("弹出层测试"),
|
|
||||||
actions: [
|
|
||||||
MorePopIcon(onTapItem: _onTapItem,)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: showConformDialog,
|
|
||||||
child: Text('关于应用'),
|
|
||||||
),
|
|
||||||
DropdownButtonColor(),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: _showModalBottomSheet,
|
|
||||||
child: Text('showModalBottomSheet'),
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: _showCupertinoModalPopup,
|
|
||||||
child: Text('showCupertinoModalPopup'),
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: _toSearchAnchor,
|
|
||||||
child: Text('SearchAnchor 案例'),
|
|
||||||
), ElevatedButton(
|
|
||||||
onPressed: _toCupertinoContextMenu,
|
|
||||||
child: Text('CupertinoContextMenu 案例'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void showConformDialog(){
|
|
||||||
showDialog(context: context, builder: _buildAbout);
|
|
||||||
// showCupertinoModalPopup(context: context, builder: builder)
|
|
||||||
// showCupertinoDialog(context: context, builder: _buildAbout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _showModalBottomSheet(){
|
|
||||||
showModalBottomSheet(
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8)
|
|
||||||
),
|
|
||||||
context: context, builder: (_)=>AppInfo());
|
|
||||||
}
|
|
||||||
|
|
||||||
void _showCupertinoModalPopup(){
|
|
||||||
showCupertinoModalPopup(
|
|
||||||
context: context, builder: (_)=>Material(child: const AppInfo()));
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildAbout(BuildContext context){
|
|
||||||
const String msg = 'FlutterUnit 是一个辅助开发者,了解 Flutter 组件和编程技术的开源项目。';
|
|
||||||
return const AboutDialog(
|
|
||||||
applicationName: "FlutterUnit",
|
|
||||||
applicationVersion: "v2.9.3",
|
|
||||||
applicationIcon: FlutterLogo(),
|
|
||||||
children: [
|
|
||||||
Text(msg,style: TextStyle(color: Colors.grey),)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onTapItem(MenuAction value) {
|
|
||||||
print(value.label);
|
|
||||||
switch(value){
|
|
||||||
case MenuAction.setting:
|
|
||||||
break;
|
|
||||||
case MenuAction.about:
|
|
||||||
showConformDialog();
|
|
||||||
break;
|
|
||||||
case MenuAction.help:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _toSearchAnchor() {
|
|
||||||
Navigator.of(context).push(MaterialPageRoute(builder: (_)=>SearchAnchorDemo()));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void _toCupertinoContextMenu() {
|
|
||||||
Navigator.of(context).push(MaterialPageRoute(builder: (_)=>CupertinoContextMenuDemo()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
enum MenuAction implements Comparable<MenuAction> {
|
|
||||||
setting(label: '应用设置', iconData: Icons.settings),
|
|
||||||
about(label: '关于应用', iconData: Icons.info),
|
|
||||||
help(label: '帮助中心', iconData: Icons.help);
|
|
||||||
|
|
||||||
final String label;
|
|
||||||
final IconData iconData;
|
|
||||||
|
|
||||||
const MenuAction({
|
|
||||||
required this.label,
|
|
||||||
required this.iconData,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
int compareTo(MenuAction other) => label.compareTo(other.label);
|
|
||||||
|
|
||||||
bool operator >(MenuAction other) {
|
|
||||||
return compareTo(other) > 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MorePopIcon extends StatelessWidget {
|
|
||||||
final ValueChanged<MenuAction> onTapItem;
|
|
||||||
const MorePopIcon({super.key, required this.onTapItem});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return PopupMenuButton<MenuAction>(
|
|
||||||
itemBuilder: _buildItem,
|
|
||||||
onSelected: onTapItem,
|
|
||||||
icon: const Icon(Icons.more_vert_outlined),
|
|
||||||
position: PopupMenuPosition.under,
|
|
||||||
shape: const RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<PopupMenuEntry<MenuAction>> _buildItem(BuildContext context) {
|
|
||||||
return MenuAction.values
|
|
||||||
.map((MenuAction action) => PopupMenuItem<MenuAction>(
|
|
||||||
height: 35,
|
|
||||||
value: action,
|
|
||||||
child: Center(
|
|
||||||
child: Wrap(
|
|
||||||
crossAxisAlignment: WrapCrossAlignment.center,
|
|
||||||
spacing: 6,
|
|
||||||
children: [
|
|
||||||
Text(action.label),
|
|
||||||
Icon(action.iconData, size: 18),
|
|
||||||
],
|
|
||||||
)),
|
|
||||||
))
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,162 +0,0 @@
|
|||||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class SearchAnchorDemo extends StatefulWidget {
|
|
||||||
const SearchAnchorDemo({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<SearchAnchorDemo> createState() => _SearchAnchorDemoState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _SearchAnchorDemoState extends State<SearchAnchorDemo> {
|
|
||||||
Color? selectedColorSeed;
|
|
||||||
List<ColorLabel> searchHistory = <ColorLabel>[];
|
|
||||||
|
|
||||||
Iterable<Widget> getHistoryList(SearchController controller) {
|
|
||||||
return searchHistory.map(
|
|
||||||
(ColorLabel color) => ListTile(
|
|
||||||
leading: const Icon(Icons.history),
|
|
||||||
title: Text(color.label),
|
|
||||||
trailing: IconButton(
|
|
||||||
icon: const Icon(Icons.call_missed),
|
|
||||||
onPressed: () {
|
|
||||||
controller.text = color.label;
|
|
||||||
controller.selection = TextSelection.collapsed(offset: controller.text.length);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterable<Widget> getSuggestions(SearchController controller) {
|
|
||||||
final String input = controller.value.text;
|
|
||||||
return ColorLabel.values.where((ColorLabel color) => color.label.contains(input)).map(
|
|
||||||
(ColorLabel filteredColor) => ListTile(
|
|
||||||
leading: CircleAvatar(backgroundColor: filteredColor.color),
|
|
||||||
title: Text(filteredColor.label),
|
|
||||||
trailing: IconButton(
|
|
||||||
icon: const Icon(Icons.call_missed),
|
|
||||||
onPressed: () {
|
|
||||||
controller.text = filteredColor.label;
|
|
||||||
controller.selection = TextSelection.collapsed(offset: controller.text.length);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
onTap: () {
|
|
||||||
controller.closeView(filteredColor.label);
|
|
||||||
handleSelection(filteredColor);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void handleSelection(ColorLabel selectedColor) {
|
|
||||||
setState(() {
|
|
||||||
selectedColorSeed = selectedColor.color;
|
|
||||||
if (searchHistory.length >= 5) {
|
|
||||||
searchHistory.removeLast();
|
|
||||||
}
|
|
||||||
searchHistory.insert(0, selectedColor);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String,Color> colorMaps(ColorScheme colors) => {
|
|
||||||
'primary':colors.primary ,
|
|
||||||
'secondary':colors.secondary ,
|
|
||||||
'inverseSurface':colors.inverseSurface ,
|
|
||||||
'background':colors.background ,
|
|
||||||
|
|
||||||
|
|
||||||
'onPrimaryContainer':colors.onPrimaryContainer ,
|
|
||||||
'onErrorContainer':colors.onErrorContainer ,
|
|
||||||
'onBackground':colors.onBackground ,
|
|
||||||
'onTertiaryContainer':colors.onTertiaryContainer ,
|
|
||||||
|
|
||||||
|
|
||||||
'error':colors.error ,
|
|
||||||
'inversePrimary':colors.inversePrimary ,
|
|
||||||
'primaryContainer':colors.primaryContainer ,
|
|
||||||
'errorContainer':colors.errorContainer ,
|
|
||||||
|
|
||||||
'onPrimary':colors.onPrimary ,
|
|
||||||
'onSecondary':colors.onSecondary ,
|
|
||||||
'onError':colors.onError ,
|
|
||||||
'onTertiary':colors.onTertiary ,
|
|
||||||
'onSurfaceVariant':colors.onSurfaceVariant ,
|
|
||||||
'shadow':colors.shadow ,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final ThemeData themeData = ThemeData(useMaterial3: true, colorSchemeSeed: selectedColorSeed);
|
|
||||||
final ColorScheme colors = themeData.colorScheme;
|
|
||||||
Map<String,Color> data = colorMaps(colors);
|
|
||||||
SizedBox cardSize = const SizedBox(
|
|
||||||
width: 80,
|
|
||||||
height: 30,
|
|
||||||
child: Text(''),
|
|
||||||
);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(title: const Text('搜索颜色')),
|
|
||||||
body: Align(
|
|
||||||
alignment: Alignment.topCenter,
|
|
||||||
child: Column(
|
|
||||||
children: <Widget>[
|
|
||||||
SearchAnchor.bar(
|
|
||||||
barHintText: '输入颜色',
|
|
||||||
suggestionsBuilder: (BuildContext context, SearchController controller) {
|
|
||||||
if (controller.text.isEmpty) {
|
|
||||||
if (searchHistory.isNotEmpty) {
|
|
||||||
return getHistoryList(controller);
|
|
||||||
}
|
|
||||||
return <Widget>[Center(child: Text('暂无历史记录.', style: TextStyle(color: colors.outline)))];
|
|
||||||
}
|
|
||||||
return getSuggestions(controller);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
cardSize,
|
|
||||||
Wrap(
|
|
||||||
children: data.keys.map((key) => Card(color: data[key], child: SizedBox(
|
|
||||||
width: 80,
|
|
||||||
height: 30,
|
|
||||||
child: Center(child: Text(key,style: TextStyle(fontSize: 8,color: Colors.white,shadows: [
|
|
||||||
BoxShadow(color: Colors.black,offset: Offset(.1,.1),blurRadius: 2)
|
|
||||||
]),)),
|
|
||||||
))).toList(),
|
|
||||||
),
|
|
||||||
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
enum ColorLabel {
|
|
||||||
red('red', Colors.red),
|
|
||||||
orange('orange', Colors.orange),
|
|
||||||
yellow('yellow', Colors.yellow),
|
|
||||||
green('green', Colors.green),
|
|
||||||
blue('blue', Colors.blue),
|
|
||||||
indigo('indigo', Colors.indigo),
|
|
||||||
violet('violet', Color(0xFF8F00FF)),
|
|
||||||
purple('purple', Colors.purple),
|
|
||||||
pink('pink', Colors.pink),
|
|
||||||
silver('silver', Color(0xFF808080)),
|
|
||||||
gold('gold', Color(0xFFFFD700)),
|
|
||||||
beige('beige', Color(0xFFF5F5DC)),
|
|
||||||
brown('brown', Colors.brown),
|
|
||||||
grey('grey', Colors.grey),
|
|
||||||
black('black', Colors.black),
|
|
||||||
white('white', Colors.white);
|
|
||||||
|
|
||||||
const ColorLabel(this.label, this.color);
|
|
||||||
final String label;
|
|
||||||
final Color color;
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
app_info.dart: 弹出对话框界面
|
|
||||||
cupertino_context_menu_demo.dart: 弹出 CupertinoContextMenu
|
|
||||||
dropdown_button_color.dart: 弹出 DropdownButton
|
|
||||||
more_pop_icon.dart: 弹出 PopupMenuButton
|
|
||||||
search_anchor_demo.dart: 弹出 SearchAnchor
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class ColorDetailPage extends StatelessWidget {
|
|
||||||
final Color color;
|
|
||||||
const ColorDetailPage({super.key, required this.color});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: color,
|
|
||||||
appBar: AppBar(
|
|
||||||
centerTitle: true,
|
|
||||||
iconTheme: IconThemeData(color: Colors.white),
|
|
||||||
titleTextStyle: TextStyle(color: Colors.white,fontSize: 16,fontWeight: FontWeight.bold),
|
|
||||||
backgroundColor: color,
|
|
||||||
title: Text('颜色详情页'),
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: Text( '#${color.value.toRadixString(16)}',style: TextStyle(color: Colors.white,fontSize: 26,fontWeight: FontWeight.bold),),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
||||||
import 'package:iroute/11/transition.dart';
|
|
||||||
|
|
||||||
import 'color_page.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const MyApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
title: 'Flutter Demo',
|
|
||||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
|
||||||
supportedLocales: const [
|
|
||||||
Locale('zh', 'CN'),
|
|
||||||
],
|
|
||||||
locale: const Locale('zh', 'CN'),
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
theme: ThemeData(
|
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
|
||||||
useMaterial3: true,
|
|
||||||
),
|
|
||||||
home: const HomePage(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<HomePage> createState() => _HomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _HomePageState extends State<HomePage> {
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text("Cose 酷色"),
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: _toColorHome,
|
|
||||||
child: Text('打开颜色界面'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _toColorHome() {
|
|
||||||
Route route = PageRouteBuilder<void>(
|
|
||||||
barrierColor: Colors.white,
|
|
||||||
pageBuilder: (_, __, ___) => const ColorPage(),
|
|
||||||
transitionsBuilder: kSlideBottomToTopWithSecondary,
|
|
||||||
);
|
|
||||||
Navigator.push(context, route);
|
|
||||||
// Navigator.pushReplacement(context, route);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
RouteTransitionsBuilder kSlideBottomToTopWithSecondary = (
|
|
||||||
BuildContext context,
|
|
||||||
Animation<double> animation,
|
|
||||||
Animation<double> secondaryAnimation,
|
|
||||||
Widget child,
|
|
||||||
) {
|
|
||||||
return SlideTransition(
|
|
||||||
position: Tween<Offset>(
|
|
||||||
begin: const Offset(0.0, 1.0),
|
|
||||||
end: Offset.zero,
|
|
||||||
).animate(animation),
|
|
||||||
child: SlideTransition(
|
|
||||||
position: Tween<Offset>(
|
|
||||||
begin: Offset.zero,
|
|
||||||
end: const Offset(0.0, 1.0),
|
|
||||||
).animate(secondaryAnimation),
|
|
||||||
child: child,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
路由第二动画控制器效果演示
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'pages/app/app.dart';
|
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const App());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import '../page_a.dart';
|
|
||||||
import '../page_b.dart';
|
|
||||||
import '../page_c.dart';
|
|
||||||
import '../home_page.dart';
|
|
||||||
|
|
||||||
ValueNotifier<List<String>> router = ValueNotifier(['/']);
|
|
||||||
|
|
||||||
class AppNavigation extends StatefulWidget {
|
|
||||||
const AppNavigation({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<AppNavigation> createState() => _AppNavigationState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _AppNavigationState extends State<AppNavigation> {
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
router.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return ValueListenableBuilder(
|
|
||||||
valueListenable: router,
|
|
||||||
builder: (_, List<String> value, __) => buildNavigatorByConfig(value),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final Map<String, Page> _pageMap = const {
|
|
||||||
'/': MaterialPage(child: HomePage()),
|
|
||||||
'a': MaterialPage(child: PageA()),
|
|
||||||
'b': MaterialPage(child: PageB()),
|
|
||||||
'c': MaterialPage(child: PageC()),
|
|
||||||
};
|
|
||||||
|
|
||||||
Widget buildNavigatorByConfig(List<String> value) {
|
|
||||||
return Navigator(
|
|
||||||
onPopPage: _onPopPage,
|
|
||||||
pages: router.value.map((e) => _pageMap[e]!).toList(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _onPopPage(Route route, result) {
|
|
||||||
return route.didPop(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'app_navigation.dart';
|
|
||||||
|
|
||||||
class AppToolBar extends StatefulWidget implements PreferredSizeWidget{
|
|
||||||
const AppToolBar({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<AppToolBar> createState() => _AppToolBarState();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
class _AppToolBarState extends State<AppToolBar> {
|
|
||||||
|
|
||||||
TextEditingController _ctrl = TextEditingController();
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_changRoute();
|
|
||||||
router.addListener(_changRoute);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
router.removeListener(_changRoute);
|
|
||||||
_ctrl.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _changRoute() {
|
|
||||||
_ctrl.text=router.value.join(',');
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
|
|
||||||
return AppBar(
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
elevation: 0,
|
|
||||||
title : TextField(
|
|
||||||
controller: _ctrl,
|
|
||||||
onSubmitted: _onSubmitted,
|
|
||||||
decoration: InputDecoration( //装饰
|
|
||||||
filled: true, //填充
|
|
||||||
fillColor: Color(0xffF3F6F9), //填充颜色
|
|
||||||
constraints: BoxConstraints(maxHeight: 34), //约束信息
|
|
||||||
contentPadding: EdgeInsets.only(top: -14,left: 10),
|
|
||||||
border: UnderlineInputBorder( //边线信息
|
|
||||||
borderSide: BorderSide.none,
|
|
||||||
borderRadius: BorderRadius.all(Radius.circular(6)),
|
|
||||||
),
|
|
||||||
hintText: "请输入路由", //提示字
|
|
||||||
hintStyle: TextStyle(fontSize: 14) //提示字样式
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onSubmitted(String value) {
|
|
||||||
router.value = value.split(',');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'app/app_navigation.dart';
|
|
||||||
|
|
||||||
class HomePage extends StatelessWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCFFCC);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('主页起点'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(child: ElevatedButton(
|
|
||||||
onPressed: () => toPageA(context),
|
|
||||||
child: const Text('Push A'),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageA(BuildContext context) {
|
|
||||||
router.value = ['/', 'a'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'app/app_navigation.dart';
|
|
||||||
|
|
||||||
class PageA extends StatelessWidget {
|
|
||||||
const PageA({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCFFFF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('A 界面'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
leading: BackButton(onPressed: _pop),
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: () => toPageB(context),
|
|
||||||
child: const Text('Push B'),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageB(BuildContext context) {
|
|
||||||
router.value = ['/', 'a', 'b'];
|
|
||||||
}
|
|
||||||
|
|
||||||
void _pop() {
|
|
||||||
router.value = List.of(router.value)..removeLast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'app/app_navigation.dart';
|
|
||||||
|
|
||||||
|
|
||||||
class PageB extends StatelessWidget {
|
|
||||||
const PageB({super.key});
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCE5FF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('B 界面'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
leading: BackButton(
|
|
||||||
onPressed: _pop,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: () => toPageC(context),
|
|
||||||
child: const Text('Push C'),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void toPageC(BuildContext context){
|
|
||||||
router.value = ['/','a','b','c'];
|
|
||||||
}
|
|
||||||
|
|
||||||
void _pop() {
|
|
||||||
router.value = List.of(router.value)..removeLast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'app/app_navigation.dart';
|
|
||||||
|
|
||||||
class PageC extends StatelessWidget {
|
|
||||||
const PageC({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffFFE6CC);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('C 界面'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
leading: BackButton(onPressed: _pop),
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: Text('到达终点'),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
void _pop() {
|
|
||||||
router.value = List.of(router.value)..removeLast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
01: Navigator#page 的使用测试
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'pages/app/app.dart';
|
|
||||||
import 'pages/app/app_router_delegate.dart';
|
|
||||||
|
|
||||||
|
|
||||||
AppRouterDelegate router = AppRouterDelegate();
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const App());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
import 'dart:ffi';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import '../page_a.dart';
|
|
||||||
import '../page_b.dart';
|
|
||||||
import '../page_c.dart';
|
|
||||||
import '../home_page.dart';
|
|
||||||
|
|
||||||
class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier{
|
|
||||||
|
|
||||||
List<String> _value = ['/'];
|
|
||||||
|
|
||||||
List<String> get value => _value;
|
|
||||||
|
|
||||||
set value(List<String> value){
|
|
||||||
_value = value;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Navigator(
|
|
||||||
onPopPage: _onPopPage,
|
|
||||||
pages: _value.map((e) => _pageMap[e]!).toList(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final Map<String, Page> _pageMap = const {
|
|
||||||
'/': MaterialPage(child: HomePage()),
|
|
||||||
'a': MaterialPage(child: PageA()),
|
|
||||||
'b': MaterialPage(child: PageB()),
|
|
||||||
'c': MaterialPage(child: PageC()),
|
|
||||||
};
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> popRoute() async{
|
|
||||||
print('=======popRoute=========');
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _onPopPage(Route route, result) {
|
|
||||||
return route.didPop(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> setNewRoutePath(configuration) async{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// class AppRouterDelegate extends RouterDelegate<String> with ChangeNotifier, PopNavigatorRouterDelegateMixin {
|
|
||||||
//
|
|
||||||
// List<String> _value = ['/'];
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// List<String> get value => _value;
|
|
||||||
//
|
|
||||||
// set value(List<String> value){
|
|
||||||
// _value = value;
|
|
||||||
// notifyListeners();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @override
|
|
||||||
// Widget build(BuildContext context) {
|
|
||||||
// return Navigator(
|
|
||||||
// onPopPage: _onPopPage,
|
|
||||||
// pages: _value.map((e) => _pageMap[e]!).toList(),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// final Map<String, Page> _pageMap = const {
|
|
||||||
// '/': MaterialPage(child: HomePage()),
|
|
||||||
// 'a': MaterialPage(child: PageA()),
|
|
||||||
// 'b': MaterialPage(child: PageB()),
|
|
||||||
// 'c': MaterialPage(child: PageC()),
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// bool _onPopPage(Route route, result) {
|
|
||||||
// _value = List.of(_value)..removeLast();
|
|
||||||
// notifyListeners();
|
|
||||||
// return route.didPop(result);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @override
|
|
||||||
// GlobalKey<NavigatorState>? navigatorKey = GlobalKey<NavigatorState>();
|
|
||||||
//
|
|
||||||
// @override
|
|
||||||
// Future<void> setNewRoutePath(String configuration) async{
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import '../../main.dart';
|
|
||||||
|
|
||||||
class AppToolBar extends StatefulWidget implements PreferredSizeWidget{
|
|
||||||
const AppToolBar({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<AppToolBar> createState() => _AppToolBarState();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
class _AppToolBarState extends State<AppToolBar> {
|
|
||||||
|
|
||||||
TextEditingController _ctrl = TextEditingController();
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_changRoute();
|
|
||||||
router.addListener(_changRoute);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
router.removeListener(_changRoute);
|
|
||||||
_ctrl.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _changRoute() {
|
|
||||||
_ctrl.text= router.value.join(',');
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
|
|
||||||
return AppBar(
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
elevation: 0,
|
|
||||||
title : TextField(
|
|
||||||
controller: _ctrl,
|
|
||||||
onSubmitted: _onSubmitted,
|
|
||||||
decoration: InputDecoration( //装饰
|
|
||||||
filled: true, //填充
|
|
||||||
fillColor: Color(0xffF3F6F9), //填充颜色
|
|
||||||
constraints: BoxConstraints(maxHeight: 34), //约束信息
|
|
||||||
contentPadding: EdgeInsets.only(top: -14,left: 10),
|
|
||||||
border: UnderlineInputBorder( //边线信息
|
|
||||||
borderSide: BorderSide.none,
|
|
||||||
borderRadius: BorderRadius.all(Radius.circular(6)),
|
|
||||||
),
|
|
||||||
hintText: "请输入路由", //提示字
|
|
||||||
hintStyle: TextStyle(fontSize: 14) //提示字样式
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onSubmitted(String value) {
|
|
||||||
router.value = value.split(',');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import '../main.dart';
|
|
||||||
|
|
||||||
|
|
||||||
class HomePage extends StatelessWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCFFCC);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('主页起点'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(child: ElevatedButton(
|
|
||||||
onPressed: () => toPageA(context),
|
|
||||||
child: const Text('Push A'),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageA(BuildContext context) {
|
|
||||||
router.value = ['/', 'a'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import '../main.dart';
|
|
||||||
|
|
||||||
class PageA extends StatelessWidget {
|
|
||||||
const PageA({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCFFFF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('A 界面'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
leading: BackButton(onPressed: _pop),
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: () => toPageB(context),
|
|
||||||
child: const Text('Push B'),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageB(BuildContext context) {
|
|
||||||
router.value = ['/', 'a', 'b'];
|
|
||||||
}
|
|
||||||
|
|
||||||
void _pop() {
|
|
||||||
router.value = List.of(router.value)..removeLast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import '../main.dart';
|
|
||||||
|
|
||||||
class PageB extends StatelessWidget {
|
|
||||||
const PageB({super.key});
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCE5FF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('B 界面'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
leading: BackButton(onPressed: _pop),
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: () => toPageC(context),
|
|
||||||
child: const Text('Push C'),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageC(BuildContext context){
|
|
||||||
router.value = ['/','a','b','c'];
|
|
||||||
}
|
|
||||||
|
|
||||||
void _pop() {
|
|
||||||
router.value = List.of(router.value)..removeLast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import '../main.dart';
|
|
||||||
|
|
||||||
class PageC extends StatelessWidget {
|
|
||||||
const PageC({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffFFE6CC);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('C 界面'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
leading: BackButton(onPressed: _pop),
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: Text('到达终点'),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
void _pop() {
|
|
||||||
router.value = List.of(router.value)..removeLast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'pages/app/app.dart';
|
|
||||||
import 'pages/app/app_router_delegate.dart';
|
|
||||||
|
|
||||||
|
|
||||||
AppRouterDelegate router = AppRouterDelegate();
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const App());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
import 'dart:ffi';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import '../page_a.dart';
|
|
||||||
import '../page_b.dart';
|
|
||||||
import '../page_c.dart';
|
|
||||||
import '../home_page.dart';
|
|
||||||
|
|
||||||
class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier{
|
|
||||||
|
|
||||||
List<String> _value = ['/'];
|
|
||||||
|
|
||||||
List<String> get value => _value;
|
|
||||||
|
|
||||||
set value(List<String> value){
|
|
||||||
_value = value;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Navigator(
|
|
||||||
onPopPage: _onPopPage,
|
|
||||||
pages: _value.map((e) => _pageMap[e]!).toList(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final Map<String, Page> _pageMap = const {
|
|
||||||
'/': MaterialPage(child: HomePage()),
|
|
||||||
'a': MaterialPage(child: PageA()),
|
|
||||||
'b': MaterialPage(child: PageB()),
|
|
||||||
'c': MaterialPage(child: PageC()),
|
|
||||||
};
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> popRoute() async{
|
|
||||||
print('=======popRoute=========');
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _onPopPage(Route route, result) {
|
|
||||||
value = List.of(_value)..removeLast();
|
|
||||||
return route.didPop(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> setNewRoutePath(configuration) async{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// class AppRouterDelegate extends RouterDelegate<String> with ChangeNotifier, PopNavigatorRouterDelegateMixin {
|
|
||||||
//
|
|
||||||
// List<String> _value = ['/'];
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// List<String> get value => _value;
|
|
||||||
//
|
|
||||||
// set value(List<String> value){
|
|
||||||
// _value = value;
|
|
||||||
// notifyListeners();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @override
|
|
||||||
// Widget build(BuildContext context) {
|
|
||||||
// return Navigator(
|
|
||||||
// onPopPage: _onPopPage,
|
|
||||||
// pages: _value.map((e) => _pageMap[e]!).toList(),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// final Map<String, Page> _pageMap = const {
|
|
||||||
// '/': MaterialPage(child: HomePage()),
|
|
||||||
// 'a': MaterialPage(child: PageA()),
|
|
||||||
// 'b': MaterialPage(child: PageB()),
|
|
||||||
// 'c': MaterialPage(child: PageC()),
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// bool _onPopPage(Route route, result) {
|
|
||||||
// _value = List.of(_value)..removeLast();
|
|
||||||
// notifyListeners();
|
|
||||||
// return route.didPop(result);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @override
|
|
||||||
// GlobalKey<NavigatorState>? navigatorKey = GlobalKey<NavigatorState>();
|
|
||||||
//
|
|
||||||
// @override
|
|
||||||
// Future<void> setNewRoutePath(String configuration) async{
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import '../../main.dart';
|
|
||||||
|
|
||||||
class AppToolBar extends StatefulWidget implements PreferredSizeWidget{
|
|
||||||
const AppToolBar({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<AppToolBar> createState() => _AppToolBarState();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
class _AppToolBarState extends State<AppToolBar> {
|
|
||||||
|
|
||||||
TextEditingController _ctrl = TextEditingController();
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_changRoute();
|
|
||||||
router.addListener(_changRoute);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
router.removeListener(_changRoute);
|
|
||||||
_ctrl.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _changRoute() {
|
|
||||||
_ctrl.text= router.value.join(',');
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
|
|
||||||
return AppBar(
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
elevation: 0,
|
|
||||||
title : TextField(
|
|
||||||
controller: _ctrl,
|
|
||||||
onSubmitted: _onSubmitted,
|
|
||||||
decoration: InputDecoration( //装饰
|
|
||||||
filled: true, //填充
|
|
||||||
fillColor: Color(0xffF3F6F9), //填充颜色
|
|
||||||
constraints: BoxConstraints(maxHeight: 34), //约束信息
|
|
||||||
contentPadding: EdgeInsets.only(top: -14,left: 10),
|
|
||||||
border: UnderlineInputBorder( //边线信息
|
|
||||||
borderSide: BorderSide.none,
|
|
||||||
borderRadius: BorderRadius.all(Radius.circular(6)),
|
|
||||||
),
|
|
||||||
hintText: "请输入路由", //提示字
|
|
||||||
hintStyle: TextStyle(fontSize: 14) //提示字样式
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onSubmitted(String value) {
|
|
||||||
router.value = value.split(',');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import '../main.dart';
|
|
||||||
|
|
||||||
|
|
||||||
class HomePage extends StatelessWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCFFCC);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('主页起点'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(child: ElevatedButton(
|
|
||||||
onPressed: () => toPageA(context),
|
|
||||||
child: const Text('Push A'),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageA(BuildContext context) {
|
|
||||||
router.value = ['/', 'a'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import '../main.dart';
|
|
||||||
|
|
||||||
class PageA extends StatelessWidget {
|
|
||||||
const PageA({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCFFFF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('A 界面'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: () => toPageB(context),
|
|
||||||
child: const Text('Push B'),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageB(BuildContext context) {
|
|
||||||
router.value = ['/', 'a', 'b'];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import '../main.dart';
|
|
||||||
|
|
||||||
class PageB extends StatelessWidget {
|
|
||||||
const PageB({super.key});
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffCCE5FF);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('B 界面'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: () => toPageC(context),
|
|
||||||
child: const Text('Push C'),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
void toPageC(BuildContext context){
|
|
||||||
router.value = ['/','a','b','c'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import '../main.dart';
|
|
||||||
|
|
||||||
class PageC extends StatelessWidget {
|
|
||||||
const PageC({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const Color bgColor = Color(0xffFFE6CC);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('C 界面'),
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: Text('到达终点'),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'app/unit_app.dart';
|
|
||||||
import 'app/navigation/app_router_delegate.dart';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const UnitApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
01: Router#RouterDelegate 基础使用
|
|
||||||
改造基于数据控制 A、B、C 三个界面跳转。
|
|
||||||
|
|
||||||
02: 导航 2.0 中返回操作介绍
|
|
||||||
|
|
||||||
03: 侧栏菜单导航 V1
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'app/unit_app.dart';
|
|
||||||
import 'app/navigation/app_router_delegate.dart';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(const UnitApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
01: 颜色添加页和详情页跳转
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export 'counter/counter_page.dart';
|
|
||||||
export 'guess/guess_page.dart';
|
|
||||||
export 'paper/paper.dart';
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
|
|
||||||
class GuessAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|
||||||
final VoidCallback onCheck;
|
|
||||||
final TextEditingController controller;
|
|
||||||
|
|
||||||
const GuessAppBar({
|
|
||||||
Key? key,
|
|
||||||
required this.onCheck,
|
|
||||||
required this.controller,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return AppBar(
|
|
||||||
leading: Icon(Icons.menu, color: Colors.black),
|
|
||||||
actions: [
|
|
||||||
IconButton(
|
|
||||||
splashRadius: 20,
|
|
||||||
onPressed: onCheck,
|
|
||||||
icon: Icon(
|
|
||||||
Icons.run_circle_outlined,
|
|
||||||
color: Colors.blue,
|
|
||||||
))
|
|
||||||
],
|
|
||||||
title: TextField(
|
|
||||||
controller: controller,
|
|
||||||
keyboardType: TextInputType.number,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
filled: true,
|
|
||||||
fillColor: Color(0xffF3F6F9),
|
|
||||||
constraints: BoxConstraints(maxHeight: 34), //约束信息
|
|
||||||
contentPadding: EdgeInsets.only(top: -14,left: 10),
|
|
||||||
border: UnderlineInputBorder(
|
|
||||||
borderSide: BorderSide.none,
|
|
||||||
borderRadius: BorderRadius.all(Radius.circular(6)),
|
|
||||||
),
|
|
||||||
hintText: "输入 0~99 数字",
|
|
||||||
hintStyle: TextStyle(fontSize: 14)),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
|
||||||
}
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'guess_app_bar.dart';
|
|
||||||
import 'result_notice.dart';
|
|
||||||
|
|
||||||
class GuessPage extends StatefulWidget {
|
|
||||||
const GuessPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<GuessPage> createState() => _GuessPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _GuessPageState extends State<GuessPage> with SingleTickerProviderStateMixin,AutomaticKeepAliveClientMixin{
|
|
||||||
|
|
||||||
late AnimationController controller;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
controller = AnimationController(
|
|
||||||
vsync: this,
|
|
||||||
duration: const Duration(milliseconds: 200),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int _value = 0;
|
|
||||||
|
|
||||||
final Random _random = Random();
|
|
||||||
bool _guessing = false;
|
|
||||||
bool? _isBig;
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_guessCtrl.dispose();
|
|
||||||
controller.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _generateRandomValue() {
|
|
||||||
setState(() {
|
|
||||||
_guessing = true;
|
|
||||||
_value = _random.nextInt(100);
|
|
||||||
print(_value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TextEditingController _guessCtrl = TextEditingController();
|
|
||||||
|
|
||||||
void _onCheck() {
|
|
||||||
print("=====Check:目标数值:$_value=====${_guessCtrl.text}============");
|
|
||||||
int? guessValue = int.tryParse(_guessCtrl.text);
|
|
||||||
// 游戏未开始,或者输入非整数,无视
|
|
||||||
if (!_guessing || guessValue == null) return;
|
|
||||||
controller.forward(from: 0);
|
|
||||||
//猜对了
|
|
||||||
if (guessValue == _value) {
|
|
||||||
setState(() {
|
|
||||||
_isBig = null;
|
|
||||||
_guessing = false;
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 猜错了
|
|
||||||
setState(() {
|
|
||||||
_isBig = guessValue > _value;
|
|
||||||
});
|
|
||||||
_guessCtrl.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: GuessAppBar(
|
|
||||||
controller: _guessCtrl,
|
|
||||||
onCheck: _onCheck,
|
|
||||||
),
|
|
||||||
body: Stack(
|
|
||||||
children: [
|
|
||||||
if(_isBig!=null)
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
if(_isBig!)
|
|
||||||
ResultNotice(color:Colors.redAccent,info:'大了',controller: controller,),
|
|
||||||
Spacer(),
|
|
||||||
if(!_isBig!)
|
|
||||||
ResultNotice(color:Colors.blueAccent,info:'小了',controller: controller,),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: <Widget>[
|
|
||||||
if (!_guessing)
|
|
||||||
const Text(
|
|
||||||
'点击生成随机数值',
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
_guessing ? '**' : '$_value',
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 68, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
floatingActionButton: FloatingActionButton(
|
|
||||||
onPressed: _guessing ? null : _generateRandomValue,
|
|
||||||
backgroundColor: _guessing ? Colors.grey : Colors.blue,
|
|
||||||
tooltip: 'Increment',
|
|
||||||
child: const Icon(Icons.generating_tokens_outlined),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
// TODO: implement wantKeepAlive
|
|
||||||
bool get wantKeepAlive => true;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class ResultNotice extends StatelessWidget {
|
|
||||||
final Color color;
|
|
||||||
final String info;
|
|
||||||
final AnimationController controller;
|
|
||||||
|
|
||||||
const ResultNotice({
|
|
||||||
Key? key,
|
|
||||||
required this.color,
|
|
||||||
required this.info,
|
|
||||||
required this.controller,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Expanded(
|
|
||||||
child: Container(
|
|
||||||
alignment: Alignment.center,
|
|
||||||
color: color,
|
|
||||||
child: AnimatedBuilder(
|
|
||||||
animation: controller,
|
|
||||||
builder: (_, child) => Text(
|
|
||||||
info,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 54 * (controller.value),
|
|
||||||
color: Colors.white,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class ColorSelector extends StatelessWidget {
|
|
||||||
final List<Color> supportColors;
|
|
||||||
final ValueChanged<int> onSelect;
|
|
||||||
final int activeIndex;
|
|
||||||
|
|
||||||
const ColorSelector({
|
|
||||||
Key? key,
|
|
||||||
required this.supportColors,
|
|
||||||
required this.activeIndex,
|
|
||||||
required this.onSelect,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8),
|
|
||||||
child: Wrap(
|
|
||||||
// crossAxisAlignment: CrossAxisAlignment.end,
|
|
||||||
children: List.generate(
|
|
||||||
supportColors.length,
|
|
||||||
_buildByIndex,
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildByIndex(int index) {
|
|
||||||
bool select = index == activeIndex;
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () => onSelect(index),
|
|
||||||
child: Container(
|
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 2),
|
|
||||||
padding: const EdgeInsets.all(2),
|
|
||||||
width: 24,
|
|
||||||
height: 24,
|
|
||||||
alignment: Alignment.center,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
// borderRadius: BorderRadius.circular(8),
|
|
||||||
border: select ? Border.all(color: Colors.blue) : null
|
|
||||||
),
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
color: supportColors[index],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
/// create by 张风捷特烈 on 2020-04-23
|
|
||||||
/// contact me by email 1981462002@qq.com
|
|
||||||
/// 说明:
|
|
||||||
|
|
||||||
class ConformDialog extends StatelessWidget {
|
|
||||||
final String title;
|
|
||||||
final String msg;
|
|
||||||
final String conformText;
|
|
||||||
final VoidCallback onConform;
|
|
||||||
|
|
||||||
ConformDialog({
|
|
||||||
Key? key,
|
|
||||||
required this.title,
|
|
||||||
required this.msg,
|
|
||||||
required this.onConform,
|
|
||||||
this.conformText = '删除',
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final ButtonStyle conformStyle = ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.redAccent,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
elevation: 0,
|
|
||||||
minimumSize: const Size(70, 35),
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
shape: const StadiumBorder(),
|
|
||||||
);
|
|
||||||
|
|
||||||
final ButtonStyle cancelStyle = OutlinedButton.styleFrom(
|
|
||||||
minimumSize: const Size(70, 35),
|
|
||||||
elevation: 0,
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
shape: const StadiumBorder(),
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Dialog(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(20.0),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: <Widget>[
|
|
||||||
_buildTitle(),
|
|
||||||
_buildMessage(),
|
|
||||||
_buildButtons(context),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildTitle()=>Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.warning_amber_rounded, color: Colors.orange),
|
|
||||||
const SizedBox(
|
|
||||||
width: 10,
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
title,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 16, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
Widget _buildMessage()=>Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
top: 15,
|
|
||||||
bottom: 15,
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
msg,
|
|
||||||
style: const TextStyle(fontSize: 14),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
Widget _buildButtons(BuildContext context) => Row(
|
|
||||||
children: [
|
|
||||||
const Spacer(),
|
|
||||||
OutlinedButton(
|
|
||||||
onPressed: Navigator.of(context).pop,
|
|
||||||
style: cancelStyle,
|
|
||||||
child: const Text(
|
|
||||||
'取消',
|
|
||||||
style: TextStyle(fontSize: 12, color: Colors.grey),
|
|
||||||
)),
|
|
||||||
const SizedBox(width: 10),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: onConform,
|
|
||||||
style: conformStyle,
|
|
||||||
child: Text(conformText),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class Line {
|
|
||||||
List<Offset> points;
|
|
||||||
Color color;
|
|
||||||
double strokeWidth;
|
|
||||||
|
|
||||||
Line({
|
|
||||||
required this.points,
|
|
||||||
this.color = Colors.black,
|
|
||||||
this.strokeWidth = 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,194 +0,0 @@
|
|||||||
import 'dart:math';
|
|
||||||
import 'dart:ui';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'color_selector.dart';
|
|
||||||
import 'conform_dialog.dart';
|
|
||||||
|
|
||||||
import 'model.dart';
|
|
||||||
import 'paper_app_bar.dart';
|
|
||||||
import 'stork_width_selector.dart';
|
|
||||||
|
|
||||||
class Paper extends StatefulWidget {
|
|
||||||
const Paper({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<Paper> createState() => _PaperState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _PaperState extends State<Paper> with AutomaticKeepAliveClientMixin {
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool get wantKeepAlive => true;
|
|
||||||
|
|
||||||
|
|
||||||
List<Line> _lines = []; // 线列表
|
|
||||||
|
|
||||||
int _activeColorIndex = 0; // 颜色激活索引
|
|
||||||
int _activeStorkWidthIndex = 0; // 线宽激活索引
|
|
||||||
|
|
||||||
// 支持的颜色
|
|
||||||
final List<Color> supportColors = [
|
|
||||||
Colors.black,
|
|
||||||
Colors.red,
|
|
||||||
Colors.orange,
|
|
||||||
Colors.yellow,
|
|
||||||
Colors.green,
|
|
||||||
Colors.blue,
|
|
||||||
Colors.indigo,
|
|
||||||
Colors.purple,
|
|
||||||
Colors.pink,
|
|
||||||
Colors.grey,
|
|
||||||
Colors.redAccent,
|
|
||||||
Colors.orangeAccent,
|
|
||||||
Colors.yellowAccent,
|
|
||||||
Colors.greenAccent,
|
|
||||||
Colors.blueAccent,
|
|
||||||
Colors.indigoAccent,
|
|
||||||
Colors.purpleAccent,
|
|
||||||
Colors.pinkAccent,
|
|
||||||
];
|
|
||||||
|
|
||||||
// 支持的线粗
|
|
||||||
final List<double> supportStorkWidths = [1, 2, 4, 6, 8, 10];
|
|
||||||
|
|
||||||
List<Line> _historyLines = [];
|
|
||||||
|
|
||||||
void _back() {
|
|
||||||
Line line = _lines.removeLast();
|
|
||||||
_historyLines.add(line);
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
|
|
||||||
void _revocation() {
|
|
||||||
Line line = _historyLines.removeLast();
|
|
||||||
_lines.add(line);
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: PaperAppBar(
|
|
||||||
onClear: _showClearDialog,
|
|
||||||
onBack: _lines.isEmpty ? null : _back,
|
|
||||||
onRevocation: _historyLines.isEmpty ? null : _revocation,
|
|
||||||
),
|
|
||||||
body: Stack(
|
|
||||||
children: [
|
|
||||||
GestureDetector(
|
|
||||||
onPanStart: _onPanStart,
|
|
||||||
onPanUpdate: _onPanUpdate,
|
|
||||||
child: CustomPaint(
|
|
||||||
painter: PaperPainter(lines: _lines),
|
|
||||||
child: ConstrainedBox(constraints: const BoxConstraints.expand()),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
bottom: 0,
|
|
||||||
width: MediaQuery.of(context).size.width,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: ColorSelector(
|
|
||||||
supportColors: supportColors,
|
|
||||||
activeIndex: _activeColorIndex,
|
|
||||||
onSelect: _onSelectColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
StorkWidthSelector(
|
|
||||||
supportStorkWidths: supportStorkWidths,
|
|
||||||
color: supportColors[_activeColorIndex],
|
|
||||||
activeIndex: _activeStorkWidthIndex,
|
|
||||||
onSelect: _onSelectStorkWidth,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _showClearDialog() {
|
|
||||||
String msg = "您的当前操作会清空绘制内容,是否确定删除!";
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (ctx) => ConformDialog(
|
|
||||||
title: '清空提示',
|
|
||||||
conformText: '确定',
|
|
||||||
msg: msg,
|
|
||||||
onConform: _clear,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
void _clear() {
|
|
||||||
_lines.clear();
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onPanStart(DragStartDetails details) {
|
|
||||||
_lines.add(Line(
|
|
||||||
points: [details.localPosition],
|
|
||||||
strokeWidth: supportStorkWidths[_activeStorkWidthIndex],
|
|
||||||
color: supportColors[_activeColorIndex],
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onPanUpdate(DragUpdateDetails details) {
|
|
||||||
Offset point = details.localPosition;
|
|
||||||
double distance = (_lines.last.points.last - point).distance;
|
|
||||||
if (distance > 5) {
|
|
||||||
_lines.last.points.add(details.localPosition);
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onSelectStorkWidth(int index) {
|
|
||||||
if (index != _activeStorkWidthIndex) {
|
|
||||||
setState(() {
|
|
||||||
_activeStorkWidthIndex = index;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onSelectColor(int index) {
|
|
||||||
if (index != _activeColorIndex) {
|
|
||||||
setState(() {
|
|
||||||
_activeColorIndex = index;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class PaperPainter extends CustomPainter {
|
|
||||||
PaperPainter({
|
|
||||||
required this.lines,
|
|
||||||
}) {
|
|
||||||
_paint = Paint()
|
|
||||||
..style = PaintingStyle.stroke
|
|
||||||
..strokeCap = StrokeCap.round;
|
|
||||||
}
|
|
||||||
|
|
||||||
late Paint _paint;
|
|
||||||
final List<Line> lines;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void paint(Canvas canvas, Size size) {
|
|
||||||
for (int i = 0; i < lines.length; i++) {
|
|
||||||
drawLine(canvas, lines[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///根据点位绘制线
|
|
||||||
void drawLine(Canvas canvas, Line line) {
|
|
||||||
_paint.color = line.color;
|
|
||||||
_paint.strokeWidth = line.strokeWidth;
|
|
||||||
canvas.drawPoints(PointMode.polygon, line.points, _paint);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool shouldRepaint(CustomPainter oldDelegate) => true;
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
|
|
||||||
class PaperAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|
||||||
final VoidCallback onClear;
|
|
||||||
final VoidCallback? onBack;
|
|
||||||
final VoidCallback? onRevocation;
|
|
||||||
|
|
||||||
const PaperAppBar({
|
|
||||||
Key? key,
|
|
||||||
required this.onClear,
|
|
||||||
this.onBack,
|
|
||||||
this.onRevocation,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return AppBar(
|
|
||||||
leading: BackUpButtons(
|
|
||||||
onBack: onBack,
|
|
||||||
onRevocation: onRevocation,
|
|
||||||
),
|
|
||||||
leadingWidth: 100,
|
|
||||||
title: Text('画板绘制'),
|
|
||||||
actions: [
|
|
||||||
IconButton(
|
|
||||||
splashRadius: 20,
|
|
||||||
onPressed: onClear,
|
|
||||||
icon: Icon(CupertinoIcons.delete, size: 20))
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
class BackUpButtons extends StatelessWidget {
|
|
||||||
final VoidCallback? onBack;
|
|
||||||
final VoidCallback? onRevocation;
|
|
||||||
|
|
||||||
const BackUpButtons({
|
|
||||||
Key? key,
|
|
||||||
required this.onBack,
|
|
||||||
required this.onRevocation,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
const BoxConstraints cts = BoxConstraints(minHeight: 32, minWidth: 32);
|
|
||||||
Color backColor = onBack ==null?Colors.grey:Colors.black;
|
|
||||||
Color revocationColor = onRevocation ==null?Colors.grey:Colors.black;
|
|
||||||
return Center(
|
|
||||||
child: Wrap(
|
|
||||||
children: [
|
|
||||||
Transform.scale(
|
|
||||||
scaleX: -1,
|
|
||||||
child: IconButton(
|
|
||||||
splashRadius: 20,
|
|
||||||
constraints: cts,
|
|
||||||
onPressed: onBack,
|
|
||||||
icon: Icon(Icons.next_plan_outlined,color: backColor),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
splashRadius: 20,
|
|
||||||
onPressed: onRevocation,
|
|
||||||
constraints: cts,
|
|
||||||
icon: Icon(Icons.next_plan_outlined, color: revocationColor),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class StorkWidthSelector extends StatelessWidget {
|
|
||||||
final List<double> supportStorkWidths;
|
|
||||||
final ValueChanged<int> onSelect;
|
|
||||||
final int activeIndex;
|
|
||||||
final Color color;
|
|
||||||
|
|
||||||
const StorkWidthSelector({
|
|
||||||
Key? key,
|
|
||||||
required this.supportStorkWidths,
|
|
||||||
required this.activeIndex,
|
|
||||||
required this.onSelect,
|
|
||||||
required this.color,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
|
||||||
children: List.generate(
|
|
||||||
supportStorkWidths.length,
|
|
||||||
_buildByIndex,
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildByIndex(int index) {
|
|
||||||
bool select = index == activeIndex;
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () => onSelect(index),
|
|
||||||
child: Container(
|
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 2),
|
|
||||||
width: 70,
|
|
||||||
height: 18,
|
|
||||||
alignment: Alignment.center,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
border: select ? Border.all(color: Colors.blue) : null),
|
|
||||||
child: Container(
|
|
||||||
width: 50,
|
|
||||||
color: color,
|
|
||||||
height: supportStorkWidths[index],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
3
lib/components/components.dart
Normal file
3
lib/components/components.dart
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export 'toly_ui/toly_ui.dart';
|
||||||
|
export 'windows/window_buttons.dart';
|
||||||
|
export 'windows/drag_to_move_area.dart';
|
||||||
60
lib/components/toly_ui/button/hover_icon_button.dart
Normal file
60
lib/components/toly_ui/button/hover_icon_button.dart
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
class HoverIconButton extends StatefulWidget {
|
||||||
|
final VoidCallback? onPressed;
|
||||||
|
final IconData icon;
|
||||||
|
final double size;
|
||||||
|
final Color? hoverColor;
|
||||||
|
final Color? defaultColor;
|
||||||
|
final MouseCursor cursor;
|
||||||
|
|
||||||
|
const HoverIconButton({
|
||||||
|
super.key,
|
||||||
|
required this.onPressed,
|
||||||
|
required this.icon,
|
||||||
|
this.hoverColor,
|
||||||
|
this.size = 24,
|
||||||
|
this.defaultColor,
|
||||||
|
this.cursor = SystemMouseCursors.click,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<HoverIconButton> createState() => _HoverIconButtonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HoverIconButtonState extends State<HoverIconButton> {
|
||||||
|
bool _hover = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
Color? color = (_hover)
|
||||||
|
? widget.hoverColor ?? Theme.of(context).primaryColor
|
||||||
|
: (widget.defaultColor ?? null);
|
||||||
|
|
||||||
|
return MouseRegion(
|
||||||
|
cursor: widget.cursor,
|
||||||
|
onEnter: _onEnter,
|
||||||
|
onExit: _onExit,
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: widget.onPressed,
|
||||||
|
child: Icon(
|
||||||
|
widget.icon,
|
||||||
|
size: widget.size,
|
||||||
|
color: color,
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onEnter(PointerEnterEvent event) {
|
||||||
|
setState(() {
|
||||||
|
_hover = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onExit(PointerExitEvent event) {
|
||||||
|
setState(() {
|
||||||
|
_hover = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user