Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added example/images/multi.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion example/lib/basic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Basic extends StatelessWidget {
foregroundColor: WidgetStatePropertyAll(Colors.black),
),
onPressed: () {
invalidateNinePatchCacheItem(const AssetImage('images/flag.9.webp'));
NinePatchCache.of(context)?.invalidateNinePatchCacheItem(const AssetImage('images/flag.9.webp'));
},
child: const Text('NinePatch with "centerSlice" and "padding" embedded in image'),
),
Expand Down
81 changes: 47 additions & 34 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,46 +1,59 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:nine_patch/nine_patch.dart';

import 'animation.dart';
import 'basic.dart';
import 'multi.dart';
import 'shadows.dart';

main() {
runApp(MaterialApp(
scrollBehavior: const MaterialScrollBehavior().copyWith(dragDevices: {PointerDeviceKind.mouse, PointerDeviceKind.touch}),
home: Scaffold(
body: Builder(
builder: (context) {
return ListView(
children: [
ListTile(
title: const Text('basic usage'),
subtitle: const Text('Basic()'),
onTap: () {
final route = MaterialPageRoute(builder: (ctx) => Basic());
Navigator.of(context).push(route);
},
),
ListTile(
title: const Text('text field shadows'),
subtitle: const Text('EditableTextShadows()'),
onTap: () {
final route = MaterialPageRoute(builder: (ctx) => EditableTextShadows());
Navigator.of(context).push(route);
},
),
ListTile(
title: const Text('animated stuff'),
subtitle: const Text('Animated()'),
onTap: () {
final route = MaterialPageRoute(builder: (ctx) => Animated());
Navigator.of(context).push(route);
},
),
],
);
}
runApp(NinePatchCache(
maximumSize: 10,
child: MaterialApp(
scrollBehavior: const MaterialScrollBehavior().copyWith(dragDevices: {PointerDeviceKind.mouse, PointerDeviceKind.touch}),
home: Scaffold(
body: Builder(
builder: (context) {
return ListView(
children: [
ListTile(
title: const Text('basic usage'),
subtitle: const Text('Basic()'),
onTap: () {
final route = MaterialPageRoute(builder: (ctx) => Basic());
Navigator.of(context).push(route);
},
),
ListTile(
title: const Text('multiple stretch lines'),
subtitle: const Text('Multi()'),
onTap: () {
final route = MaterialPageRoute(builder: (ctx) => Multi());
Navigator.of(context).push(route);
},
),
ListTile(
title: const Text('text field shadows'),
subtitle: const Text('EditableTextShadows()'),
onTap: () {
final route = MaterialPageRoute(builder: (ctx) => EditableTextShadows());
Navigator.of(context).push(route);
},
),
ListTile(
title: const Text('animated stuff'),
subtitle: const Text('Animated()'),
onTap: () {
final route = MaterialPageRoute(builder: (ctx) => Animated());
Navigator.of(context).push(route);
},
),
],
);
}
),
),
),
));
Expand Down
65 changes: 65 additions & 0 deletions example/lib/multi.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// ignore_for_file: use_key_in_widget_constructors

import 'package:flutter/material.dart';

import 'package:nine_patch/nine_patch.dart';

class Multi extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: SingleChildScrollView(
child: Center(
child: Column(
children: [
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 200),
child: const NinePatch(
imageProvider: AssetImage('images/multi.webp'),
child: Center(
child: Text('this background is a single webp image that contains two horizontal stretch areas'),
),
),
),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 128),
child: NinePatch(
colorFilter: ColorFilter.mode(Colors.lightGreenAccent.shade400, BlendMode.modulate),
imageProvider: const AssetImage('images/multi.webp'),
child: const Center(
child: Text('Incididunt aliquip elit non laboris aliquip do irure non non sint reprehenderit et exercitation elit.'),
),
),
),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 225),
child: Container(
decoration: NinePatchDecoration(
image: const NinePatchDecorationImage(
image: AssetImage('images/multi.webp')
),
context: context,
padding: const EdgeInsets.only(top: 8) + const EdgeInsets.all(10),
),
child: const Center(
child: Text.rich(TextSpan(
children: [
TextSpan(text: 'this is a simple '),
TextSpan(text: 'Container ', style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(text: 'using '),
TextSpan(text: 'NinePatchDecoration', style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(text: ', note that you have to provide the content padding since it cannot be synchronously read from the '),
TextSpan(text: 'ImageProvider', style: TextStyle(fontWeight: FontWeight.bold)),
],
)),
),
),
),
],
),
),
),
);
}
}
86 changes: 45 additions & 41 deletions example/lib/shadows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,58 @@ class _EditableTextShadowsState extends State<EditableTextShadows> {
Widget build(BuildContext context) {
final textTheme = Theme.of(context).textTheme;
return Scaffold(
backgroundColor: Colors.green.shade200,
appBar: AppBar(),
body: Column(
children: [
const Card(
child: Padding(
padding: EdgeInsets.all(4),
child: Text('click any text field (or one of "focus traversal" buttons)', ),
),
),
Row(
children: [
const Padding(
padding: EdgeInsets.only(left: 8),
child: Text('move focus:'),
body: DecoratedBox(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [Colors.indigo.shade100, Colors.teal.shade200]),
),
child: Column(
children: [
const Card(
child: Padding(
padding: EdgeInsets.all(4),
child: Text('click any text field (or one of "focus traversal" buttons)', ),
),
IconButton(onPressed: () => _moveFocus(-1, 0), icon: const Icon(Icons.arrow_back)),
IconButton(onPressed: () => _moveFocus(1, -1), icon: const Icon(Icons.arrow_forward)),
],
),
const Divider(),
for (final (controller, focusNode) in editableTextData)
Padding(
padding: const EdgeInsets.only(top: 6, left: 6, right: 6),
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
color: focusNode.hasFocus? Colors.grey.shade200 : Colors.white,
child: AnimatedMultiNinePatch(
imageProvider: const AssetImage('images/shadows.webp'),
frameBuilder: horizontalFixedSizeFrameBuilder(6, const Size(18, 13)),
phase: focusNode.hasFocus? 0 : 1,
),
Row(
children: [
const Padding(
padding: EdgeInsets.only(left: 8),
child: Text('move focus:'),
),
IconButton(onPressed: () => _moveFocus(-1, 0), icon: const Icon(Icons.arrow_back)),
IconButton(onPressed: () => _moveFocus(1, -1), icon: const Icon(Icons.arrow_forward)),
],
),
const Divider(),
for (final (controller, focusNode) in editableTextData)
Padding(
padding: const EdgeInsets.only(top: 6, left: 6, right: 6),
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
debugLabel: 'shadows',
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: EditableText(
controller: controller,
focusNode: focusNode,
style: textTheme.headlineSmall!,
cursorColor: Colors.black54,
backgroundCursorColor: Colors.white,
color: focusNode.hasFocus? Colors.grey.shade200 : Colors.white,
child: AnimatedMultiNinePatch(
imageProvider: const AssetImage('images/shadows.webp'),
frameBuilder: horizontalFixedSizeFrameBuilder(6, const Size(18, 13)),
phase: focusNode.hasFocus? 0 : 1,
duration: const Duration(milliseconds: 300),
debugLabel: 'shadows',
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: EditableText(
controller: controller,
focusNode: focusNode,
style: textTheme.headlineSmall!,
cursorColor: Colors.black54,
backgroundCursorColor: Colors.white,
),
),
),
),
),
),
const SizedBox(height: 6),
],
const SizedBox(height: 6),
],
),
),
);
}
Expand Down
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ flutter:
- images/flag1.9.webp
- images/btn_default_normal.9.webp
- images/shadows.webp
- images/multi.webp


# An image asset can refer to one or more resolution-specific "variants", see
Expand Down
9 changes: 4 additions & 5 deletions lib/nine_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ export 'src/nine_patch.dart' show
NinePatch,
AnimatedNinePatch,
AnimatedMultiNinePatch,
ninePatchCacheSize,
NinePatchDecoration,
NinePatchDecorationImage,
horizontalFixedSizeFrameBuilder,
verticalFixedSizeFrameBuilder,
gridFixedSizeFrameBuilder,
invalidateNinePatchCache,
invalidateNinePatchCacheItem,
invalidateNinePatchCacheWhere,
NinePatchBuilder,
FrameBuilder,
NinePatchAnimatedBuilder;
NinePatchAnimatedBuilder,
NinePatchCache;
Loading