Add flutter 3+ support. Update dependencies. Fix code style and format issues.
This commit is contained in:
@@ -2,12 +2,10 @@ import 'dart:async';
|
||||
|
||||
import 'package:stream_transform/stream_transform.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:thingsboard_app/core/context/tb_context.dart';
|
||||
import 'package:thingsboard_app/core/context/tb_context_widget.dart';
|
||||
|
||||
class TbAppBar extends TbContextWidget implements PreferredSizeWidget {
|
||||
|
||||
final Widget? leading;
|
||||
final Widget? title;
|
||||
final List<Widget>? actions;
|
||||
@@ -18,18 +16,22 @@ class TbAppBar extends TbContextWidget implements PreferredSizeWidget {
|
||||
@override
|
||||
final Size preferredSize;
|
||||
|
||||
TbAppBar(TbContext tbContext, {this.leading, this.title, this.actions, this.elevation = 8,
|
||||
this.shadowColor, this.showLoadingIndicator = false}) :
|
||||
preferredSize = Size.fromHeight(kToolbarHeight + (showLoadingIndicator ? 4 : 0)),
|
||||
super(tbContext);
|
||||
TbAppBar(TbContext tbContext,
|
||||
{this.leading,
|
||||
this.title,
|
||||
this.actions,
|
||||
this.elevation = 8,
|
||||
this.shadowColor,
|
||||
this.showLoadingIndicator = false})
|
||||
: preferredSize =
|
||||
Size.fromHeight(kToolbarHeight + (showLoadingIndicator ? 4 : 0)),
|
||||
super(tbContext);
|
||||
|
||||
@override
|
||||
_TbAppBarState createState() => _TbAppBarState();
|
||||
|
||||
}
|
||||
|
||||
class _TbAppBarState extends TbContextState<TbAppBar> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -45,18 +47,15 @@ class _TbAppBarState extends TbContextState<TbAppBar> {
|
||||
List<Widget> children = <Widget>[];
|
||||
children.add(buildDefaultBar());
|
||||
if (widget.showLoadingIndicator) {
|
||||
children.add(
|
||||
ValueListenableBuilder(
|
||||
valueListenable: loadingNotifier,
|
||||
builder: (context, bool loading, child) {
|
||||
if (loading) {
|
||||
return LinearProgressIndicator();
|
||||
} else {
|
||||
return Container(height: 4);
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
children.add(ValueListenableBuilder(
|
||||
valueListenable: loadingNotifier,
|
||||
builder: (context, bool loading, child) {
|
||||
if (loading) {
|
||||
return LinearProgressIndicator();
|
||||
} else {
|
||||
return Container(height: 4);
|
||||
}
|
||||
}));
|
||||
}
|
||||
return Column(
|
||||
children: children,
|
||||
@@ -75,7 +74,6 @@ class _TbAppBarState extends TbContextState<TbAppBar> {
|
||||
}
|
||||
|
||||
class TbAppSearchBar extends TbContextWidget implements PreferredSizeWidget {
|
||||
|
||||
final double? elevation;
|
||||
final Color? shadowColor;
|
||||
final bool showLoadingIndicator;
|
||||
@@ -85,9 +83,14 @@ class TbAppSearchBar extends TbContextWidget implements PreferredSizeWidget {
|
||||
@override
|
||||
final Size preferredSize;
|
||||
|
||||
TbAppSearchBar(TbContext tbContext, {this.elevation = 8,
|
||||
this.shadowColor, this.showLoadingIndicator = false, this.searchHint, this.onSearch}) :
|
||||
preferredSize = Size.fromHeight(kToolbarHeight + (showLoadingIndicator ? 4 : 0)),
|
||||
TbAppSearchBar(TbContext tbContext,
|
||||
{this.elevation = 8,
|
||||
this.shadowColor,
|
||||
this.showLoadingIndicator = false,
|
||||
this.searchHint,
|
||||
this.onSearch})
|
||||
: preferredSize =
|
||||
Size.fromHeight(kToolbarHeight + (showLoadingIndicator ? 4 : 0)),
|
||||
super(tbContext);
|
||||
|
||||
@override
|
||||
@@ -95,7 +98,6 @@ class TbAppSearchBar extends TbContextWidget implements PreferredSizeWidget {
|
||||
}
|
||||
|
||||
class _TbAppSearchBarState extends TbContextState<TbAppSearchBar> {
|
||||
|
||||
final TextEditingController _filter = new TextEditingController();
|
||||
final _textUpdates = StreamController<String>();
|
||||
|
||||
@@ -106,7 +108,11 @@ class _TbAppSearchBarState extends TbContextState<TbAppSearchBar> {
|
||||
_filter.addListener(() {
|
||||
_textUpdates.add(_filter.text);
|
||||
});
|
||||
_textUpdates.stream.skip(1).debounce(const Duration(milliseconds: 150)).distinct().forEach((element) => widget.onSearch!(element));
|
||||
_textUpdates.stream
|
||||
.skip(1)
|
||||
.debounce(const Duration(milliseconds: 150))
|
||||
.distinct()
|
||||
.forEach((element) => widget.onSearch!(element));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -120,18 +126,15 @@ class _TbAppSearchBarState extends TbContextState<TbAppSearchBar> {
|
||||
List<Widget> children = <Widget>[];
|
||||
children.add(buildSearchBar());
|
||||
if (widget.showLoadingIndicator) {
|
||||
children.add(
|
||||
ValueListenableBuilder(
|
||||
valueListenable: loadingNotifier,
|
||||
builder: (context, bool loading, child) {
|
||||
if (loading) {
|
||||
return LinearProgressIndicator();
|
||||
} else {
|
||||
return Container(height: 4);
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
children.add(ValueListenableBuilder(
|
||||
valueListenable: loadingNotifier,
|
||||
builder: (context, bool loading, child) {
|
||||
if (loading) {
|
||||
return LinearProgressIndicator();
|
||||
} else {
|
||||
return Container(height: 4);
|
||||
}
|
||||
}));
|
||||
}
|
||||
return Column(
|
||||
children: children,
|
||||
@@ -140,40 +143,37 @@ class _TbAppSearchBarState extends TbContextState<TbAppSearchBar> {
|
||||
|
||||
AppBar buildSearchBar() {
|
||||
return AppBar(
|
||||
centerTitle: true,
|
||||
elevation: widget.elevation ?? 8,
|
||||
shadowColor: widget.shadowColor ?? Color(0xFFFFFFFF).withAlpha(150),
|
||||
title: TextField(
|
||||
controller: _filter,
|
||||
autofocus: true,
|
||||
// cursorColor: Colors.white,
|
||||
decoration: new InputDecoration(
|
||||
border: InputBorder.none,
|
||||
hintStyle: TextStyle(
|
||||
color: Color(0xFF282828).withAlpha((255 * 0.38).ceil()),
|
||||
),
|
||||
contentPadding: EdgeInsets.only(left: 15, bottom: 11, top: 15, right: 15),
|
||||
hintText: widget.searchHint ?? 'Search',
|
||||
)
|
||||
),
|
||||
actions: [
|
||||
ValueListenableBuilder(valueListenable: _filter,
|
||||
builder: (context, value, child) {
|
||||
if (_filter.text.isNotEmpty) {
|
||||
return IconButton(
|
||||
icon: Icon(
|
||||
Icons.clear
|
||||
),
|
||||
onPressed: () {
|
||||
_filter.text = '';
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
}
|
||||
)
|
||||
]
|
||||
);
|
||||
centerTitle: true,
|
||||
elevation: widget.elevation ?? 8,
|
||||
shadowColor: widget.shadowColor ?? Color(0xFFFFFFFF).withAlpha(150),
|
||||
title: TextField(
|
||||
controller: _filter,
|
||||
autofocus: true,
|
||||
// cursorColor: Colors.white,
|
||||
decoration: new InputDecoration(
|
||||
border: InputBorder.none,
|
||||
hintStyle: TextStyle(
|
||||
color: Color(0xFF282828).withAlpha((255 * 0.38).ceil()),
|
||||
),
|
||||
contentPadding:
|
||||
EdgeInsets.only(left: 15, bottom: 11, top: 15, right: 15),
|
||||
hintText: widget.searchHint ?? 'Search',
|
||||
)),
|
||||
actions: [
|
||||
ValueListenableBuilder(
|
||||
valueListenable: _filter,
|
||||
builder: (context, value, child) {
|
||||
if (_filter.text.isNotEmpty) {
|
||||
return IconButton(
|
||||
icon: Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
_filter.text = '';
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
})
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:thingsboard_app/constants/assets_path.dart';
|
||||
|
||||
class TbProgressIndicator extends ProgressIndicator {
|
||||
|
||||
final double size;
|
||||
|
||||
const TbProgressIndicator({
|
||||
@@ -16,22 +14,22 @@ class TbProgressIndicator extends ProgressIndicator {
|
||||
String? semanticsLabel,
|
||||
String? semanticsValue,
|
||||
}) : super(
|
||||
key: key,
|
||||
value: null,
|
||||
valueColor: valueColor,
|
||||
semanticsLabel: semanticsLabel,
|
||||
semanticsValue: semanticsValue,
|
||||
);
|
||||
key: key,
|
||||
value: null,
|
||||
valueColor: valueColor,
|
||||
semanticsLabel: semanticsLabel,
|
||||
semanticsValue: semanticsValue,
|
||||
);
|
||||
|
||||
@override
|
||||
_TbProgressIndicatorState createState() => _TbProgressIndicatorState();
|
||||
|
||||
Color _getValueColor(BuildContext context) => valueColor?.value ?? Theme.of(context).primaryColor;
|
||||
|
||||
Color _getValueColor(BuildContext context) =>
|
||||
valueColor?.value ?? Theme.of(context).primaryColor;
|
||||
}
|
||||
|
||||
class _TbProgressIndicatorState extends State<TbProgressIndicator> with SingleTickerProviderStateMixin {
|
||||
|
||||
class _TbProgressIndicatorState extends State<TbProgressIndicator>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _controller;
|
||||
late CurvedAnimation _rotation;
|
||||
|
||||
@@ -39,8 +37,10 @@ class _TbProgressIndicatorState extends State<TbProgressIndicator> with SingleTi
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = AnimationController(
|
||||
duration: const Duration(milliseconds: 1500),
|
||||
vsync: this, upperBound: 1, animationBehavior: AnimationBehavior.preserve);
|
||||
duration: const Duration(milliseconds: 1500),
|
||||
vsync: this,
|
||||
upperBound: 1,
|
||||
animationBehavior: AnimationBehavior.preserve);
|
||||
_rotation = CurvedAnimation(parent: _controller, curve: Curves.easeInOut);
|
||||
_controller.repeat();
|
||||
}
|
||||
@@ -48,8 +48,7 @@ class _TbProgressIndicatorState extends State<TbProgressIndicator> with SingleTi
|
||||
@override
|
||||
void didUpdateWidget(TbProgressIndicator oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (!_controller.isAnimating)
|
||||
_controller.repeat();
|
||||
if (!_controller.isAnimating) _controller.repeat();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -74,13 +73,10 @@ class _TbProgressIndicatorState extends State<TbProgressIndicator> with SingleTi
|
||||
color: widget._getValueColor(context)),
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
return Transform.rotate(
|
||||
angle: _rotation.value * pi * 2,
|
||||
child: child
|
||||
);
|
||||
angle: _rotation.value * pi * 2, child: child);
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'package:flutter/widgets.dart';
|
||||
import 'package:preload_page_view/preload_page_view.dart';
|
||||
|
||||
class TwoPageViewController {
|
||||
|
||||
_TwoPageViewState? _state;
|
||||
|
||||
setTransitionIndexedStackState(_TwoPageViewState state) {
|
||||
@@ -24,7 +23,6 @@ class TwoPageViewController {
|
||||
}
|
||||
|
||||
int? get index => _state?._selectedIndex;
|
||||
|
||||
}
|
||||
|
||||
class TwoPageView extends StatefulWidget {
|
||||
@@ -33,21 +31,19 @@ class TwoPageView extends StatefulWidget {
|
||||
final Duration duration;
|
||||
final TwoPageViewController? controller;
|
||||
|
||||
const TwoPageView({
|
||||
Key? key,
|
||||
required this.first,
|
||||
required this.second,
|
||||
this.controller,
|
||||
this.duration = const Duration(milliseconds: 250)
|
||||
}) : super(key: key);
|
||||
const TwoPageView(
|
||||
{Key? key,
|
||||
required this.first,
|
||||
required this.second,
|
||||
this.controller,
|
||||
this.duration = const Duration(milliseconds: 250)})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_TwoPageViewState createState() => _TwoPageViewState();
|
||||
|
||||
}
|
||||
|
||||
class _TwoPageViewState extends State<TwoPageView> {
|
||||
|
||||
late List<Widget> _pages;
|
||||
bool _reverse = false;
|
||||
int _selectedIndex = 0;
|
||||
@@ -68,7 +64,8 @@ class _TwoPageViewState extends State<TwoPageView> {
|
||||
_reverse = true;
|
||||
});
|
||||
}
|
||||
await _pageController.animateToPage(_selectedIndex, duration: widget.duration, curve: Curves.fastOutSlowIn);
|
||||
await _pageController.animateToPage(_selectedIndex,
|
||||
duration: widget.duration, curve: Curves.fastOutSlowIn);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -77,7 +74,8 @@ class _TwoPageViewState extends State<TwoPageView> {
|
||||
Future<bool> _close(int index, {bool animate = true}) async {
|
||||
if (_selectedIndex == index) {
|
||||
_selectedIndex = index == 1 ? 0 : 1;
|
||||
await _pageController.animateToPage(_selectedIndex, duration: widget.duration, curve: Curves.fastOutSlowIn);
|
||||
await _pageController.animateToPage(_selectedIndex,
|
||||
duration: widget.duration, curve: Curves.fastOutSlowIn);
|
||||
if (index == 0) {
|
||||
setState(() {
|
||||
_reverse = false;
|
||||
@@ -106,5 +104,4 @@ class _TwoPageViewState extends State<TwoPageView> {
|
||||
controller: _pageController,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,14 +2,13 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class TwoValueListenableBuilder<A, B> extends StatelessWidget {
|
||||
TwoValueListenableBuilder(
|
||||
{
|
||||
Key? key,
|
||||
required this.firstValueListenable,
|
||||
required this.secondValueListenable,
|
||||
required this.builder,
|
||||
this.child,
|
||||
}) : super(key: key);
|
||||
TwoValueListenableBuilder({
|
||||
Key? key,
|
||||
required this.firstValueListenable,
|
||||
required this.secondValueListenable,
|
||||
required this.builder,
|
||||
this.child,
|
||||
}) : super(key: key);
|
||||
|
||||
final ValueListenable<A> firstValueListenable;
|
||||
final ValueListenable<B> secondValueListenable;
|
||||
|
||||
Reference in New Issue
Block a user